HDFS-13868. WebHDFS: GETSNAPSHOTDIFF API NPE when param "snapshotname" is given but "oldsnapshotname" is not. Contributed by Pranay Singh.

This commit is contained in:
Wei-Chiu Chuang 2018-09-19 03:11:29 -07:00
parent e435e12f1f
commit 28ceb34a72
4 changed files with 17 additions and 1 deletions

View File

@ -2158,6 +2158,10 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory,
String fromSnapshot, String toSnapshot) throws IOException {
checkOpen();
try (TraceScope ignored = tracer.newScope("getSnapshotDiffReport")) {
Preconditions.checkArgument(fromSnapshot != null,
"null fromSnapshot");
Preconditions.checkArgument(toSnapshot != null,
"null toSnapshot");
return namenode
.getSnapshotDiffReport(snapshotDir, fromSnapshot, toSnapshot);
} catch (RemoteException re) {

View File

@ -277,7 +277,7 @@ public class DirectorySnapshottableFeature extends DirectoryWithSnapshotFeature
Snapshot fromSnapshot = getSnapshotByName(snapshotRootDir, from);
Snapshot toSnapshot = getSnapshotByName(snapshotRootDir, to);
// if the start point is equal to the end point, return null
if (from.equals(to)) {
if (from != null && from.equals(to)) {
return null;
}
SnapshotDiffInfo diffs = new SnapshotDiffInfo(snapshotRootDir,

View File

@ -230,6 +230,12 @@ public class TestSnapshotDiffReport {
LOG.info(report.toString());
assertEquals(0, report.getDiffList().size());
try {
report = hdfs.getSnapshotDiffReport(subsubsub1, null, "s2");
fail("Expect exception when providing null fromSnapshot ");
} catch (IllegalArgumentException e) {
GenericTestUtils.assertExceptionContains("null fromSnapshot", e);
}
report = hdfs.getSnapshotDiffReport(subsubsub1, "s0", "s2");
LOG.info(report.toString());
assertEquals(0, report.getDiffList().size());

View File

@ -743,6 +743,12 @@ public class TestWebHDFS {
Assert.assertTrue(diffReport.getDiffList().contains(entry3));
Assert.assertTrue(diffReport.getDiffList().contains(entry4));
Assert.assertEquals(diffReport.getDiffList().size(), 5);
// Test with fromSnapshot and toSnapshot as null.
diffReport = webHdfs.getSnapshotDiffReport(foo, null, "s2");
Assert.assertEquals(diffReport.getDiffList().size(), 0);
diffReport = webHdfs.getSnapshotDiffReport(foo, "s1", null);
Assert.assertEquals(diffReport.getDiffList().size(), 5);
} finally {
if (cluster != null) {
cluster.shutdown();