From bd7baea5a5d4ff351645e34c0ef09b7ba82f4285 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Fri, 23 Aug 2019 15:27:32 +0900 Subject: [PATCH] HDFS-14396. Failed to load image from FSImageFile when downgrade from 3.x to 2.x. Contributed by Fei Hui. --- .../server/namenode/FSImageFormatProtobuf.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java index 3144d4b17c..51379b8657 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java @@ -813,6 +813,8 @@ private long saveInternal(FileOutputStream fout, FSImageCompression compression, String filePath) throws IOException { StartupProgress prog = NameNode.getStartupProgress(); MessageDigest digester = MD5Hash.getDigester(); + int layoutVersion = + context.getSourceNamesystem().getEffectiveLayoutVersion(); underlyingOutputStream = new DigestOutputStream(new BufferedOutputStream( fout), digester); @@ -839,11 +841,16 @@ private long saveInternal(FileOutputStream fout, // depends on this behavior. context.checkCancelled(); + Step step; + // Erasure coding policies should be saved before inodes - Step step = new Step(StepType.ERASURE_CODING_POLICIES, filePath); - prog.beginStep(Phase.SAVING_CHECKPOINT, step); - saveErasureCodingSection(b); - prog.endStep(Phase.SAVING_CHECKPOINT, step); + if (NameNodeLayoutVersion.supports( + NameNodeLayoutVersion.Feature.ERASURE_CODING, layoutVersion)) { + step = new Step(StepType.ERASURE_CODING_POLICIES, filePath); + prog.beginStep(Phase.SAVING_CHECKPOINT, step); + saveErasureCodingSection(b); + prog.endStep(Phase.SAVING_CHECKPOINT, step); + } step = new Step(StepType.INODES, filePath); prog.beginStep(Phase.SAVING_CHECKPOINT, step);