@@ -46,26 +46,30 @@ SnapshotManager::SnapshotManager(std::shared_ptr<Transaction> transaction)
4646SnapshotManager::~SnapshotManager () = default ;
4747
4848SnapshotManager& SnapshotManager::Cherrypick (int64_t snapshot_id) {
49+ ICEBERG_BUILDER_RETURN_IF_ERROR (CommitIfRefUpdatesExist ());
4950 // TODO(anyone): Implement cherrypick operation
5051 ICEBERG_BUILDER_CHECK (false , " Cherrypick operation not yet implemented" );
5152 return *this ;
5253}
5354
5455SnapshotManager& SnapshotManager::SetCurrentSnapshot (int64_t snapshot_id) {
56+ ICEBERG_BUILDER_RETURN_IF_ERROR (CommitIfRefUpdatesExist ());
5557 ICEBERG_BUILDER_ASSIGN_OR_RETURN (auto set_snapshot, transaction_->NewSetSnapshot ());
5658 set_snapshot->SetCurrentSnapshot (snapshot_id);
5759 ICEBERG_BUILDER_RETURN_IF_ERROR (set_snapshot->Commit ());
5860 return *this ;
5961}
6062
6163SnapshotManager& SnapshotManager::RollbackToTime (int64_t timestamp_ms) {
64+ ICEBERG_BUILDER_RETURN_IF_ERROR (CommitIfRefUpdatesExist ());
6265 ICEBERG_BUILDER_ASSIGN_OR_RETURN (auto set_snapshot, transaction_->NewSetSnapshot ());
6366 set_snapshot->RollbackToTime (timestamp_ms);
6467 ICEBERG_BUILDER_RETURN_IF_ERROR (set_snapshot->Commit ());
6568 return *this ;
6669}
6770
6871SnapshotManager& SnapshotManager::RollbackTo (int64_t snapshot_id) {
72+ ICEBERG_BUILDER_RETURN_IF_ERROR (CommitIfRefUpdatesExist ());
6973 ICEBERG_BUILDER_ASSIGN_OR_RETURN (auto set_snapshot, transaction_->NewSetSnapshot ());
7074 set_snapshot->RollbackTo (snapshot_id);
7175 ICEBERG_BUILDER_RETURN_IF_ERROR (set_snapshot->Commit ());
@@ -168,8 +172,13 @@ SnapshotManager& SnapshotManager::SetMaxRefAgeMs(const std::string& name,
168172}
169173
170174Status SnapshotManager::Commit () {
175+ transaction_->EnableAutoCommit ();
171176 ICEBERG_RETURN_UNEXPECTED (CheckErrors ());
172- return CommitIfRefUpdatesExist ();
177+ ICEBERG_RETURN_UNEXPECTED (CommitIfRefUpdatesExist ());
178+ if (!transaction_->is_committed ()) {
179+ ICEBERG_RETURN_UNEXPECTED (transaction_->Commit ());
180+ }
181+ return {};
173182}
174183
175184Result<std::shared_ptr<UpdateSnapshotReference>>
0 commit comments