Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -698,9 +698,10 @@ public static class DatanodeInfoBuilder {
private long nonDfsUsed = 0L;
private long lastBlockReportTime = 0L;
private long lastBlockReportMonotonic = 0L;
private int numBlocks;

private int numBlocks = 0;

// Please use setNumBlocks explicitly to set numBlocks as this method doesn't have
// sufficient info about numBlocks
public DatanodeInfoBuilder setFrom(DatanodeInfo from) {
this.capacity = from.getCapacity();
this.dfsUsed = from.getDfsUsed();
Expand All @@ -717,7 +718,6 @@ public DatanodeInfoBuilder setFrom(DatanodeInfo from) {
this.upgradeDomain = from.getUpgradeDomain();
this.lastBlockReportTime = from.getLastBlockReportTime();
this.lastBlockReportMonotonic = from.getLastBlockReportMonotonic();
this.numBlocks = from.getNumBlocks();
setNodeID(from);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,8 @@ public DatanodeStorageReport[] getDatanodeStorageReport(
for (int i = 0; i < reports.length; i++) {
final DatanodeDescriptor d = datanodes.get(i);
reports[i] = new DatanodeStorageReport(
new DatanodeInfoBuilder().setFrom(d).build(), d.getStorageReports());
new DatanodeInfoBuilder().setFrom(d).setNumBlocks(d.numBlocks()).build(),
d.getStorageReports());
}
return reports;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.UnresolvedLinkException;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorageReport;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.test.GenericTestUtils;
Expand All @@ -31,6 +36,8 @@
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TestNameNodeRpcServerMethods {
private static NamenodeProtocols nnRpc;
private static Configuration conf;
Expand Down Expand Up @@ -83,4 +90,27 @@ public void testDeleteSnapshotWhenSnapshotNameIsEmpty() throws Exception {

}

@Test
public void testGetDatanodeStorageReportWithNumBLocksNotZero() throws Exception {
int buffSize = 1024;
long blockSize = 1024 * 1024;
String file = "/testFile";
DistributedFileSystem dfs = cluster.getFileSystem();
FSDataOutputStream outputStream = dfs.create(
new Path(file), true, buffSize, (short)1, blockSize);
byte[] outBuffer = new byte[buffSize];
for (int i = 0; i < buffSize; i++) {
outBuffer[i] = (byte) (i & 0x00ff);
}
outputStream.write(outBuffer);
outputStream.close();

int numBlocks = 0;
DatanodeStorageReport[] reports
= nnRpc.getDatanodeStorageReport(HdfsConstants.DatanodeReportType.ALL);
for (DatanodeStorageReport r : reports) {
numBlocks += r.getDatanodeInfo().getNumBlocks();
}
assertEquals(1, numBlocks);
}
}