if (s.isAncestorDirectory(dir)) {
throw new SnapshotException(
"Nested snapshottable directories not allowed: path=" + path
- + ", the ancestor " + s.getFullPathName()
+ + ", the subdirectory " + s.getFullPathName()
+ " is already a snapshottable directory.");
}
if (dir.isAncestorDirectory(s)) {
throw new SnapshotException(
"Nested snapshottable directories not allowed: path=" + path
- + ", the subdirectory " + s.getFullPathName()
+ + ", the ancestor " + s.getFullPathName()
+ " is already a snapshottable directory.");
}
}
}
if (s == fsdir.getRoot()) {
+ if (s.getSnapshotQuota() == 0) {
+ throw new SnapshotException("Root is not a snapshottable directory");
+ }
s.setSnapshotQuota(0);
} else {
s.replaceSelf(iip.getLatestSnapshot(), fsdir.getINodeMap());
// (A1) All lists are sorted.
// (A2) All elements in dlist must be in previous.
// (A3) All elements in clist must be not in tmp = previous - dlist.
- final List<E> tmp = new ArrayList<E>();
+ final List<E> tmp = new ArrayList<E>(previous.size() - dlist.size());
{
// tmp = previous - dlist
final Iterator<E> i = previous.iterator();
}
}
- final List<E> current = new ArrayList<E>();
+ final List<E> current = new ArrayList<E>(tmp.size() + clist.size());
{
// current = tmp + clist
final Iterator<E> tmpIterator = tmp.iterator();
import static org.apache.hadoop.hdfs.server.namenode.snapshot.INodeDirectorySnapshottable.SNAPSHOT_LIMIT;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.Random;
import org.apache.hadoop.hdfs.server.namenode.INode;
import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
import org.apache.hadoop.ipc.RemoteException;
+import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
print("delete snapshot " + rootSnapshot);
hdfs.disallowSnapshot(rootPath);
print("disallow snapshot " + rootStr);
+ try {
+ hdfs.disallowSnapshot(rootPath);
+ fail("Expect snapshot exception when disallowing snapshot on root again");
+ } catch (SnapshotException e) {
+ GenericTestUtils.assertExceptionContains(
+ "Root is not a snapshottable directory", e);
+ }
//change foo to non-snapshottable
hdfs.deleteSnapshot(foo, s1name);
hdfs.allowSnapshot(rootPath);
Assert.fail();
} catch(SnapshotException se) {
- assertNestedSnapshotException(se, "ancestor");
+ assertNestedSnapshotException(se, "subdirectory");
}
try {
hdfs.allowSnapshot(foo);
Assert.fail();
} catch(SnapshotException se) {
- assertNestedSnapshotException(se, "ancestor");
+ assertNestedSnapshotException(se, "subdirectory");
}
final Path sub1Bar = new Path(bar, "sub1");
hdfs.allowSnapshot(sub1Bar);
Assert.fail();
} catch(SnapshotException se) {
- assertNestedSnapshotException(se, "subdirectory");
+ assertNestedSnapshotException(se, "ancestor");
}
try {
hdfs.allowSnapshot(sub2Bar);
Assert.fail();
} catch(SnapshotException se) {
- assertNestedSnapshotException(se, "subdirectory");
+ assertNestedSnapshotException(se, "ancestor");
}
}