From 6f4192d77d0551b2ca847c8c1ee5b1c4a3380c36 Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Thu, 20 Oct 2016 10:49:39 -0700 Subject: [PATCH] HDFS-11018. Incorrect check and message in FsDatasetImpl#invalidate. Contributed by Yiqun Lin. (cherry picked from commit 6d2da38d16cebe9b82f1048f87127eecee33664c) Conflicts: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java --- .../fsdataset/impl/FsDatasetImpl.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java index 0b55e7ec8a8..a18c677f97f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java @@ -809,8 +809,14 @@ class FsDatasetImpl implements FsDatasetSpi { throws ReplicaNotFoundException { ReplicaInfo info = volumeMap.get(b.getBlockPoolId(), b.getLocalBlock()); if (info == null) { - throw new ReplicaNotFoundException( - ReplicaNotFoundException.NON_EXISTENT_REPLICA + b); + if (volumeMap.get(b.getBlockPoolId(), b.getLocalBlock().getBlockId()) + == null) { + throw new ReplicaNotFoundException( + ReplicaNotFoundException.NON_EXISTENT_REPLICA + b); + } else { + throw new ReplicaNotFoundException( + ReplicaNotFoundException.UNEXPECTED_GS_REPLICA + b); + } } return info; } @@ -1996,14 +2002,18 @@ class FsDatasetImpl implements FsDatasetSpi { try(AutoCloseableLock lock = datasetLock.acquire()) { final ReplicaInfo info = volumeMap.get(bpid, invalidBlks[i]); if (info == null) { - // It is okay if the block is not found -- it may be deleted earlier. - LOG.info("Failed to delete replica " + invalidBlks[i] - + ": ReplicaInfo not found."); - continue; - } - if (info.getGenerationStamp() != invalidBlks[i].getGenerationStamp()) { - errors.add("Failed to delete replica " + invalidBlks[i] - + ": GenerationStamp not matched, info=" + info); + ReplicaInfo infoByBlockId = + volumeMap.get(bpid, invalidBlks[i].getBlockId()); + if (infoByBlockId == null) { + // It is okay if the block is not found -- it + // may be deleted earlier. + LOG.info("Failed to delete replica " + invalidBlks[i] + + ": ReplicaInfo not found."); + } else { + errors.add("Failed to delete replica " + invalidBlks[i] + + ": GenerationStamp not matched, existing replica is " + + Block.toString(infoByBlockId)); + } continue; } f = info.getBlockFile();