From 63d301e1d52fe1c5bc0ca674f768be69a98bfd4f Mon Sep 17 00:00:00 2001 From: zeekling Date: Sat, 13 Apr 2024 23:52:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?FSDirectory=E8=AF=A6=E8=A7=A3:=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hdfs/FSDirectory详解.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hdfs/FSDirectory详解.md b/hdfs/FSDirectory详解.md index f931704..1190654 100644 --- a/hdfs/FSDirectory详解.md +++ b/hdfs/FSDirectory详解.md @@ -96,3 +96,16 @@ fsd.updateCount(iip, context.quotaDelta(), false); - 删除EditLog。 - 调用incrDeletedFileCount更新metrics信息。 +### 创建文件 + +**接口** + +```java +HdfsFileStatus startFile(String src, PermissionStatus permissions, + String holder, String clientMachine, EnumSet flag, + boolean createParent, short replication, long blockSize, + CryptoProtocolVersion[] supportedVersions, String ecPolicyName, + String storagePolicy, boolean logRetryCache) throws IOException { +} +``` + -- 2.45.2 From 09851a8e69eb8690744cd32d65abeadffeb11e43 Mon Sep 17 00:00:00 2001 From: zeekling Date: Sun, 14 Apr 2024 22:38:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?FSDirectory=E8=AF=A6=E8=A7=A3:=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hdfs/FSDirectory详解.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/hdfs/FSDirectory详解.md b/hdfs/FSDirectory详解.md index 1190654..b99b078 100644 --- a/hdfs/FSDirectory详解.md +++ b/hdfs/FSDirectory详解.md @@ -109,3 +109,40 @@ HdfsFileStatus startFile(String src, PermissionStatus permissions, } ``` +- 检查当前用户是否有写权限。 +- 检查是否处于安全模式,如果处于安全模式,则不能进行当前操作。 +- 检查是否对当前文件所在的目录是否有权限(开启权限管理的情况下) +- 调用FSDirWriteFileOp.startFile开始创建文件或者覆盖已有文件。 + - 对于已经存在的文件。在覆盖的场景下。主要核心代码如下,会将原来的文件删除。并且释放租约。 + ```java + List toRemoveINodes = new ChunkedArrayList<>(); + List toRemoveUCFiles = new ChunkedArrayList<>(); + long ret = FSDirDeleteOp.delete(fsd, iip, toRemoveBlocks, + toRemoveINodes, toRemoveUCFiles, now()); + if (ret >= 0) { + iip = INodesInPath.replace(iip, iip.length() - 1, null); + FSDirDeleteOp.incrDeletedFileCount(ret); + fsn.removeLeasesAndINodes(toRemoveUCFiles, toRemoveINodes, true); + } + ``` + - 对于不需要覆盖的场景下,需要重新刷新租约信息。 + ```java + fsn.recoverLeaseInternal(FSNamesystem.RecoverLeaseOp.CREATE_FILE, iip, + src, holder, clientMachine, false); + ``` + - 对于父文件夹存在的时候,将文件添加到父文件夹下面。 + ```java + iip = addFile(fsd, parent, iip.getLastLocalName(), permissions, + replication, blockSize, holder, clientMachine, shouldReplicate, + ecPolicyName, storagePolicy); + newNode = iip != null ? iip.getLastINode().asFile() : null; + ``` + - 添加租约信息。 + ```java + fsn.leaseManager.addLease( + newNode.getFileUnderConstructionFeature().getClientName(), + newNode.getId()); + ``` + - 返回文件信息。 + + -- 2.45.2