Skip to content

Commit

Permalink
Core: Commit empty operations from SetSnapshotOperation (apache#5536)
Browse files Browse the repository at this point in the history
Change-Id: I9b481ca173a12457cb6773ade0c8a1ebd0b40cbc
  • Loading branch information
szlta authored Aug 15, 2022
1 parent ce5128f commit c550e79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 4 additions & 6 deletions core/src/main/java/org/apache/iceberg/SetSnapshotOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ public void commit() {
.setBranchSnapshot(snapshot.snapshotId(), SnapshotRef.MAIN_BRANCH)
.build();

if (updated.changes().isEmpty()) {
// do not commit if the metadata has not changed. for example, this may happen when
// setting the current
// snapshot to an ID that is already current. note that this check uses identity.
return;
}
// Do commit this operation even if the metadata has not changed, as we need to
// advance the hasLastOpCommited for the transaction's commit to work properly.
// (Without any other operations in the transaction, the commitTransaction() call
// will be a no-op anyway)

// if the table UUID is missing, add it here. the UUID will be re-created each time
// this operation retries
Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/org/apache/iceberg/TestSnapshotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,15 @@ public void testCreateReferencesAndCherrypick() {
Assert.assertEquals(SnapshotRef.branchBuilder(1).build(), actualBranch);
Assert.assertEquals(SnapshotRef.tagBuilder(1).build(), actualTag);
}

@Test
public void testAttemptToRollbackToCurrentSnapshot() {
table.newAppend().appendFile(FILE_A).commit();

long currentSnapshotTimestampPlus100 = table.currentSnapshot().timestampMillis() + 100;
table.manageSnapshots().rollbackToTime(currentSnapshotTimestampPlus100).commit();

long currentSnapshotId = table.currentSnapshot().snapshotId();
table.manageSnapshots().rollbackTo(currentSnapshotId).commit();
}
}

0 comments on commit c550e79

Please sign in to comment.