Skip to content

Commit 42e2de4

Browse files
aswinshakilMaksim Myskov
authored andcommitted
HDDS-10408. NPE causes OM crash in Snapshot Purge request (apache#6250)
(cherry picked from commit 6dfd7d4)
1 parent de8d43c commit 42e2de4

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
3535
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
3636
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SnapshotPurgeRequest;
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
3739

3840
import java.io.IOException;
3941
import java.util.HashMap;
@@ -48,6 +50,8 @@
4850
*/
4951
public class OMSnapshotPurgeRequest extends OMClientRequest {
5052

53+
private static final Logger LOG = LoggerFactory.getLogger(OMSnapshotPurgeRequest.class);
54+
5155
public OMSnapshotPurgeRequest(OMRequest omRequest) {
5256
super(omRequest);
5357
}
@@ -94,6 +98,13 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
9498
SnapshotInfo fromSnapshot = omMetadataManager.getSnapshotInfoTable()
9599
.get(snapTableKey);
96100

101+
if (fromSnapshot == null) {
102+
// Snapshot may have been purged in the previous iteration of SnapshotDeletingService.
103+
LOG.warn("The snapshot {} is not longer in snapshot table, It maybe removed in the previous " +
104+
"Snapshot purge request.", snapTableKey);
105+
continue;
106+
}
107+
97108
SnapshotInfo nextSnapshot = SnapshotUtils
98109
.getNextActiveSnapshot(fromSnapshot,
99110
snapshotChainManager, omSnapshotManager);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.UUID;
4141

4242
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
43+
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_SNAPSHOT_ERROR;
4344
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DIRECTORY_TABLE;
4445
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.FILE_TABLE;
4546
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.KEY_TABLE;
@@ -148,6 +149,10 @@ public static SnapshotInfo getNextActiveSnapshot(SnapshotInfo snapInfo,
148149
// If the snapshot is deleted in the previous run, then the in-memory
149150
// SnapshotChainManager might throw NoSuchElementException as the snapshot
150151
// is removed in-memory but OMDoubleBuffer has not flushed yet.
152+
if (snapInfo == null) {
153+
throw new OMException("Snapshot Info is null. Cannot get the next snapshot", INVALID_SNAPSHOT_ERROR);
154+
}
155+
151156
try {
152157
while (chainManager.hasNextPathSnapshot(snapInfo.getSnapshotPath(),
153158
snapInfo.getSnapshotId())) {

0 commit comments

Comments
 (0)