HDFS-13868. WebHDFS: GETSNAPSHOTDIFF API NPE when param "snapshotname" is given but "oldsnapshotname" is not. Contributed by Pranay Singh.
This commit is contained in:
parent
e435e12f1f
commit
28ceb34a72
@ -2158,6 +2158,10 @@ public SnapshotDiffReport getSnapshotDiffReport(String snapshotDir,
|
||||
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) {
|
||||
|
@ -277,7 +277,7 @@ SnapshotDiffInfo computeDiff(final INodeDirectory snapshotRootDir,
|
||||
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,
|
||||
|
@ -230,6 +230,12 @@ public void testDiffReport() throws Exception {
|
||||
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());
|
||||
|
@ -743,6 +743,12 @@ public void testWebHdfsSnapshotDiff() throws Exception {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user