-
Notifications
You must be signed in to change notification settings - Fork 121
feat(logging): log transaction commit lifecycle (retries, success, snapshot adds) #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,11 @@ | |
|
|
||
| #include <format> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "iceberg/catalog.h" | ||
| #include "iceberg/location_provider.h" | ||
| #include "iceberg/logging/log_macros.h" | ||
| #include "iceberg/schema.h" | ||
| #include "iceberg/snapshot.h" | ||
| #include "iceberg/statistics_file.h" | ||
|
|
@@ -375,15 +377,55 @@ Result<std::shared_ptr<Table>> Transaction::Commit() { | |
| int32_t max_wait_ms = props.Get(TableProperties::kCommitMaxRetryWaitMs); | ||
| int32_t total_timeout_ms = props.Get(TableProperties::kCommitTotalRetryTimeMs); | ||
|
|
||
| // Snapshot id before the commit, to detect whether this commit advanced it (a | ||
| // data commit) versus a metadata-only commit that adds no snapshot. | ||
| const int64_t base_current_snapshot_id = ctx_->table->metadata()->current_snapshot_id; | ||
| bool is_first_attempt = true; | ||
| int32_t attempt = 0; | ||
| std::string last_error; | ||
| auto commit_result = | ||
| MakeCommitRetryRunner(num_retries, min_wait_ms, max_wait_ms, total_timeout_ms) | ||
| .Run([this, &is_first_attempt]() -> Result<std::shared_ptr<Table>> { | ||
| .Run([this, &is_first_attempt, &attempt, | ||
| &last_error]() -> Result<std::shared_ptr<Table>> { | ||
| ++attempt; | ||
| // The runner only re-invokes this task when it has decided to retry, so | ||
| // attempt > 1 here means a genuine retry after a retryable failure. | ||
| if (attempt > 1) { | ||
| ICEBERG_LOG_WARN("Retrying transaction commit (attempt {}) after: {}", | ||
| attempt, last_error); | ||
| } | ||
| auto result = CommitOnce(is_first_attempt); | ||
| is_first_attempt = false; | ||
| if (!result.has_value()) { | ||
| last_error = result.error().message; | ||
| } | ||
| return result; | ||
| }); | ||
|
|
||
| if (commit_result.has_value()) { | ||
| // Name the resulting snapshot only when this commit produced one (current | ||
| // snapshot advanced); metadata-only commits report a plain success. | ||
| std::string detail; | ||
| if (auto snapshot = commit_result.value()->metadata()->Snapshot(); | ||
| snapshot.has_value() && | ||
| snapshot.value()->snapshot_id != base_current_snapshot_id) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can mislabel commits: a metadata-only retry may report another writer’s snapshot, while StageOnly/ToBranch commits report none. Can we detect newly added snapshots instead of comparing current IDs? |
||
| const auto& summary = snapshot.value()->summary; | ||
| auto op = summary.find(SnapshotSummaryFields::kOperation); | ||
| detail = | ||
| std::format(": committed snapshot {} (op={})", snapshot.value()->snapshot_id, | ||
| op != summary.end() ? op->second : "unknown"); | ||
| } | ||
| if (attempt > 1) { | ||
| ICEBERG_LOG_INFO("Transaction commit succeeded after {} attempts{}", attempt, | ||
| detail); | ||
| } else { | ||
| ICEBERG_LOG_INFO("Transaction commit succeeded{}", detail); | ||
| } | ||
| } else { | ||
| ICEBERG_LOG_ERROR("Transaction commit failed after {} attempt(s): {}", attempt, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java propagates the final commit error without a generic ERROR log. Also, |
||
| commit_result.error().message); | ||
| } | ||
|
|
||
| Result<const TableMetadata*> finalize_result = | ||
| commit_result.has_value() | ||
| ? Result<const TableMetadata*>(commit_result.value()->metadata().get()) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we drop this DEBUG log to stay closer to Java?
AddSnapshotis a low-level builder operation and may run for temporary or retry metadata that is never committed; Java logs only after the snapshot commit succeeds.