Skip to content

Conversation

@shangxinli
Copy link
Contributor

Move last_update_committed_ assignment to after auto-commit attempt.

If Commit() fails, ICEBERG_RETURN_UNEXPECTED returns early and the flag remains false, preventing the transaction from incorrectly reporting the update as committed when it actually failed.

Set last_update_committed_ before calling Commit(), but revert the flag
if auto-commit fails.

This ensures:
1. Commit() can proceed (it requires last_update_committed_ == true)
2. If commit fails, the flag is reverted to false
3. Transaction state remains consistent on failure
update->ApplyTo(*metadata_builder_);
}

last_update_committed_ = true;
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it is simpler to move line 68 to be after the if (auto_commit_) block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense! it makes simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems the test failed after we move this line. The problem is Commit() requires this flag to be true at the start. So we need to set it to be true before that.

Copy link
Member

Choose a reason for hiding this comment

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

I think the name last_update_committed_ might confuse readers a little bit because it only means whether previous created pending update has called commit to apply changes to the transaction. We use this flag to make sure updates are created and committed sequentially to make the state of transaction simpler. Since it has nothing to do with the transaction object itself, I'm hesitant to set last_update_committed_ to false when transaction.Commit fails. Perhaps we should rename it to last_update_applied or something more precise. WDYT?

Simplifies the Apply() method by moving the flag assignment to after
the auto-commit conditional block. This eliminates the need to revert
the flag on commit failure while maintaining the same behavior.
…mode

The previous refactor moved the flag assignment after the auto_commit
block, but Commit() requires this flag to be true. This caused test
failures with 'Cannot commit transaction when previous update is not
committed' error.

The fix:
- Set last_update_committed_ = true before calling Commit()
- On Commit() failure, revert the flag to false
- This maintains exception safety while allowing Commit() to proceed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants