Skip to content

Commit bd7baea

Browse files
committed
HDFS-14396. Failed to load image from FSImageFile when downgrade from 3.x to 2.x. Contributed by Fei Hui.
1 parent edd7085 commit bd7baea

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,8 @@ private long saveInternal(FileOutputStream fout,
813813
FSImageCompression compression, String filePath) throws IOException {
814814
StartupProgress prog = NameNode.getStartupProgress();
815815
MessageDigest digester = MD5Hash.getDigester();
816+
int layoutVersion =
817+
context.getSourceNamesystem().getEffectiveLayoutVersion();
816818

817819
underlyingOutputStream = new DigestOutputStream(new BufferedOutputStream(
818820
fout), digester);
@@ -839,11 +841,16 @@ private long saveInternal(FileOutputStream fout,
839841
// depends on this behavior.
840842
context.checkCancelled();
841843

844+
Step step;
845+
842846
// Erasure coding policies should be saved before inodes
843-
Step step = new Step(StepType.ERASURE_CODING_POLICIES, filePath);
844-
prog.beginStep(Phase.SAVING_CHECKPOINT, step);
845-
saveErasureCodingSection(b);
846-
prog.endStep(Phase.SAVING_CHECKPOINT, step);
847+
if (NameNodeLayoutVersion.supports(
848+
NameNodeLayoutVersion.Feature.ERASURE_CODING, layoutVersion)) {
849+
step = new Step(StepType.ERASURE_CODING_POLICIES, filePath);
850+
prog.beginStep(Phase.SAVING_CHECKPOINT, step);
851+
saveErasureCodingSection(b);
852+
prog.endStep(Phase.SAVING_CHECKPOINT, step);
853+
}
847854

848855
step = new Step(StepType.INODES, filePath);
849856
prog.beginStep(Phase.SAVING_CHECKPOINT, step);

0 commit comments

Comments
 (0)