Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDFS-17456. Fix the incorrect dfsused statistics of datanode when appending a file. #6713

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,9 @@ public ReplicaInPipeline append(String bpid, ReplicaInfo replicaInfo,

// rename meta file to rbw directory
// rename block file to rbw directory
long oldReplicaLength = replicaInfo.getMetadataLength() + replicaInfo.getBlockDataLength();
fuchaohong marked this conversation as resolved.
Show resolved Hide resolved
newReplicaInfo.moveReplicaFrom(replicaInfo, newBlkFile);
getBlockPoolSlice(bpid).decDfsUsed(oldReplicaLength);

reserveSpaceForReplica(bytesReserved);
return newReplicaInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2102,4 +2102,46 @@ public void delayGetMetaDataInputStream() {
DataNodeFaultInjector.set(oldDnInjector);
}
}

@Test(timeout = 30000)
public void testAppend() {
MiniDFSCluster cluster = null;
try {
cluster = new MiniDFSCluster.Builder(conf)
.numDataNodes(1)
.storageTypes(new StorageType[]{StorageType.DISK, StorageType.DISK})
.storagesPerDatanode(2)
.build();
FileSystem fs = cluster.getFileSystem();
DataNode dataNode = cluster.getDataNodes().get(0);

// Create test file
Path filePath = new Path("testData");
FsDatasetImpl fsDataSetImpl = (FsDatasetImpl) dataNode.getFSDataset();
DFSTestUtil.createFile(fs, filePath, 100, (short) 1, 0);
ExtendedBlock block = DFSTestUtil.getFirstBlock(fs, filePath);
ReplicaInfo replicaInfo = fsDataSetImpl.getReplicaInfo(block);
long oldMetaLength = replicaInfo.getMetadataLength();
long oldDfsUsed = fsDataSetImpl.getDfsUsed();

// Append to file
int appendLength = 100;
DFSTestUtil.appendFile(fs, filePath, appendLength);

block = DFSTestUtil.getFirstBlock(fs, filePath);
replicaInfo = fsDataSetImpl.getReplicaInfo(block);
long newMetaLength = replicaInfo.getMetadataLength();
long newDfsUsed = fsDataSetImpl.getDfsUsed();

assert newDfsUsed == oldDfsUsed + appendLength + (newMetaLength - oldMetaLength) :
"When appending a file, the dfsused statistics of datanode are incorrect.";
} catch (Exception ex) {
LOG.info("Exception in testAppend ", ex);
fail("Exception while testing testAppend ");
} finally {
if (cluster.isClusterUp()) {
cluster.shutdown();
}
}
}
}
Loading