Skip to content

Commit 3b3b34e

Browse files
committed
fix snapshot scenarios
1 parent d2832de commit 3b3b34e

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ private static Triple<Boolean, Optional<QuotaCounts>, Optional<QuotaCounts>> ver
8282
return Triple.of(false, srcDelta, dstDelta);
8383
}
8484

85-
// Verify srcPath and dstPath without valid 'DirectoryWithQuotaFeature'
86-
// Note: In overwrite scenarios, quota calculation is still required because:
87-
// Overwrite operations delete existing content (affecting rootDir's quota)
88-
if (!overwrite && FSDirectory.verifyPathWithoutValidQuotaFeature(src)
89-
&& FSDirectory.verifyPathWithoutValidQuotaFeature(dst)) {
85+
// Verify path without valid 'DirectoryWithQuotaFeature'
86+
// Note: In overwrite scenarios, quota calculation is still required,
87+
// overwrite operations delete existing content, which affects the root directory's quota.
88+
if (!overwrite && FSDirectory.verifyPathWithoutValidFeature(src)
89+
&& FSDirectory.verifyPathWithoutValidFeature(dst)) {
9090
return Triple.of(false, srcDelta, dstDelta);
9191
}
9292

@@ -722,8 +722,8 @@ private static class RenameOperation {
722722
} else {
723723
withCount = null;
724724
}
725-
this.updateQuota = quotaPair.getLeft();
726725
// Set quota for src and dst, ignore src is in Snapshot or is Reference
726+
this.updateQuota = quotaPair.getLeft() || isSrcInSnapshot || srcChildIsReference;
727727
this.srcSubTreeCount = withCount == null ?
728728
quotaPair.getMiddle() : Optional.empty();
729729
this.dstSubTreeCount = quotaPair.getRight();

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.namenode;
1919

20+
import org.apache.hadoop.hdfs.server.namenode.snapshot.DirectorySnapshottableFeature;
2021
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
2122
import org.apache.hadoop.util.StringUtils;
2223

@@ -1244,18 +1245,16 @@ static void verifyQuota(INodesInPath iip, int pos, QuotaCounts deltas,
12441245

12451246
/**
12461247
* Verifies that the path from the specified position to the root
1247-
* (excluding the root itself) does not contain any valid quota features.
1248+
* does not contain any valid features.
12481249
*
12491250
* @param iip the INodesInPath containing all the ancestral INodes.
1250-
* @return true if no valid quota features are found along the path (root excluded),
1251-
* false if any directory in the path has an active quota feature.
1251+
* @return true if no valid features are found along the path,
1252+
* false if any directory in the path has an active feature.
12521253
*/
1253-
static boolean verifyPathWithoutValidQuotaFeature(INodesInPath iip) {
1254-
// Exclude the root inode
1254+
static boolean verifyPathWithoutValidFeature(INodesInPath iip) {
12551255
for (int i = iip.length() - 2; i >= 1; i--) {
1256-
final DirectoryWithQuotaFeature q =
1257-
iip.getINode(i).asDirectory().getDirectoryWithQuotaFeature();
1258-
if (q != null) {
1256+
INodeDirectory d = iip.getINode(i).asDirectory();
1257+
if (d.isWithQuota()) {
12591258
return false;
12601259
}
12611260
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCorrectnessOfQuotaAfterRenameOp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void testQuotaUsageWhenRenameWithDifferStoragePolicy() throws Exception {
169169
}
170170

171171
@Test
172-
public void testRenameWithoutValidQuotaFeature() throws Exception {
172+
public void testRenameWithoutValidFeature() throws Exception {
173173
final int fileLen = 1024;
174174
final short replication = 3;
175175
final Path root = new Path("/testRename");

0 commit comments

Comments
 (0)