From 8d242458e96c7a9bcd5390a32dc9324be93cf5fc Mon Sep 17 00:00:00 2001 From: zeekling Date: Wed, 27 Mar 2024 23:42:27 +0800 Subject: [PATCH] =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0hdfs=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/apache/hadoop/hdfs/server/namenode/FSDirectory.java | 6 ++++++ .../apache/hadoop/hdfs/server/namenode/FSNamesystem.java | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java index fc17eaebf7..37b368c31f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java @@ -151,7 +151,10 @@ private static INodeDirectory createRoot(FSNamesystem namesystem) { .isdir(true) .build(); + // 整个文件系统目录树的根节点, 是INodeDirectory类型的 。 INodeDirectory rootDir; + + // Namenode的核心类, 这个类主要支持对数据块进行操作的一些方法, 例如addBlock()。 private final FSNamesystem namesystem; private volatile boolean skipQuotaCheck = false; //skip while consuming edits private final int maxComponentLength; @@ -159,6 +162,7 @@ private static INodeDirectory createRoot(FSNamesystem namesystem) { private final int lsLimit; // max list limit private final int contentCountLimit; // max content summary counts per run private final long contentSleepMicroSec; + // 记录根目录下所有的INode,并维护INodeId ->INode的映射关系。 private final INodeMap inodeMap; // Synchronized by dirLock private long yieldCount = 0; // keep track of lock yield count. private int quotaInitThreads; @@ -300,6 +304,7 @@ public int getListLimit() { /** * Caches frequently used file names used in {@link INode} to reuse * byte[] objects and reduce heap usage. + * 将常用的name缓存下来, 以降低byte[]的使用, 并降低JVM heap的使用 */ private final NameCache nameCache; @@ -318,6 +323,7 @@ public enum DirOp { this.inodeId = new INodeId(); rootDir = createRoot(ns); inodeMap = INodeMap.newInstance(rootDir); + // 是否开启权限管理 this.isPermissionEnabled = conf.getBoolean( DFSConfigKeys.DFS_PERMISSIONS_ENABLED_KEY, DFSConfigKeys.DFS_PERMISSIONS_ENABLED_DEFAULT); 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 b8e687085e..3267b6fc12 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 @@ -1218,12 +1218,13 @@ private List initAuditLoggers(Configuration conf) { return Collections.unmodifiableList(auditLoggers); } + // FSNamesystem在初始化完FSDirectory dir成员,会调用loadFSImage方法,从fsimage和edits加载元数据信息 private void loadFSImage(StartupOption startOpt) throws IOException { final FSImage fsImage = getFSImage(); - // format before starting up if requested + // format before starting up if requested // 如果启动选项类型为FORMAT(格式化),在启动之前需要进行格式化 if (startOpt == StartupOption.FORMAT) { - // reuse current id + // reuse current id 对FSImage执行格式化操作 fsImage.format(this, fsImage.getStorage().determineClusterId(), false); startOpt = StartupOption.REGULAR;