From 7885ef38f8e297be9e197f6a421528a1b2a7ed01 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 18 Nov 2026 17:37:43 +0800 Subject: [PATCH 1/3] fix: retain transaction base metadata across table refresh Keep the metadata builder base alive independently of the shared Table and replace both during rebase. Add a deterministic lifetime regression for caller-triggered refresh. Co-authored-by: Codex --- src/iceberg/test/transaction_test.cc | 23 +++++++++++++++++++++++ src/iceberg/transaction.cc | 11 +++++------ src/iceberg/transaction.h | 2 ++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/iceberg/test/transaction_test.cc b/src/iceberg/test/transaction_test.cc index 3a1e3bcdd9..0b18c2e3cb 100644 --- a/src/iceberg/test/transaction_test.cc +++ b/src/iceberg/test/transaction_test.cc @@ -81,6 +81,29 @@ TEST_F(TransactionTest, CommitTransactionWithPropertyUpdate) { EXPECT_EQ(props.at("txn.property"), "txn.value"); } +TEST_F(TransactionTest, BaseMetadataSurvivesTableRefresh) { + std::weak_ptr original_base = table_->metadata(); + ICEBERG_UNWRAP_OR_FAIL(auto txn, table_->NewTransaction()); + ICEBERG_UNWRAP_OR_FAIL(auto update, txn->NewUpdateProperties()); + update->Set("txn.property", "txn.value"); + ASSERT_THAT(update->Commit(), IsOk()); + + ICEBERG_UNWRAP_OR_FAIL(auto concurrent, catalog_->LoadTable(table_ident_)); + ICEBERG_UNWRAP_OR_FAIL(auto properties, concurrent->NewUpdateProperties()); + properties->Set("concurrent.property", "concurrent.value"); + ASSERT_THAT(properties->Commit(), IsOk()); + ASSERT_THAT(table_->Refresh(), IsOk()); + + // The builder borrows this base even after the shared Table has refreshed. + ASSERT_FALSE(original_base.expired()); + EXPECT_EQ(txn->base(), original_base.lock().get()); + ICEBERG_UNWRAP_OR_FAIL(auto committed, txn->Commit()); + EXPECT_TRUE(original_base.expired()); + EXPECT_EQ(committed->properties().configs().at("txn.property"), "txn.value"); + EXPECT_EQ(committed->properties().configs().at("concurrent.property"), + "concurrent.value"); +} + TEST_F(TransactionTest, MultipleUpdatesInTransaction) { ICEBERG_UNWRAP_OR_FAIL(auto txn, table_->NewTransaction()); diff --git a/src/iceberg/transaction.cc b/src/iceberg/transaction.cc index eada4eb903..ef5df71ae9 100644 --- a/src/iceberg/transaction.cc +++ b/src/iceberg/transaction.cc @@ -118,7 +118,8 @@ Result> TransactionContext::Make( ctx->metadata_builder = TableMetadataBuilder::BuildFromEmpty(); std::ignore = ctx->metadata_builder->ApplyChangesForCreate(*ctx->table->metadata()); } else { - ctx->metadata_builder = TableMetadataBuilder::BuildFrom(ctx->table->metadata().get()); + ctx->base_metadata = ctx->table->metadata(); + ctx->metadata_builder = TableMetadataBuilder::BuildFrom(ctx->base_metadata.get()); } return ctx; } @@ -544,10 +545,7 @@ void Transaction::FinalizeUpdates(const TableMetadata& committed) noexcept { Result> Transaction::CommitOnce(bool is_first_attempt) { std::vector> requirements; if (ctx_->kind == TransactionKind::kUpdate) { - std::shared_ptr metadata_before_refresh; if (!is_first_attempt) { - // Keep the builder's base alive while Refresh replaces the table metadata. - metadata_before_refresh = ctx_->table->metadata(); ICEBERG_RETURN_UNEXPECTED(ctx_->table->Refresh()); } const bool metadata_changed = @@ -557,8 +555,9 @@ Result> Transaction::CommitOnce(bool is_first_attempt) { ICEBERG_CHECK(CanRetry(), "Cannot rebase a transaction containing a non-retryable update"); CleanupUpdates(); - ctx_->metadata_builder = - TableMetadataBuilder::BuildFrom(ctx_->table->metadata().get()); + auto base_metadata = ctx_->table->metadata(); + ctx_->metadata_builder = TableMetadataBuilder::BuildFrom(base_metadata.get()); + ctx_->base_metadata = std::move(base_metadata); auto applied = ReplayUpdates(); if (!applied) { return ValidationFailed("Transaction replay failed: {}", applied.error().message); diff --git a/src/iceberg/transaction.h b/src/iceberg/transaction.h index 8e952d5906..0a63b8ca3e 100644 --- a/src/iceberg/transaction.h +++ b/src/iceberg/transaction.h @@ -225,6 +225,8 @@ class ICEBERG_EXPORT TransactionContext { Result> NewLocationProvider() const; std::shared_ptr table; + // Keep the builder's borrowed base alive even when the shared Table refreshes. + std::shared_ptr base_metadata; std::unique_ptr metadata_builder; TransactionKind kind; // If PendingUpdate is created directly from Table, this is nullopt; From b4ed51091afd82377d2f91fdbb25bc63df1c30f7 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 18 Nov 2026 23:08:15 +0800 Subject: [PATCH 2/3] refactor: reset transaction base and metadata builder together Centralize the ownership update for initialization and rebase, and keep the regression focused on base metadata surviving table refresh. --- src/iceberg/test/transaction_test.cc | 9 --------- src/iceberg/transaction.cc | 12 +++++++----- src/iceberg/transaction.h | 2 ++ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/iceberg/test/transaction_test.cc b/src/iceberg/test/transaction_test.cc index 0b18c2e3cb..50491e96d8 100644 --- a/src/iceberg/test/transaction_test.cc +++ b/src/iceberg/test/transaction_test.cc @@ -84,9 +84,6 @@ TEST_F(TransactionTest, CommitTransactionWithPropertyUpdate) { TEST_F(TransactionTest, BaseMetadataSurvivesTableRefresh) { std::weak_ptr original_base = table_->metadata(); ICEBERG_UNWRAP_OR_FAIL(auto txn, table_->NewTransaction()); - ICEBERG_UNWRAP_OR_FAIL(auto update, txn->NewUpdateProperties()); - update->Set("txn.property", "txn.value"); - ASSERT_THAT(update->Commit(), IsOk()); ICEBERG_UNWRAP_OR_FAIL(auto concurrent, catalog_->LoadTable(table_ident_)); ICEBERG_UNWRAP_OR_FAIL(auto properties, concurrent->NewUpdateProperties()); @@ -96,12 +93,6 @@ TEST_F(TransactionTest, BaseMetadataSurvivesTableRefresh) { // The builder borrows this base even after the shared Table has refreshed. ASSERT_FALSE(original_base.expired()); - EXPECT_EQ(txn->base(), original_base.lock().get()); - ICEBERG_UNWRAP_OR_FAIL(auto committed, txn->Commit()); - EXPECT_TRUE(original_base.expired()); - EXPECT_EQ(committed->properties().configs().at("txn.property"), "txn.value"); - EXPECT_EQ(committed->properties().configs().at("concurrent.property"), - "concurrent.value"); } TEST_F(TransactionTest, MultipleUpdatesInTransaction) { diff --git a/src/iceberg/transaction.cc b/src/iceberg/transaction.cc index ef5df71ae9..2512d91555 100644 --- a/src/iceberg/transaction.cc +++ b/src/iceberg/transaction.cc @@ -118,12 +118,16 @@ Result> TransactionContext::Make( ctx->metadata_builder = TableMetadataBuilder::BuildFromEmpty(); std::ignore = ctx->metadata_builder->ApplyChangesForCreate(*ctx->table->metadata()); } else { - ctx->base_metadata = ctx->table->metadata(); - ctx->metadata_builder = TableMetadataBuilder::BuildFrom(ctx->base_metadata.get()); + ctx->ResetMetadataBuilder(ctx->table->metadata()); } return ctx; } +void TransactionContext::ResetMetadataBuilder(std::shared_ptr base) { + metadata_builder = TableMetadataBuilder::BuildFrom(base.get()); + base_metadata = std::move(base); +} + const TableMetadata* TransactionContext::base() const { return metadata_builder->base(); } const TableMetadata& TransactionContext::current() const { @@ -555,9 +559,7 @@ Result> Transaction::CommitOnce(bool is_first_attempt) { ICEBERG_CHECK(CanRetry(), "Cannot rebase a transaction containing a non-retryable update"); CleanupUpdates(); - auto base_metadata = ctx_->table->metadata(); - ctx_->metadata_builder = TableMetadataBuilder::BuildFrom(base_metadata.get()); - ctx_->base_metadata = std::move(base_metadata); + ctx_->ResetMetadataBuilder(ctx_->table->metadata()); auto applied = ReplayUpdates(); if (!applied) { return ValidationFailed("Transaction replay failed: {}", applied.error().message); diff --git a/src/iceberg/transaction.h b/src/iceberg/transaction.h index 0a63b8ca3e..59fdf38a4a 100644 --- a/src/iceberg/transaction.h +++ b/src/iceberg/transaction.h @@ -219,6 +219,8 @@ class ICEBERG_EXPORT TransactionContext { static Result> Make(std::shared_ptr
table, TransactionKind kind); + void ResetMetadataBuilder(std::shared_ptr base); + const TableMetadata* base() const; const TableMetadata& current() const; std::string MetadataFileLocation(std::string_view filename) const; From 7628331e370086c988b2b4d1adc75bbe16681af5 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 18 Nov 2026 23:28:32 +0800 Subject: [PATCH 3/3] ci: pin CMake to 4.4.5 for sanitizer tests Avoid the Boost.Locale source_group configuration failure with CMake 4.5.0 and verify that the pinned version is used. --- .github/workflows/sanitizer_test.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/sanitizer_test.yml b/.github/workflows/sanitizer_test.yml index e9796bc955..bdb8a23596 100644 --- a/.github/workflows/sanitizer_test.yml +++ b/.github/workflows/sanitizer_test.yml @@ -59,6 +59,15 @@ jobs: - name: Install dependencies shell: bash run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev libssl-dev + - name: Set up Python + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.13' + - name: Pin CMake to 4.4.5 + run: | + python -m pip install "cmake==4.4.5" + cmake --version + test "$(cmake --version | head -n 1)" = "cmake version 4.4.5" - name: Set up sccache uses: ./.github/actions/setup-sccache with: