Skip to content

Commit 4cb22cd

Browse files
committed
HDFS-14311. Multi-threading conflict at layoutVersion when loading block pool storage. Contributed by Yicong Cai.
1 parent aa6995f commit 4cb22cd

File tree

1 file changed

+14
-6
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode

1 file changed

+14
-6
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataStorage.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,29 +447,37 @@ private List<StorageDirectory> loadBlockPoolSliceStorage(DataNode datanode,
447447
StartupOption startOpt, ExecutorService executor) throws IOException {
448448
final String bpid = nsInfo.getBlockPoolID();
449449
final BlockPoolSliceStorage bpStorage = getBlockPoolSliceStorage(nsInfo);
450+
Map<StorageLocation, List<Callable<StorageDirectory>>> upgradeCallableMap =
451+
new HashMap<>();
450452
final List<StorageDirectory> success = Lists.newArrayList();
451453
final List<UpgradeTask> tasks = Lists.newArrayList();
452454
for (StorageLocation dataDir : dataDirs) {
453455
dataDir.makeBlockPoolDir(bpid, null);
454456
try {
455-
final List<Callable<StorageDirectory>> callables = Lists.newArrayList();
457+
final List<Callable<StorageDirectory>> sdCallables =
458+
Lists.newArrayList();
456459
final List<StorageDirectory> dirs = bpStorage.recoverTransitionRead(
457-
nsInfo, dataDir, startOpt, callables, datanode.getConf());
458-
if (callables.isEmpty()) {
460+
nsInfo, dataDir, startOpt, sdCallables, datanode.getConf());
461+
if (sdCallables.isEmpty()) {
459462
for(StorageDirectory sd : dirs) {
460463
success.add(sd);
461464
}
462465
} else {
463-
for(Callable<StorageDirectory> c : callables) {
464-
tasks.add(new UpgradeTask(dataDir, executor.submit(c)));
465-
}
466+
upgradeCallableMap.put(dataDir, sdCallables);
466467
}
467468
} catch (IOException e) {
468469
LOG.warn("Failed to add storage directory {} for block pool {}",
469470
dataDir, bpid, e);
470471
}
471472
}
472473

474+
for (Map.Entry<StorageLocation, List<Callable<StorageDirectory>>> entry :
475+
upgradeCallableMap.entrySet()) {
476+
for(Callable<StorageDirectory> c : entry.getValue()) {
477+
tasks.add(new UpgradeTask(entry.getKey(), executor.submit(c)));
478+
}
479+
}
480+
473481
if (!tasks.isEmpty()) {
474482
LOG.info("loadBlockPoolSliceStorage: {} upgrade tasks", tasks.size());
475483
for(UpgradeTask t : tasks) {

0 commit comments

Comments
 (0)