HDFS-6068. Disallow snapshot names that are also invalid directory names. Contributed by sathish

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1579004 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2014-03-18 18:34:19 +00:00
parent bd98fa152d
commit 02b25ce4ef
3 changed files with 12 additions and 3 deletions

View File

@ -415,6 +415,9 @@ Release 2.4.0 - UNRELEASED
HDFS-6090. Use MiniDFSCluster.Builder instead of deprecated constructors.
(Akira AJISAKA via jing9)
HDFS-6068. Disallow snapshot names that are also invalid directory names.
(sathish via szetszwo)
OPTIMIZATIONS
HDFS-5790. LeaseManager.findPath is very slow when many leases need recovery

View File

@ -6933,6 +6933,12 @@ String createSnapshot(String snapshotRoot, String snapshotName)
if (snapshotName == null || snapshotName.isEmpty()) {
snapshotName = Snapshot.generateDefaultSnapshotName();
}
if(snapshotName != null){
if (!DFSUtil.isValidNameForComponent(snapshotName)) {
throw new InvalidPathException("Invalid snapshot name: "
+ snapshotName);
}
}
dir.verifySnapshotName(snapshotName, snapshotRoot);
dir.writeLock();
try {

View File

@ -337,12 +337,11 @@ public void testCreateSnapshotWithIllegalName() throws Exception {
hdfs.createSnapshot(dir, name1);
fail("Exception expected when an illegal name is given");
} catch (RemoteException e) {
String errorMsg = "\"" + HdfsConstants.DOT_SNAPSHOT_DIR
+ "\" is a reserved name.";
String errorMsg = "Invalid path name Invalid snapshot name: " + name1;
GenericTestUtils.assertExceptionContains(errorMsg, e);
}
String errorMsg = "Snapshot name cannot contain \"" + Path.SEPARATOR + "\"";
final String[] badNames = new String[] { "foo" + Path.SEPARATOR,
Path.SEPARATOR + "foo", Path.SEPARATOR, "foo" + Path.SEPARATOR + "bar" };
for (String badName : badNames) {
@ -350,6 +349,7 @@ public void testCreateSnapshotWithIllegalName() throws Exception {
hdfs.createSnapshot(dir, badName);
fail("Exception expected when an illegal name is given");
} catch (RemoteException e) {
String errorMsg = "Invalid path name Invalid snapshot name: " + badName ;
GenericTestUtils.assertExceptionContains(errorMsg, e);
}
}