Skip to content

Commit 57ecaed

Browse files
committed
Readjust the repair plan
1 parent 3b72336 commit 57ecaed

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,18 +2866,14 @@ public boolean checkBlockReportLease(BlockReportContext context,
28662866
* The given storage is reporting all its blocks.
28672867
* Update the (storage{@literal -->}block list) and
28682868
* (block{@literal -->}storage list) maps.
2869-
* totalReportNum -> totalStorageReportsNum
2870-
* currentReportNum -> currentStorageReportIndex
28712869
*
28722870
* @return true if all known storages of the given DN have finished reporting.
28732871
* @throws IOException
28742872
*/
28752873
public boolean processReport(final DatanodeID nodeID,
28762874
final DatanodeStorage storage,
28772875
final BlockListAsLongs newReport,
2878-
BlockReportContext context,
2879-
int totalReportNum,
2880-
int currentReportNum) throws IOException {
2876+
BlockReportContext context) throws IOException {
28812877
namesystem.writeLock();
28822878
final long startTime = Time.monotonicNow(); //after acquiring write lock
28832879
final long endTime;
@@ -2908,13 +2904,12 @@ public boolean processReport(final DatanodeID nodeID,
29082904
}
29092905
if (namesystem.isInStartupSafeMode()
29102906
&& !StorageType.PROVIDED.equals(storageInfo.getStorageType())
2911-
&& storageInfo.getBlockReportCount() > 0
2912-
&& totalReportNum == currentReportNum) {
2907+
&& storageInfo.getBlockReportCount() > 0) {
29132908
blockLog.info("BLOCK* processReport 0x{} with lease ID 0x{}: "
29142909
+ "discarded non-initial block report from {}"
29152910
+ " because namenode still in startup phase",
29162911
strBlockReportId, fullBrLeaseId, nodeID);
2917-
blockReportLeaseManager.removeLease(node);
2912+
removeLease(node);
29182913
return !node.hasStaleStorages();
29192914
}
29202915

@@ -2962,6 +2957,19 @@ public boolean processReport(final DatanodeID nodeID,
29622957
return !node.hasStaleStorages();
29632958
}
29642959

2960+
// Remove the lease when we have received block reports for all storages for a particular DN.
2961+
void removeLease(DatanodeDescriptor node) {
2962+
boolean needRemoveLease = true;
2963+
for (DatanodeStorageInfo sInfo : node.getStorageInfos()) {
2964+
if (sInfo.getBlockReportCount() == 0) {
2965+
needRemoveLease = false;
2966+
}
2967+
}
2968+
if (needRemoveLease) {
2969+
blockReportLeaseManager.removeLease(node);
2970+
}
2971+
}
2972+
29652973
public void removeBRLeaseIfNeeded(final DatanodeID nodeID,
29662974
final BlockReportContext context) throws IOException {
29672975
namesystem.writeLock();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ public DatanodeCommand blockReport(final DatanodeRegistration nodeReg,
16501650
final int index = r;
16511651
noStaleStorages = bm.runBlockOp(() ->
16521652
bm.processReport(nodeReg, reports[index].getStorage(),
1653-
blocks, context, reports.length, index + 1));
1653+
blocks, context));
16541654
}
16551655
} else {
16561656
throw new InvalidBlockReportLeaseException(context.getReportId(), context.getLeaseId());

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,12 @@ public void testSafeModeIBR() throws Exception {
10801080
reset(node);
10811081

10821082
bm.processReport(node, new DatanodeStorage(ds.getStorageID()),
1083-
BlockListAsLongs.EMPTY, null, 1, 1);
1083+
BlockListAsLongs.EMPTY, null);
10841084
assertEquals(1, ds.getBlockReportCount());
10851085
// send block report again, should NOT be processed
10861086
reset(node);
10871087
bm.processReport(node, new DatanodeStorage(ds.getStorageID()),
1088-
BlockListAsLongs.EMPTY, null, 1, 1);
1088+
BlockListAsLongs.EMPTY, null);
10891089
assertEquals(1, ds.getBlockReportCount());
10901090

10911091
// re-register as if node restarted, should update existing node
@@ -1096,7 +1096,7 @@ public void testSafeModeIBR() throws Exception {
10961096
// send block report, should be processed after restart
10971097
reset(node);
10981098
bm.processReport(node, new DatanodeStorage(ds.getStorageID()),
1099-
BlockListAsLongs.EMPTY, null, 1, 1);
1099+
BlockListAsLongs.EMPTY, null);
11001100
// Reinitialize as registration with empty storage list pruned
11011101
// node.storageMap.
11021102
ds = node.getStorageInfos()[0];
@@ -1125,7 +1125,7 @@ public void testSafeModeIBRAfterIncremental() throws Exception {
11251125
reset(node);
11261126
doReturn(1).when(node).numBlocks();
11271127
bm.processReport(node, new DatanodeStorage(ds.getStorageID()),
1128-
BlockListAsLongs.EMPTY, null, 1, 1);
1128+
BlockListAsLongs.EMPTY, null);
11291129
assertEquals(1, ds.getBlockReportCount());
11301130
}
11311131

@@ -1198,7 +1198,7 @@ public void testSafeModeIBRBeforeFirstFullBR() throws Exception {
11981198
// Make sure it's the first full report
11991199
assertEquals(0, ds.getBlockReportCount());
12001200
bm.processReport(node, new DatanodeStorage(ds.getStorageID()),
1201-
builder.build(), null, 1, 1);
1201+
builder.build(), null);
12021202
assertEquals(1, ds.getBlockReportCount());
12031203

12041204
// verify the storage info is correct
@@ -1249,12 +1249,12 @@ public void testSafeModeWithProvidedStorageBR() throws Exception {
12491249
bmPs.getDatanodeManager().addDatanode(node1);
12501250

12511251
// process reports of provided storage and disk storage
1252-
bmPs.processReport(node0, providedStorage, BlockListAsLongs.EMPTY, null, 2, 1);
1252+
bmPs.processReport(node0, providedStorage, BlockListAsLongs.EMPTY, null);
12531253
bmPs.processReport(node0, new DatanodeStorage(ds0.getStorageID()),
1254-
BlockListAsLongs.EMPTY, null, 2, 2);
1255-
bmPs.processReport(node1, providedStorage, BlockListAsLongs.EMPTY, null, 2, 1);
1254+
BlockListAsLongs.EMPTY, null);
1255+
bmPs.processReport(node1, providedStorage, BlockListAsLongs.EMPTY, null);
12561256
bmPs.processReport(node1, new DatanodeStorage(ds1.getStorageID()),
1257-
BlockListAsLongs.EMPTY, null, 2, 2);
1257+
BlockListAsLongs.EMPTY, null);
12581258

12591259
// The provided stoage report should not affect disk storage report
12601260
DatanodeStorageInfo dsPs =

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockReportLease.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import static org.mockito.ArgumentMatchers.any;
5656
import static org.mockito.Mockito.doAnswer;
5757
import static org.mockito.Mockito.spy;
58-
import static org.mockito.Mockito.doReturn;
5958

6059
/**
6160
* Tests that BlockReportLease in BlockManager.

0 commit comments

Comments
 (0)