Skip to content

Commit ae4143a

Browse files
Santosh MarellaHexiaoqiao
authored andcommitted
HDFS-12914. Block report leases cause missing blocks until next report. Contributed by Santosh Marella, He Xiaoqiao.
Signed-off-by: Wei-Chiu Chuang <[email protected]> Co-authored-by: He Xiaoqiao <[email protected]>
1 parent 3ba090f commit ae4143a

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,21 @@ private static class BlockInfoToAdd {
25722572
}
25732573
}
25742574

2575+
/**
2576+
* Check block report lease.
2577+
* @return true if lease exist and not expire
2578+
*/
2579+
public boolean checkBlockReportLease(BlockReportContext context,
2580+
final DatanodeID nodeID) throws UnregisteredNodeException {
2581+
if (context == null) {
2582+
return true;
2583+
}
2584+
DatanodeDescriptor node = datanodeManager.getDatanode(nodeID);
2585+
final long startTime = Time.monotonicNow();
2586+
return blockReportLeaseManager.checkLease(node, startTime,
2587+
context.getLeaseId());
2588+
}
2589+
25752590
/**
25762591
* The given storage is reporting all its blocks.
25772592
* Update the (storage{@literal -->}block list) and
@@ -2619,12 +2634,6 @@ public boolean processReport(final DatanodeID nodeID,
26192634
blockReportLeaseManager.removeLease(node);
26202635
return !node.hasStaleStorages();
26212636
}
2622-
if (context != null) {
2623-
if (!blockReportLeaseManager.checkLease(node, startTime,
2624-
context.getLeaseId())) {
2625-
return false;
2626-
}
2627-
}
26282637

26292638
if (storageInfo.getBlockReportCount() == 0) {
26302639
// The first block report can be processed a lot more efficiently than

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import java.util.List;
4646
import java.util.Map;
4747
import java.util.Set;
48-
import java.util.concurrent.Callable;
4948

5049
import com.google.common.collect.Lists;
5150

@@ -175,6 +174,7 @@
175174
import org.apache.hadoop.hdfs.server.protocol.NamenodeRegistration;
176175
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
177176
import org.apache.hadoop.hdfs.server.protocol.NodeRegistration;
177+
import org.apache.hadoop.hdfs.server.protocol.RegisterCommand;
178178
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest;
179179
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
180180
import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports;
@@ -1591,21 +1591,25 @@ public DatanodeCommand blockReport(final DatanodeRegistration nodeReg,
15911591
}
15921592
final BlockManager bm = namesystem.getBlockManager();
15931593
boolean noStaleStorages = false;
1594-
for (int r = 0; r < reports.length; r++) {
1595-
final BlockListAsLongs blocks = reports[r].getBlocks();
1596-
//
1597-
// BlockManager.processReport accumulates information of prior calls
1598-
// for the same node and storage, so the value returned by the last
1599-
// call of this loop is the final updated value for noStaleStorage.
1600-
//
1601-
final int index = r;
1602-
noStaleStorages = bm.runBlockOp(new Callable<Boolean>() {
1603-
@Override
1604-
public Boolean call() throws IOException {
1605-
return bm.processReport(nodeReg, reports[index].getStorage(),
1606-
blocks, context);
1594+
try {
1595+
if (bm.checkBlockReportLease(context, nodeReg)) {
1596+
for (int r = 0; r < reports.length; r++) {
1597+
final BlockListAsLongs blocks = reports[r].getBlocks();
1598+
//
1599+
// BlockManager.processReport accumulates information of prior calls
1600+
// for the same node and storage, so the value returned by the last
1601+
// call of this loop is the final updated value for noStaleStorage.
1602+
//
1603+
final int index = r;
1604+
noStaleStorages = bm.runBlockOp(() ->
1605+
bm.processReport(nodeReg, reports[index].getStorage(),
1606+
blocks, context));
16071607
}
1608-
});
1608+
}
1609+
} catch (UnregisteredNodeException une) {
1610+
LOG.debug("Datanode {} is attempting to report but not register yet.",
1611+
nodeReg);
1612+
return RegisterCommand.REGISTER;
16091613
}
16101614
bm.removeBRLeaseIfNeeded(nodeReg, context);
16111615

0 commit comments

Comments
 (0)