diff --git a/src/iceberg/transaction.cc b/src/iceberg/transaction.cc index ca39ec043..c8cf42d36 100644 --- a/src/iceberg/transaction.cc +++ b/src/iceberg/transaction.cc @@ -75,6 +75,9 @@ Status Transaction::Apply(std::vector> updates) { } Result> Transaction::Commit() { + if (committed_) { + return Invalid("Transaction already committed"); + } if (!last_update_committed_) { return InvalidArgument( "Cannot commit transaction when previous update is not committed"); @@ -82,6 +85,7 @@ Result> Transaction::Commit() { const auto& updates = metadata_builder_->changes(); if (updates.empty()) { + committed_ = true; return table_; } @@ -98,7 +102,14 @@ Result> Transaction::Commit() { } // XXX: we should handle commit failure and retry here. - return table_->catalog()->UpdateTable(table_->name(), requirements, updates); + ICEBERG_ASSIGN_OR_RAISE(auto updated_table, table_->catalog()->UpdateTable( + table_->name(), requirements, updates)); + + // Mark as committed and update table reference + committed_ = true; + table_ = std::move(updated_table); + + return table_; } Result> Transaction::NewUpdateProperties() { diff --git a/src/iceberg/transaction.h b/src/iceberg/transaction.h index 36328026b..73c346833 100644 --- a/src/iceberg/transaction.h +++ b/src/iceberg/transaction.h @@ -80,6 +80,8 @@ class ICEBERG_EXPORT Transaction : public std::enable_shared_from_this> pending_updates_;