Skip to content

Commit eea5600

Browse files
authored
HDDS-11911. Return consistent error code when snapshot is not found in the DB or Snapshot Chain. (#7557)
1 parent e8f3b25 commit eea5600

4 files changed

Lines changed: 37 additions & 12 deletions

File tree

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOmSnapshot.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
import static org.apache.hadoop.ozone.om.OmUpgradeConfig.ConfigStrings.OZONE_OM_INIT_DEFAULT_LAYOUT_VERSION;
128128
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_FOUND;
129129
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.CONTAINS_SNAPSHOT;
130+
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
130131
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
131132
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.NOT_SUPPORTED_OPERATION_PRIOR_FINALIZATION;
132133
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
@@ -1602,13 +1603,13 @@ public void testSnapDiffNoSnapshot() throws Exception {
16021603
OMException omException = assertThrows(OMException.class,
16031604
() -> store.snapshotDiff(volume, bucket, snap1, snap2,
16041605
null, 0, false, disableNativeDiff));
1605-
assertEquals(KEY_NOT_FOUND, omException.getResult());
1606+
assertEquals(FILE_NOT_FOUND, omException.getResult());
16061607
// From snapshot is invalid
16071608
omException = assertThrows(OMException.class,
16081609
() -> store.snapshotDiff(volume, bucket, snap2, snap1,
16091610
null, 0, false, disableNativeDiff));
16101611

1611-
assertEquals(KEY_NOT_FOUND, omException.getResult());
1612+
assertEquals(FILE_NOT_FOUND, omException.getResult());
16121613
}
16131614

16141615
@Test
@@ -1699,12 +1700,12 @@ public void testSnapDiffMissingMandatoryParams() throws Exception {
16991700
OMException omException = assertThrows(OMException.class,
17001701
() -> store.snapshotDiff(volume, bucket, snap1, nullstr,
17011702
null, 0, forceFullSnapshotDiff, disableNativeDiff));
1702-
assertEquals(KEY_NOT_FOUND, omException.getResult());
1703+
assertEquals(FILE_NOT_FOUND, omException.getResult());
17031704
// From snapshot is empty
17041705
omException = assertThrows(OMException.class,
17051706
() -> store.snapshotDiff(volume, bucket, nullstr, snap1,
17061707
null, 0, forceFullSnapshotDiff, disableNativeDiff));
1707-
assertEquals(KEY_NOT_FOUND, omException.getResult());
1708+
assertEquals(FILE_NOT_FOUND, omException.getResult());
17081709
// Bucket is empty
17091710
assertThrows(IllegalArgumentException.class,
17101711
() -> store.snapshotDiff(volume, nullstr, snap1, snap2,

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_DIFF_DB_DIR;
100100
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_DIFF_REPORT_MAX_PAGE_SIZE;
101101
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_DIFF_REPORT_MAX_PAGE_SIZE_DEFAULT;
102+
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
102103
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_KEY_NAME;
103-
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_SNAPSHOT_ERROR;
104104
import static org.apache.hadoop.ozone.om.snapshot.SnapshotDiffManager.getSnapshotRootPath;
105105
import static org.apache.hadoop.ozone.om.snapshot.SnapshotUtils.checkSnapshotActive;
106106
import static org.apache.hadoop.ozone.om.snapshot.SnapshotUtils.dropColumnFamilyHandle;
@@ -352,7 +352,8 @@ public OmSnapshot load(@Nonnull UUID snapshotId) throws IOException {
352352
// If it happens, then either snapshot has been purged in between or SnapshotChain is corrupted
353353
// and missing some entries which needs investigation.
354354
if (snapshotTableKey == null) {
355-
throw new IOException("No snapshot exist with snapshotId: " + snapshotId);
355+
throw new OMException("Snapshot " + snapshotId +
356+
" is not found in the snapshot chain.", FILE_NOT_FOUND);
356357
}
357358

358359
final SnapshotInfo snapshotInfo = getSnapshotInfo(snapshotTableKey);
@@ -745,7 +746,7 @@ private SnapshotInfo getSnapshotInfo(String snapshotKey) throws IOException {
745746
snapshotInfo = ozoneManager.getMetadataManager().getSnapshotInfoTable().getSkipCache(snapshotKey);
746747
}
747748
if (snapshotInfo == null) {
748-
throw new OMException("Snapshot '" + snapshotKey + "' is not found.", INVALID_SNAPSHOT_ERROR);
749+
throw new OMException("Snapshot '" + snapshotKey + "' is not found.", FILE_NOT_FOUND);
749750
}
750751
return snapshotInfo;
751752
}

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@
4646
import java.util.UUID;
4747

4848
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
49-
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_SNAPSHOT_ERROR;
5049
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DIRECTORY_TABLE;
5150
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.FILE_TABLE;
5251
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.KEY_TABLE;
5352
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
54-
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
5553
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.TIMEOUT;
5654

5755
/**
@@ -88,7 +86,7 @@ public static SnapshotInfo getSnapshotInfo(final OzoneManager ozoneManager,
8886
}
8987
if (snapshotInfo == null) {
9088
throw new OMException("Snapshot '" + snapshotKey + "' is not found.",
91-
KEY_NOT_FOUND);
89+
FILE_NOT_FOUND);
9290
}
9391
return snapshotInfo;
9492
}
@@ -164,7 +162,7 @@ public static SnapshotInfo getNextSnapshot(OzoneManager ozoneManager,
164162
// is removed in-memory but OMDoubleBuffer has not flushed yet.
165163
if (snapInfo == null) {
166164
throw new OMException("Provided Snapshot Info argument is null. Cannot get the next snapshot for a null value",
167-
INVALID_SNAPSHOT_ERROR);
165+
FILE_NOT_FOUND);
168166
}
169167
try {
170168
if (chainManager.hasNextPathSnapshot(snapInfo.getSnapshotPath(),
@@ -201,7 +199,7 @@ private static UUID getPreviousSnapshotId(SnapshotInfo snapInfo, SnapshotChainMa
201199
// is removed in-memory but OMDoubleBuffer has not flushed yet.
202200
if (snapInfo == null) {
203201
throw new OMException("Provided Snapshot Info argument is null. Cannot get the previous snapshot for a null " +
204-
"value", INVALID_SNAPSHOT_ERROR);
202+
"value", FILE_NOT_FOUND);
205203
}
206204
try {
207205
if (chainManager.hasPreviousPathSnapshot(snapInfo.getSnapshotPath(),

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshotManager.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.hadoop.hdds.utils.db.DBStore;
2626
import org.apache.hadoop.hdds.utils.db.RDBBatchOperation;
2727
import org.apache.hadoop.hdds.utils.db.Table;
28+
import org.apache.hadoop.ozone.om.exceptions.OMException;
2829
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
2930
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
3031
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
@@ -72,6 +73,7 @@
7273
import static org.junit.jupiter.api.Assertions.assertEquals;
7374
import static org.junit.jupiter.api.Assertions.assertFalse;
7475
import static org.junit.jupiter.api.Assertions.assertTrue;
76+
import static org.junit.jupiter.api.Assertions.assertThrows;
7577
import static org.mockito.Mockito.mock;
7678
import static org.mockito.Mockito.timeout;
7779
import static org.mockito.Mockito.times;
@@ -314,6 +316,29 @@ public void testHardLinkCreation() throws IOException {
314316
getINode(f1FileLink.toPath()), "link matches original file");
315317
}
316318

319+
320+
@Test
321+
public void testGetSnapshotInfo() throws IOException {
322+
SnapshotInfo s1 = createSnapshotInfo("vol", "buck");
323+
UUID latestGlobalSnapId =
324+
((OmMetadataManagerImpl) om.getMetadataManager()).getSnapshotChainManager()
325+
.getLatestGlobalSnapshotId();
326+
UUID latestPathSnapId =
327+
((OmMetadataManagerImpl) om.getMetadataManager()).getSnapshotChainManager()
328+
.getLatestPathSnapshotId(String.join("/", "vol", "buck"));
329+
s1.setPathPreviousSnapshotId(latestPathSnapId);
330+
s1.setGlobalPreviousSnapshotId(latestGlobalSnapId);
331+
((OmMetadataManagerImpl) om.getMetadataManager()).getSnapshotChainManager()
332+
.addSnapshot(s1);
333+
OMException ome = assertThrows(OMException.class,
334+
() -> om.getOmSnapshotManager().getSnapshot(s1.getSnapshotId()));
335+
assertEquals(OMException.ResultCodes.FILE_NOT_FOUND, ome.getResult());
336+
// not present in snapshot chain too
337+
SnapshotInfo s2 = createSnapshotInfo("vol", "buck");
338+
ome = assertThrows(OMException.class,
339+
() -> om.getOmSnapshotManager().getSnapshot(s2.getSnapshotId()));
340+
assertEquals(OMException.ResultCodes.FILE_NOT_FOUND, ome.getResult());
341+
}
317342
/*
318343
* Test that exclude list is generated correctly.
319344
*/

0 commit comments

Comments
 (0)