From edfde6eebcf5ef638706dbae0bd07172aa5ab4a9 Mon Sep 17 00:00:00 2001 From: jianghuazhu <740087514@qq.com> Date: Sun, 12 Sep 2021 19:58:30 +0800 Subject: [PATCH] HDFS-16197.Simplify getting NNStorage in FSNamesystem. (#3357) --- .../hdfs/server/namenode/FSNamesystem.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index c4051b22625..a9fce49d46f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -4639,6 +4639,10 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, return getFSImage().getEditLog(); } + private NNStorage getNNStorage() { + return getFSImage().getStorage(); + } + @Metric({"MissingBlocks", "Number of missing blocks"}) public long getMissingBlocksCount() { // not locking @@ -4662,7 +4666,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, "Number of transactions since last checkpoint"}) public long getTransactionsSinceLastCheckpoint() { return getFSImage().getLastAppliedOrWrittenTxId() - - getFSImage().getStorage().getMostRecentCheckpointTxId(); + getNNStorage().getMostRecentCheckpointTxId(); } @Metric({"TransactionsSinceLastLogRoll", @@ -4697,7 +4701,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, @Metric({"LastCheckpointTime", "Time in milliseconds since the epoch of the last checkpoint"}) public long getLastCheckpointTime() { - return getFSImage().getStorage().getMostRecentCheckpointTime(); + return getNNStorage().getMostRecentCheckpointTime(); } /** @see ClientProtocol#getStats() */ @@ -4967,10 +4971,10 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, // if it is disabled - enable it and vice versa. if(arg.equals("check")) { - val = getFSImage().getStorage().getRestoreFailedStorage(); + val = getNNStorage().getRestoreFailedStorage(); } else { val = arg.equals("true"); // false if not - getFSImage().getStorage().setRestoreFailedStorage(val); + getNNStorage().setRestoreFailedStorage(val); } } finally { writeUnlock(operationName, getLockReportInfoSupplier(null)); @@ -5969,11 +5973,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, NamenodeRegistration nnReg) throws IOException { writeLock(); try { - if(getFSImage().getStorage().getNamespaceID() + if(getNNStorage().getNamespaceID() != bnReg.getNamespaceID()) throw new IOException("Incompatible namespaceIDs: " + " Namenode namespaceID = " - + getFSImage().getStorage().getNamespaceID() + "; " + + getNNStorage().getNamespaceID() + "; " + bnReg.getRole() + " node namespaceID = " + bnReg.getNamespaceID()); if (bnReg.getRole() == NamenodeRole.BACKUP) { @@ -5997,11 +6001,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, writeLock(); try { checkOperation(OperationCategory.WRITE); - if(getFSImage().getStorage().getNamespaceID() + if(getNNStorage().getNamespaceID() != registration.getNamespaceID()) throw new IOException("Incompatible namespaceIDs: " + " Namenode namespaceID = " - + getFSImage().getStorage().getNamespaceID() + "; " + + getNNStorage().getNamespaceID() + "; " + registration.getRole() + " node namespaceID = " + registration.getNamespaceID()); getEditLog().releaseBackupStream(registration); @@ -6635,7 +6639,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, @Override // NameNodeMXBean public String getClusterId() { - return getFSImage().getStorage().getClusterID(); + return getNNStorage().getClusterID(); } @Override // NameNodeMXBean @@ -6650,14 +6654,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, Map activeDirs = new HashMap(); for (Iterator it - = getFSImage().getStorage().dirIterator(); it.hasNext();) { + = getNNStorage().dirIterator(); it.hasNext();) { StorageDirectory st = it.next(); activeDirs.put(st.getRoot(), st.getStorageDirType()); } statusMap.put("active", activeDirs); List removedStorageDirs - = getFSImage().getStorage().getRemovedStorageDirs(); + = getNNStorage().getRemovedStorageDirs(); Map failedDirs = new HashMap(); for (StorageDirectory st : removedStorageDirs) { failedDirs.put(st.getRoot(), st.getStorageDirType()); @@ -6908,7 +6912,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, @Override // NameNodeStatusMXBean public String getNameDirSize() { - return getFSImage().getStorage().getNNDirectorySize(); + return getNNStorage().getNNDirectorySize(); } /**