Skip to content

Commit b2be450

Browse files
kamcheungting-dbwgtmac
authored andcommitted
fix(logging): address commit lifecycle review feedback
1 parent 0d70ad8 commit b2be450

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

‎src/iceberg/table_metadata.cc‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "iceberg/exception.h"
3939
#include "iceberg/file_io.h"
4040
#include "iceberg/json_serde_internal.h"
41-
#include "iceberg/logging/log_macros.h"
4241
#include "iceberg/metrics_config.h"
4342
#include "iceberg/partition_field.h"
4443
#include "iceberg/partition_spec.h"
@@ -1107,8 +1106,6 @@ Status TableMetadataBuilder::Impl::AddSnapshot(std::shared_ptr<Snapshot> snapsho
11071106
metadata_.next_row_id += add_rows.value();
11081107
}
11091108

1110-
ICEBERG_LOG_DEBUG("Added snapshot {} (sequence number {}) to table metadata",
1111-
snapshot->snapshot_id, snapshot->sequence_number);
11121109
return {};
11131110
}
11141111

‎src/iceberg/transaction.cc‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "iceberg/transaction.h"
2020

2121
#include <format>
22+
#include <iterator>
2223
#include <memory>
2324
#include <string>
2425

@@ -400,9 +401,6 @@ Status Transaction::ApplyUpdatePartitionStatistics(UpdatePartitionStatistics& up
400401
Result<std::shared_ptr<Table>> Transaction::Commit() {
401402
ICEBERG_RETURN_UNEXPECTED(CheckReady());
402403
Result<std::shared_ptr<Table>> commit_result = ctx_->table;
403-
// Snapshot id before the commit, to detect whether this commit advanced it (a
404-
// data commit) versus a metadata-only commit that adds no snapshot.
405-
const int64_t base_current_snapshot_id = ctx_->table->metadata()->current_snapshot_id;
406404
int32_t attempt = 0;
407405
std::string last_error;
408406
try {
@@ -444,27 +442,42 @@ Result<std::shared_ptr<Table>> Transaction::Commit() {
444442
}
445443

446444
if (commit_result) {
447-
// Name the resulting snapshot only when this commit produced one (current
448-
// snapshot advanced); metadata-only commits report a plain success.
445+
// The builder contains only changes made by the successful attempt. Inspecting
446+
// AddSnapshot changes avoids attributing a concurrent writer's snapshot to this
447+
// transaction and also detects snapshots committed with StageOnly or ToBranch.
449448
std::string detail;
450-
if (auto snapshot = commit_result.value()->metadata()->Snapshot();
451-
snapshot.has_value() &&
452-
snapshot.value()->snapshot_id != base_current_snapshot_id) {
453-
const auto& summary = snapshot.value()->summary;
454-
auto op = summary.find(SnapshotSummaryFields::kOperation);
455-
detail =
456-
std::format(": committed snapshot {} (op={})", snapshot.value()->snapshot_id,
457-
op != summary.end() ? op->second : "unknown");
449+
const auto& changes = ctx_->metadata_builder->changes();
450+
size_t added_snapshot_count = 0;
451+
for (const auto& change : changes) {
452+
added_snapshot_count += change->kind() == TableUpdate::Kind::kAddSnapshot;
453+
}
454+
if (added_snapshot_count > 0) {
455+
detail.reserve(32 + added_snapshot_count * 48);
456+
std::format_to(std::back_inserter(detail), ": committed snapshot{} ",
457+
added_snapshot_count == 1 ? "" : "s");
458+
459+
size_t appended_snapshot_count = 0;
460+
for (const auto& change : changes) {
461+
if (change->kind() != TableUpdate::Kind::kAddSnapshot) {
462+
continue;
463+
}
464+
const auto& snapshot =
465+
internal::checked_cast<const table::AddSnapshot&>(*change).snapshot();
466+
if (appended_snapshot_count++ > 0) {
467+
detail += ", ";
468+
}
469+
const auto& summary = snapshot->summary;
470+
auto op = summary.find(SnapshotSummaryFields::kOperation);
471+
std::format_to(std::back_inserter(detail), "{} (op={})", snapshot->snapshot_id,
472+
op != summary.end() ? op->second : "unknown");
473+
}
458474
}
459475
if (attempt > 1) {
460476
ICEBERG_LOG_INFO("Transaction commit succeeded after {} attempts{}", attempt,
461477
detail);
462478
} else {
463479
ICEBERG_LOG_INFO("Transaction commit succeeded{}", detail);
464480
}
465-
} else {
466-
ICEBERG_LOG_ERROR("Transaction commit failed after {} attempt(s): {}", attempt,
467-
commit_result.error().message);
468481
}
469482

470483
if (!commit_result) {

0 commit comments

Comments
 (0)