Source:
public void testSnapshotLimitOnRestart() throws Exception { final Configuration conf = new Configuration(); final Path snapshottableDir = new Path("/" + getClass().getSimpleName()); int numSnapshots = 5; conf.setInt(DFSConfigKeys. DFS_NAMENODE_SNAPSHOT_MAX_LIMIT, numSnapshots); conf.setInt(DFSConfigKeys.DFS_NAMENODE_SNAPSHOT_FILESYSTEM_LIMIT, numSnapshots * 2); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf). numDataNodes(0).build(); cluster.waitActive(); DistributedFileSystem hdfs = cluster.getFileSystem(); hdfs.mkdirs(snapshottableDir); hdfs.allowSnapshot(snapshottableDir); int i = 0; for (; i < numSnapshots; i++) { hdfs.createSnapshot(snapshottableDir, "s" + i); } LambdaTestUtils.intercept(SnapshotException.class, "snapshot limit", () -> hdfs.createSnapshot(snapshottableDir, "s5")); cluster.getNameNode().getConf().setInt(DFSConfigKeys. DFS_NAMENODE_SNAPSHOT_MAX_LIMIT, 2); cluster.restartNameNodes(); SnapshotManager snapshotManager = cluster.getNamesystem(). getSnapshotManager(); Assert.assertEquals(numSnapshots, snapshotManager.getNumSnapshots()); Assert.assertEquals(2, snapshotManager.getMaxSnapshotLimit()); LambdaTestUtils.intercept(SnapshotException.class, "snapshot limit", () -> hdfs.createSnapshot(snapshottableDir, "s5")); cluster.getNameNode().getConf().setInt(DFSConfigKeys. DFS_NAMENODE_SNAPSHOT_FILESYSTEM_LIMIT, 2); cluster.restartNameNodes(); snapshotManager = cluster.getNamesystem(). getSnapshotManager(); Assert.assertEquals(numSnapshots, snapshotManager.getNumSnapshots()); Assert.assertEquals(2, snapshotManager.getMaxSnapshotLimit()); }

Target:
public void testSnapshotLimitOnRestart() throws Exception { final Configuration conf = new Configuration(); final Path snapshottableDir = new Path("/" + getClass().getSimpleName()); int numSnapshots = 5; conf.setInt(DFSConfigKeys. DFS_NAMENODE_SNAPSHOT_MAX_LIMIT, numSnapshots); conf.setInt(DFSConfigKeys.DFS_NAMENODE_SNAPSHOT_FILESYSTEM_LIMIT, numSnapshots * 2); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf). numDataNodes(0).build(); cluster.waitActive(); DistributedFileSystem hdfs = cluster.getFileSystem(); hdfs.mkdirs(snapshottableDir); hdfs.allowSnapshot(snapshottableDir); for (int i = 0; i < numSnapshots; i++) { hdfs.createSnapshot(snapshottableDir, "s" + i); } LambdaTestUtils.intercept(SnapshotException.class, "snapshot limit", () -> hdfs.createSnapshot(snapshottableDir, "s5")); cluster.getNameNode().getConf().setInt(DFSConfigKeys. DFS_NAMENODE_SNAPSHOT_MAX_LIMIT, 2); cluster.restartNameNodes(); SnapshotManager snapshotManager = cluster.getNamesystem(). getSnapshotManager(); Assert.assertEquals(numSnapshots, snapshotManager.getNumSnapshots()); Assert.assertEquals(2, snapshotManager.getMaxSnapshotLimit()); LambdaTestUtils.intercept(SnapshotException.class, "snapshot limit", () -> hdfs.createSnapshot(snapshottableDir, "s5")); cluster.getNameNode().getConf().setInt(DFSConfigKeys. DFS_NAMENODE_SNAPSHOT_FILESYSTEM_LIMIT, 2); cluster.restartNameNodes(); snapshotManager = cluster.getNamesystem(). getSnapshotManager(); Assert.assertEquals(numSnapshots, snapshotManager.getNumSnapshots()); Assert.assertEquals(2, snapshotManager.getMaxSnapshotLimit()); } finally { if (cluster != null) { cluster.shutdown(); } } }