This is an automated email from the ASF dual-hosted git repository. szetszwo pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push: new 1e6411c9ec6 HDFS-17528. FsImageValidation: set txid when saving a new image (#6828) 1e6411c9ec6 is described below commit 1e6411c9ec610f406f71a8d9f54d32a400c26815 Author: Tsz-Wo Nicholas Sze <szets...@apache.org> AuthorDate: Wed Jun 19 11:38:17 2024 +0800 HDFS-17528. FsImageValidation: set txid when saving a new image (#6828) --- .../org/apache/hadoop/hdfs/server/namenode/FSImage.java | 13 +++++++++---- .../hadoop/hdfs/server/namenode/FsImageValidation.java | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java index f9b796551d6..fa321fe85e5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java @@ -977,12 +977,16 @@ public class FSImage implements Closeable { " but expecting " + expectedMd5); } - long txId = loader.getLoadedImageTxId(); + final long txId = setLastAppliedTxId(loader); LOG.info("Loaded image for txid " + txId + " from " + curFile); - lastAppliedTxId = txId; storage.setMostRecentCheckpointInfo(txId, curFile.lastModified()); } + synchronized long setLastAppliedTxId(FSImageFormat.LoaderDelegator loader) { + lastAppliedTxId = loader.getLoadedImageTxId(); + return lastAppliedTxId; + } + /** * Save the contents of the FS image to the file. */ @@ -1215,8 +1219,9 @@ public class FSImage implements Closeable { } void save(FSNamesystem src, File dst) throws IOException { - final SaveNamespaceContext context = new SaveNamespaceContext(src, - getCorrectLastAppliedOrWrittenTxId(), new Canceler()); + final long txid = getCorrectLastAppliedOrWrittenTxId(); + LOG.info("save fsimage with txid={} to {}", txid, dst.getAbsolutePath()); + final SaveNamespaceContext context = new SaveNamespaceContext(src, txid, new Canceler()); final Storage.StorageDirectory storageDirectory = new Storage.StorageDirectory(dst); Files.createDirectories(storageDirectory.getCurrentDir().toPath()); new FSImageSaver(context, storageDirectory, NameNodeFile.IMAGE).run(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FsImageValidation.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FsImageValidation.java index 275be905051..4dac221e4d2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FsImageValidation.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FsImageValidation.java @@ -214,6 +214,7 @@ public class FsImageValidation { initConf(conf); // check INodeReference + NameNode.initMetrics(conf, HdfsServerConstants.NamenodeRole.NAMENODE); // to avoid NPE final FSNamesystem namesystem = checkINodeReference(conf, errorCount); // check INodeMap @@ -276,14 +277,16 @@ public class FsImageValidation { namesystem.getFSDirectory().writeLock(); try { loader.load(fsImageFile, false); + fsImage.setLastAppliedTxId(loader); } finally { namesystem.getFSDirectory().writeUnlock(); namesystem.writeUnlock("loadImage"); } } t.cancel(); - Cli.println("Loaded %s %s successfully in %s", - FS_IMAGE, fsImageFile, StringUtils.formatTime(now() - loadStart)); + Cli.println("Loaded %s %s with txid %d successfully in %s", + FS_IMAGE, fsImageFile, namesystem.getFSImage().getLastAppliedTxId(), + StringUtils.formatTime(now() - loadStart)); return namesystem; } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org