Skip to content

Commit b47f4d9

Browse files
committed
Fix naming conventions and supplement UT
1 parent d64b0ca commit b47f4d9

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-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
@@ -2391,7 +2391,7 @@ protected String reconfigurePropertyImpl(String property, String newVal)
23912391
|| property.equals(DFS_NAMENODE_WRITE_LOCK_REPORTING_THRESHOLD_MS_KEY)) {
23922392
return reconfigureFSNamesystemLockMetricsParameters(property, newVal);
23932393
} else if (property.equals(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY)) {
2394-
return reconfMaxDirItems(newVal);
2394+
return reconfigureMaxDirItems(newVal);
23952395
} else {
23962396
throw new ReconfigurationException(property, newVal, getConf().get(
23972397
property));
@@ -2810,7 +2810,7 @@ private String reconfigureFSNamesystemLockMetricsParameters(final String propert
28102810
}
28112811
}
28122812

2813-
private String reconfMaxDirItems(String newVal) throws ReconfigurationException {
2813+
private String reconfigureMaxDirItems(String newVal) throws ReconfigurationException {
28142814
int newSetting;
28152815
namesystem.writeLock(RwLockMode.BM);
28162816
try {
@@ -2823,7 +2823,7 @@ private String reconfMaxDirItems(String newVal) throws ReconfigurationException
28232823
throw new ReconfigurationException(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY, newVal,
28242824
getConf().get(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY), e);
28252825
} finally {
2826-
namesystem.writeUnlock(RwLockMode.BM, "reconfMaxDirItems");
2826+
namesystem.writeUnlock(RwLockMode.BM, "reconfigureMaxDirItems");
28272827
}
28282828
}
28292829

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

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

869869
@Test
870-
public void testReconfigureMaxDirItems()
871-
throws ReconfigurationException {
870+
public void testReconfigureMaxDirItems() throws ReconfigurationException {
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+
try {
885+
// Reconfigure to negative, and expect failed.
886+
nameNode.reconfigureProperty(DFS_NAMENODE_MAX_DIRECTORY_ITEMS_KEY,
887+
Integer.toString(1024 * 1024 * -1));
888+
} catch (ReconfigurationException e) {
889+
assertEquals("Could not change property " +
890+
"dfs.namenode.fs-limits.max-directory-items from '" + 1024 * 1024 * 2
891+
+ "' to '" + 1024 * 1024 * -1 + "'", e.getMessage());
892+
}
893+
894+
// Assert DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY is also 1024 * 1024 * 2.
895+
assertEquals(1024 * 1024 * 2, fsd.getMaxDirItems());
884896
}
885897

886898
@AfterEach

0 commit comments

Comments
 (0)