-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-8665. Implemented CopyObject for SnapshotInfo and moved out snapshot chain update form OMSnapshotPurgeResponse #5201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,8 @@ | |
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.NoSuchElementException; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * Handles OMSnapshotPurge Request. | ||
|
|
@@ -73,6 +75,8 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, | |
| List<String> snapInfosToUpdate = snapshotPurgeRequest | ||
| .getUpdatedSnapshotDBKeyList(); | ||
| Map<String, SnapshotInfo> updatedSnapInfos = new HashMap<>(); | ||
| Map<String, SnapshotInfo> updatedPathPreviousAndGlobalSnapshots = | ||
| new HashMap<>(); | ||
|
|
||
| // Snapshots that are already deepCleaned by the KeyDeletingService | ||
| // can be marked as deepCleaned. | ||
|
|
@@ -94,12 +98,16 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, | |
| SnapshotInfo nextSnapshot = SnapshotUtils | ||
| .getNextActiveSnapshot(fromSnapshot, | ||
| snapshotChainManager, omSnapshotManager); | ||
|
|
||
| updateSnapshotInfoAndCache(nextSnapshot, omMetadataManager, | ||
| trxnLogIndex, updatedSnapInfos, true); | ||
| updateSnapshotChainAndCache(omMetadataManager, fromSnapshot, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a possibility that snapshot chain may get corrupted because of batch operation. |
||
| trxnLogIndex, updatedPathPreviousAndGlobalSnapshots); | ||
| } | ||
|
|
||
| omClientResponse = new OMSnapshotPurgeResponse(omResponse.build(), | ||
| snapshotDbKeys, updatedSnapInfos); | ||
| snapshotDbKeys, updatedSnapInfos, | ||
| updatedPathPreviousAndGlobalSnapshots); | ||
| } catch (IOException ex) { | ||
| omClientResponse = new OMSnapshotPurgeResponse( | ||
| createErrorOMResponse(omResponse, ex)); | ||
|
|
@@ -124,4 +132,95 @@ private void updateSnapshotInfoAndCache(SnapshotInfo snapInfo, | |
| updatedSnapInfos.put(snapInfo.getTableKey(), snapInfo); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Removes the snapshot from the chain and updates the next snapshot's | ||
| * previousPath and previousGlobal IDs in DB cache. | ||
| * It also returns the pair of updated next path and global snapshots to | ||
| * update in DB. | ||
| */ | ||
| private void updateSnapshotChainAndCache( | ||
| OmMetadataManagerImpl metadataManager, | ||
| SnapshotInfo snapInfo, | ||
| long trxnLogIndex, | ||
| Map<String, SnapshotInfo> updatedPathPreviousAndGlobalSnapshots | ||
| ) throws IOException { | ||
| if (snapInfo == null) { | ||
| return; | ||
| } | ||
|
|
||
| SnapshotChainManager snapshotChainManager = metadataManager | ||
| .getSnapshotChainManager(); | ||
| SnapshotInfo nextPathSnapInfo = null; | ||
|
|
||
| // If the snapshot is deleted in the previous run, then the in-memory | ||
| // SnapshotChainManager might throw NoSuchElementException as the snapshot | ||
| // is removed in-memory but OMDoubleBuffer has not flushed yet. | ||
| boolean hasNextPathSnapshot; | ||
| boolean hasNextGlobalSnapshot; | ||
| try { | ||
| hasNextPathSnapshot = snapshotChainManager.hasNextPathSnapshot( | ||
| snapInfo.getSnapshotPath(), snapInfo.getSnapshotId()); | ||
| hasNextGlobalSnapshot = snapshotChainManager.hasNextGlobalSnapshot( | ||
| snapInfo.getSnapshotId()); | ||
| } catch (NoSuchElementException ex) { | ||
| return; | ||
| } | ||
|
|
||
| // Updates next path snapshot's previous snapshot ID | ||
| if (hasNextPathSnapshot) { | ||
| UUID nextPathSnapshotId = snapshotChainManager.nextPathSnapshot( | ||
| snapInfo.getSnapshotPath(), snapInfo.getSnapshotId()); | ||
|
|
||
| String snapshotTableKey = snapshotChainManager | ||
| .getTableKey(nextPathSnapshotId); | ||
| nextPathSnapInfo = metadataManager.getSnapshotInfoTable() | ||
| .get(snapshotTableKey); | ||
| if (nextPathSnapInfo != null) { | ||
| nextPathSnapInfo.setPathPreviousSnapshotId( | ||
| snapInfo.getPathPreviousSnapshotId()); | ||
| metadataManager.getSnapshotInfoTable().addCacheEntry( | ||
| new CacheKey<>(nextPathSnapInfo.getTableKey()), | ||
| CacheValue.get(trxnLogIndex, nextPathSnapInfo)); | ||
| updatedPathPreviousAndGlobalSnapshots | ||
| .put(nextPathSnapInfo.getTableKey(), nextPathSnapInfo); | ||
| } | ||
| } | ||
|
|
||
| // Updates next global snapshot's previous snapshot ID | ||
| if (hasNextGlobalSnapshot) { | ||
| UUID nextGlobalSnapshotId = | ||
| snapshotChainManager.nextGlobalSnapshot(snapInfo.getSnapshotId()); | ||
|
|
||
| String snapshotTableKey = snapshotChainManager | ||
| .getTableKey(nextGlobalSnapshotId); | ||
|
|
||
| SnapshotInfo nextGlobalSnapInfo = metadataManager.getSnapshotInfoTable() | ||
| .get(snapshotTableKey); | ||
| // If both next global and path snapshot are same, it may overwrite | ||
| // nextPathSnapInfo.setPathPreviousSnapshotID(), adding this check | ||
| // will prevent it. | ||
| if (nextGlobalSnapInfo != null && nextPathSnapInfo != null && | ||
| nextGlobalSnapInfo.getSnapshotId().equals( | ||
| nextPathSnapInfo.getSnapshotId())) { | ||
| nextPathSnapInfo.setGlobalPreviousSnapshotId( | ||
| snapInfo.getGlobalPreviousSnapshotId()); | ||
| metadataManager.getSnapshotInfoTable().addCacheEntry( | ||
| new CacheKey<>(nextPathSnapInfo.getTableKey()), | ||
| CacheValue.get(trxnLogIndex, nextPathSnapInfo)); | ||
| updatedPathPreviousAndGlobalSnapshots | ||
| .put(nextPathSnapInfo.getTableKey(), nextPathSnapInfo); | ||
| } else if (nextGlobalSnapInfo != null) { | ||
| nextGlobalSnapInfo.setGlobalPreviousSnapshotId( | ||
| snapInfo.getGlobalPreviousSnapshotId()); | ||
| metadataManager.getSnapshotInfoTable().addCacheEntry( | ||
| new CacheKey<>(nextGlobalSnapInfo.getTableKey()), | ||
| CacheValue.get(trxnLogIndex, nextGlobalSnapInfo)); | ||
| updatedPathPreviousAndGlobalSnapshots | ||
| .put(nextGlobalSnapInfo.getTableKey(), nextGlobalSnapInfo); | ||
| } | ||
| } | ||
|
|
||
| snapshotChainManager.deleteSnapshot(snapInfo); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.