Skip to content

Commit

Permalink
fast return
Browse files Browse the repository at this point in the history
  • Loading branch information
askwang committed Nov 6, 2024
1 parent 321c8ef commit 29c4c12
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,13 @@ public void rollbackTo(long snapshotId) {
"Rollback snapshot '%s' doesn't exist.",
snapshotId);

rollbackHelper().cleanLargerThan(snapshotManager.snapshot(snapshotId));
Snapshot snapshot = snapshotManager.snapshot(snapshotId);
// fast return
if (snapshot.equals(snapshotManager.latestSnapshot())) {
return;
}

rollbackHelper().cleanLargerThan(snapshot);
}

public Snapshot findSnapshot(long fromSnapshotId) throws SnapshotNotExistException {
Expand Down Expand Up @@ -625,14 +631,19 @@ public void rollbackTo(String tagName) {
checkArgument(tagManager.tagExists(tagName), "Rollback tag '%s' doesn't exist.", tagName);

Snapshot taggedSnapshot = tagManager.taggedSnapshot(tagName);
SnapshotManager snapshotManager = snapshotManager();
// fast return
if (taggedSnapshot.equals(snapshotManager.latestSnapshot())) {
return;
}

rollbackHelper().cleanLargerThan(taggedSnapshot);

try {
// it is possible that the earliest snapshot is later than the rollback tag because of
// snapshot expiration, in this case the `cleanLargerThan` method will delete all
// snapshots, so we should write the tag file to snapshot directory and modify the
// earliest hint
SnapshotManager snapshotManager = snapshotManager();
if (!snapshotManager.snapshotExists(taggedSnapshot.id())) {
fileIO.writeFile(
snapshotManager().snapshotPath(taggedSnapshot.id()),
Expand Down

0 comments on commit 29c4c12

Please sign in to comment.