Browse Source

HDFS-15201 SnapshotCounter hits MaxSnapshotID limit (#1870)

Karthik Palanisamy 5 years ago
parent
commit
5250cd6db3

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java

@@ -96,7 +96,7 @@ public class SnapshotManager implements SnapshotStatsMXBean {
   private final boolean snapshotDiffAllowSnapRootDescendant;
 
   private final AtomicInteger numSnapshots = new AtomicInteger();
-  private static final int SNAPSHOT_ID_BIT_WIDTH = 24;
+  private static final int SNAPSHOT_ID_BIT_WIDTH = 28;
 
   private boolean allowNestedSnapshots = false;
   private int snapshotCounter = 0;
@@ -541,7 +541,7 @@ public class SnapshotManager implements SnapshotStatsMXBean {
    *
    * @return maximum allowable snapshot ID.
    */
-   public int getMaxSnapshotID() {
+  public int getMaxSnapshotID() {
     return ((1 << SNAPSHOT_ID_BIT_WIDTH) - 1);
   }
 

+ 14 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotManager.java

@@ -92,4 +92,18 @@ public class TestSnapshotManager {
           StringUtils.toLowerCase(se.getMessage()).contains("rollover"));
     }
   }
+
+  /**
+   *  Snapshot is identified by INODE CURRENT_STATE_ID.
+   *  So maximum allowable snapshotID should be less than CURRENT_STATE_ID
+   */
+  @Test
+  public void testValidateSnapshotIDWidth() {
+    FSDirectory fsdir = mock(FSDirectory.class);
+    SnapshotManager snapshotManager = new SnapshotManager(new Configuration(),
+        fsdir);
+    Assert.assertTrue(snapshotManager.
+        getMaxSnapshotID() < Snapshot.CURRENT_STATE_ID);
+  }
+
 }