Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions core/src/main/java/org/apache/iceberg/SnapshotProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,18 @@ public void commit() {
.run(taskOps -> {
Snapshot newSnapshot = apply();
newSnapshotId.set(newSnapshot.snapshotId());
TableMetadata updated;
if (stageOnly) {
updated = base.addStagedSnapshot(newSnapshot);
TableMetadata.Builder update = TableMetadata.buildFrom(base);
if (base.snapshot(newSnapshot.snapshotId()) != null) {
// this is a rollback or cherrypick operation
update.setCurrentSnapshot(newSnapshot.snapshotId());
} else if (stageOnly) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you port the changes from the other fix? That removed methods from TableMetadata rather than adding new ones. I think it would be best to keep 0.13.x and master in sync rather than having slightly different fixes.

Thanks, @sririshindra!

Copy link
Contributor

@wypoon wypoon Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rdblue, would the following be acceptable? (from line 285)

            TableMetadata.Builder update = TableMetadata.buildFrom(base);
            if (base.snapshot(newSnapshot.snapshotId()) != null) {
              // this is a rollback or cherrypick operation
              update.setCurrentSnapshot(newSnapshot.snapshotId());
              } else if (stageOnly) {
              update.addSnapshot(newSnapshot);
            } else {
              update.setCurrentSnapshot(newSnapshot);
            }

            TableMetadata updated = update.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;
            }

I know the point of #4089 is to replace setCurrentSnapshot with setBranchSnapshot, but in 0.13.x, we don't support branching yet, and the commits #4089 builds on are not present. The above mirrors your change to SnapshotProducer in #4089.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, calling the right setCurrentSnapshot is a good way to backport this. Thanks!

update.addSnapshot(newSnapshot);
} else {
updated = base.replaceCurrentSnapshot(newSnapshot);
update.setCurrentSnapshot(newSnapshot);
}

if (updated == base) {
TableMetadata updated = update.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;
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/apache/iceberg/TableMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ public TableMetadata replaceCurrentSnapshot(Snapshot snapshot) {
return new Builder(this).setCurrentSnapshot(snapshot).build();
}

public TableMetadata replaceCurrentSnapshot(long snapshotId) {
return new Builder(this).setCurrentSnapshot(snapshotId).build();
}

Comment on lines +504 to +507
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was an oversight, right? We don't need this new method; it is not used.
In fact, with the above change to SnapshotProducer, even replaceCurrentSnapshot(Snapshot) is no longer used and can be removed, I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right. I missed this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed #4155 to remove the unused methods.

public TableMetadata removeSnapshotsIf(Predicate<Snapshot> removeIf) {
List<Snapshot> toRemove = snapshots.stream().filter(removeIf).collect(Collectors.toList());
return new Builder(this).removeSnapshots(toRemove).build();
Expand Down