Skip to content

Commit 50b7f9c

Browse files
committed
Fix naming conventions and supplement UT
1 parent 2537597 commit 50b7f9c

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ private static INodeDirectory createRoot(FSNamesystem namesystem) {
217217
// authorizeWithContext() API or not.
218218
private boolean useAuthorizationWithContextAPI = false;
219219

220+
// We need a maximum maximum because by default, PB limits message sizes
221+
// to 64MB. This means we can only store approximately 6.7 million entries
222+
// per directory, but let's use 6.4 million for some safety.
220223
private static final int maxDirItemsLimit = 64 * 100 * 1000;
221224

222225
public void setINodeAttributeProvider(
@@ -397,9 +400,6 @@ public enum DirOp {
397400
Preconditions.checkArgument(this.inodeXAttrsLimit >= 0,
398401
"Cannot set a negative limit on the number of xattrs per inode (%s).",
399402
DFSConfigKeys.DFS_NAMENODE_MAX_XATTRS_PER_INODE_KEY);
400-
// We need a maximum maximum because by default, PB limits message sizes
401-
// to 64MB. This means we can only store approximately 6.7 million entries
402-
// per directory, but let's use 6.4 million for some safety.
403403
Preconditions.checkArgument(
404404
maxDirItems > 0 && maxDirItems <= maxDirItemsLimit, "Cannot set "
405405
+ DFSConfigKeys.DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY
@@ -582,7 +582,7 @@ String setProtectedDirectories(String protectedDirsString) {
582582
}
583583

584584
public void setMaxDirItems(int newVal) {
585-
com.google.common.base.Preconditions.checkArgument(
585+
Preconditions.checkArgument(
586586
newVal > 0 && newVal <= maxDirItemsLimit, "Cannot set "
587587
+ DFSConfigKeys.DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY
588588
+ " to a value less than 1 or greater than " + maxDirItemsLimit);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,7 @@ protected String reconfigurePropertyImpl(String property, String newVal)
23922392
|| property.equals(DFS_NAMENODE_WRITE_LOCK_REPORTING_THRESHOLD_MS_KEY)) {
23932393
return reconfigureFSNamesystemLockMetricsParameters(property, newVal);
23942394
} else if (property.equals(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY)) {
2395-
return reconfMaxDirItems(newVal);
2395+
return reconfigureMaxDirItems(newVal);
23962396
} else {
23972397
throw new ReconfigurationException(property, newVal, getConf().get(
23982398
property));
@@ -2811,7 +2811,7 @@ private String reconfigureFSNamesystemLockMetricsParameters(final String propert
28112811
}
28122812
}
28132813

2814-
private String reconfMaxDirItems(String newVal) throws ReconfigurationException {
2814+
private String reconfigureMaxDirItems(String newVal) throws ReconfigurationException {
28152815
int newSetting;
28162816
namesystem.writeLock(RwLockMode.BM);
28172817
try {
@@ -2824,7 +2824,7 @@ private String reconfMaxDirItems(String newVal) throws ReconfigurationException
28242824
throw new ReconfigurationException(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY, newVal,
28252825
getConf().get(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY), e);
28262826
} finally {
2827-
namesystem.writeUnlock(RwLockMode.BM, "reconfMaxDirItems");
2827+
namesystem.writeUnlock(RwLockMode.BM, "reconfigureMaxDirItems");
28282828
}
28292829
}
28302830

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -867,20 +867,29 @@ public void testReconfigureSlowPeerCollectInterval() throws Exception {
867867
}
868868

869869
@Test
870-
public void testReconfigureMaxDirItems()
871-
throws ReconfigurationException {
870+
public void testReconfigureMaxDirItems() throws Exception {
872871
final NameNode nameNode = cluster.getNameNode();
873872
final FSDirectory fsd = nameNode.namesystem.getFSDirectory();
874873

875-
// By default, DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY is 1024*1024.
876-
assertEquals(1024*1024, fsd.getMaxDirItems());
874+
// By default, DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY is 1024 * 1024.
875+
assertEquals(1024 * 1024, fsd.getMaxDirItems());
877876

878877
// Reconfigure.
879-
nameNode.reconfigureProperty(
880-
DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY, Integer.toString(1024*1024*2));
878+
nameNode.reconfigureProperty(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY,
879+
Integer.toString(1024 * 1024 * 2));
881880

882-
// Assert DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY is 10.
883-
assertEquals(1024*1024*2, fsd.getMaxDirItems());
881+
// Assert DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY is 1024 * 1024 * 2.
882+
assertEquals(1024 * 1024 * 2, fsd.getMaxDirItems());
883+
884+
// Reconfigure to negative, and expect failed.
885+
LambdaTestUtils.intercept(ReconfigurationException.class,
886+
"Could not change property dfs.namenode.fs-limits.max-directory-items from '"
887+
+ 1024 * 1024 * 2 + "' to '" + 1024 * 1024 * -1 + "'",
888+
() -> nameNode.reconfigureProperty(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY,
889+
Integer.toString(1024 * 1024 * -1)));
890+
891+
// Assert DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY is also 1024 * 1024 * 2.
892+
assertEquals(1024 * 1024 * 2, fsd.getMaxDirItems());
884893
}
885894

886895
@AfterEach

0 commit comments

Comments
 (0)