Skip to content

Commit 7d30c11

Browse files
committed
fix: review comments
1 parent 3fdb461 commit 7d30c11

File tree

5 files changed

+45
-59
lines changed

5 files changed

+45
-59
lines changed

src/iceberg/transaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ std::string Transaction::MetadataFileLocation(std::string_view filename) const {
9393

9494
Status Transaction::AddUpdate(const std::shared_ptr<PendingUpdate>& update) {
9595
ICEBERG_PRECHECK(update->kind() != PendingUpdate::Kind::kSnapshotManager,
96-
"SnapshotManager updates should not be added to the transaction");
96+
"SnapshotManager should not be added to the transaction");
9797
ICEBERG_CHECK(last_update_committed_,
9898
"Cannot add update when previous update is not committed");
9999

src/iceberg/update/snapshot_manager.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Result<std::shared_ptr<SnapshotManager>> SnapshotManager::Make(
4141
}
4242

4343
SnapshotManager::SnapshotManager(std::shared_ptr<Transaction> transaction)
44-
: PendingUpdate(transaction) {}
44+
: PendingUpdate(std::move(transaction)) {}
4545

4646
SnapshotManager::~SnapshotManager() = default;
4747

@@ -58,9 +58,9 @@ SnapshotManager& SnapshotManager::SetCurrentSnapshot(int64_t snapshot_id) {
5858
return *this;
5959
}
6060

61-
SnapshotManager& SnapshotManager::RollbackToTime(TimePointMs timestamp_ms) {
61+
SnapshotManager& SnapshotManager::RollbackToTime(int64_t timestamp_ms) {
6262
ICEBERG_BUILDER_ASSIGN_OR_RETURN(auto set_snapshot, transaction_->NewSetSnapshot());
63-
set_snapshot->RollbackToTime(UnixMsFromTimePointMs(timestamp_ms));
63+
set_snapshot->RollbackToTime(timestamp_ms);
6464
ICEBERG_BUILDER_RETURN_IF_ERROR(set_snapshot->Commit());
6565
return *this;
6666
}
@@ -81,7 +81,7 @@ SnapshotManager& SnapshotManager::CreateBranch(const std::string& name) {
8181
const auto& current_refs = base().refs;
8282
ICEBERG_BUILDER_CHECK(!base().refs.contains(name), "Ref {} already exists", name);
8383
ICEBERG_BUILDER_ASSIGN_OR_RETURN(auto fast_append, transaction_->NewFastAppend());
84-
ICEBERG_BUILDER_RETURN_IF_ERROR(fast_append->ToBranch(name).Commit());
84+
ICEBERG_BUILDER_RETURN_IF_ERROR(fast_append->SetTargetBranch(name).Commit());
8585
return *this;
8686
}
8787

@@ -167,26 +167,24 @@ SnapshotManager& SnapshotManager::SetMaxRefAgeMs(const std::string& name,
167167
return *this;
168168
}
169169

170-
Result<std::shared_ptr<Snapshot>> SnapshotManager::Apply() { return base().Snapshot(); }
171-
172170
Status SnapshotManager::Commit() {
173171
ICEBERG_RETURN_UNEXPECTED(CheckErrors());
174172
return CommitIfRefUpdatesExist();
175173
}
176174

177175
Result<std::shared_ptr<UpdateSnapshotReference>>
178176
SnapshotManager::UpdateSnapshotReferencesOperation() {
179-
if (update_snapshot_references_operation_ == nullptr) {
180-
ICEBERG_ASSIGN_OR_RAISE(update_snapshot_references_operation_,
177+
if (update_snap_refs_ == nullptr) {
178+
ICEBERG_ASSIGN_OR_RAISE(update_snap_refs_,
181179
transaction_->NewUpdateSnapshotReference());
182180
}
183-
return update_snapshot_references_operation_;
181+
return update_snap_refs_;
184182
}
185183

186184
Status SnapshotManager::CommitIfRefUpdatesExist() {
187-
if (update_snapshot_references_operation_ != nullptr) {
188-
ICEBERG_RETURN_UNEXPECTED(update_snapshot_references_operation_->Commit());
189-
update_snapshot_references_operation_ = nullptr;
185+
if (update_snap_refs_ != nullptr) {
186+
ICEBERG_RETURN_UNEXPECTED(update_snap_refs_->Commit());
187+
update_snap_refs_ = nullptr;
190188
}
191189
return {};
192190
}

src/iceberg/update/snapshot_manager.h

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424

2525
#include "iceberg/iceberg_export.h"
2626
#include "iceberg/result.h"
27-
#include "iceberg/snapshot.h"
2827
#include "iceberg/type_fwd.h"
2928
#include "iceberg/update/pending_update.h"
30-
#include "iceberg/util/timepoint.h"
3129

3230
namespace iceberg {
3331

@@ -51,25 +49,25 @@ class ICEBERG_EXPORT SnapshotManager : public PendingUpdate {
5149
/// \brief Apply supported changes in given snapshot and create a new snapshot which
5250
/// will be set as the current snapshot on commit.
5351
///
54-
/// \param snapshot_id A snapshot ID whose changes to apply
52+
/// \param snapshot_id A Snapshot ID whose changes to apply
5553
/// \return Reference to this for method chaining
5654
SnapshotManager& Cherrypick(int64_t snapshot_id);
5755

58-
/// \brief Roll this table's data back to a specific Snapshot identified by id.
56+
/// \brief Roll this table's data back to a specific Snapshot ID.
5957
///
60-
/// \param snapshot_id Long id of the snapshot to roll back table data to
58+
/// \param snapshot_id Snapshot ID to roll back table data to
6159
/// \return Reference to this for method chaining
6260
SnapshotManager& SetCurrentSnapshot(int64_t snapshot_id);
6361

64-
/// \brief Roll this table's data back to the last Snapshot before the given timestamp.
62+
/// \brief Roll this table's data back to the last snapshot before the given timestamp.
6563
///
6664
/// \param timestamp_ms A timestamp in milliseconds
6765
/// \return Reference to this for method chaining
68-
SnapshotManager& RollbackToTime(TimePointMs timestamp_ms);
66+
SnapshotManager& RollbackToTime(int64_t timestamp_ms);
6967

70-
/// \brief Rollback table's state to a specific Snapshot identified by id.
68+
/// \brief Rollback table's state to a specific Snapshot ID.
7169
///
72-
/// \param snapshot_id Long id of snapshot id to roll back table to. Must be an ancestor
70+
/// \param snapshot_id Snapshot ID to roll back table to. Must be an ancestor
7371
/// of the current snapshot
7472
/// \return Reference to this for method chaining
7573
SnapshotManager& RollbackTo(int64_t snapshot_id);
@@ -82,14 +80,14 @@ class ICEBERG_EXPORT SnapshotManager : public PendingUpdate {
8280
/// \return Reference to this for method chaining
8381
SnapshotManager& CreateBranch(const std::string& name);
8482

85-
/// \brief Create a new branch pointing to the given snapshot id.
83+
/// \brief Create a new branch pointing to the given Snapshot ID.
8684
///
8785
/// \param name Branch name
88-
/// \param snapshot_id ID of the snapshot which will be the head of the branch
86+
/// \param snapshot_id Snapshot ID which will be the head of the branch
8987
/// \return Reference to this for method chaining
9088
SnapshotManager& CreateBranch(const std::string& name, int64_t snapshot_id);
9189

92-
/// \brief Create a new tag pointing to the given snapshot id.
90+
/// \brief Create a new tag pointing to the given Snapshot ID.
9391
///
9492
/// \param name Tag name
9593
/// \param snapshot_id Snapshot ID for the head of the new tag
@@ -111,30 +109,30 @@ class ICEBERG_EXPORT SnapshotManager : public PendingUpdate {
111109
/// \brief Replaces the tag with the given name to point to the specified snapshot.
112110
///
113111
/// \param name Tag to replace
114-
/// \param snapshot_id New snapshot id for the given tag
112+
/// \param snapshot_id New Snapshot ID for the given tag
115113
/// \return Reference to this for method chaining
116114
SnapshotManager& ReplaceTag(const std::string& name, int64_t snapshot_id);
117115

118116
/// \brief Replaces the branch with the given name to point to the specified snapshot.
119117
///
120118
/// \param name Branch to replace
121-
/// \param snapshot_id New snapshot id for the given branch
119+
/// \param snapshot_id New Snapshot ID for the given branch
122120
/// \return Reference to this for method chaining
123121
SnapshotManager& ReplaceBranch(const std::string& name, int64_t snapshot_id);
124122

125-
/// \brief Replaces the from branch to point to the to snapshot. The to will remain
126-
/// unchanged, and from branch will retain its retention properties. If the from branch
127-
/// does not exist, it will be created with default retention properties.
123+
/// \brief Replaces the `from` branch to point to the `to` snapshot. The `to` will
124+
/// remain unchanged, and `from` branch will retain its retention properties. If the
125+
/// `from` branch does not exist, it will be created with default retention properties.
128126
///
129127
/// \param from Branch to replace
130128
/// \param to The branch from should be replaced with
131129
/// \return Reference to this for method chaining
132130
SnapshotManager& ReplaceBranch(const std::string& from, const std::string& to);
133131

134-
/// \brief Performs a fast-forward of from up to the to snapshot if from is an ancestor
135-
/// of to. The to will remain unchanged, and from will retain its retention properties.
136-
/// If the from branch does not exist, it will be created with default retention
137-
/// properties.
132+
/// \brief Performs a fast-forward of `from` up to the `to` snapshot if `from` is an
133+
/// ancestor of `to`. The `to` will remain unchanged, and `from` will retain its
134+
/// retention properties. If the `from` branch does not exist, it will be created with
135+
/// default retention properties.
138136
///
139137
/// \param from Branch to fast-forward
140138
/// \param to Ref for the from branch to be fast forwarded to
@@ -171,11 +169,6 @@ class ICEBERG_EXPORT SnapshotManager : public PendingUpdate {
171169
/// \return Reference to this for method chaining
172170
SnapshotManager& SetMaxRefAgeMs(const std::string& name, int64_t max_ref_age_ms);
173171

174-
/// \brief Apply the pending changes and return the current snapshot.
175-
///
176-
/// \return The current snapshot after applying changes, or an error
177-
Result<std::shared_ptr<Snapshot>> Apply();
178-
179172
/// \brief Commit all pending changes.
180173
///
181174
/// \return Status indicating success or failure
@@ -193,7 +186,7 @@ class ICEBERG_EXPORT SnapshotManager : public PendingUpdate {
193186
/// \brief Commit any pending reference updates if they exist.
194187
Status CommitIfRefUpdatesExist();
195188

196-
std::shared_ptr<UpdateSnapshotReference> update_snapshot_references_operation_;
189+
std::shared_ptr<UpdateSnapshotReference> update_snap_refs_;
197190
};
198191

199192
} // namespace iceberg

src/iceberg/update/snapshot_update.cc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,6 @@ Status SnapshotUpdate::Finalize(std::optional<Error> commit_error) {
331331
return {};
332332
}
333333

334-
Status SnapshotUpdate::SetTargetBranch(const std::string& branch) {
335-
ICEBERG_PRECHECK(!branch.empty(), "Branch name cannot be empty");
336-
337-
if (auto ref_it = base().refs.find(branch); ref_it != base().refs.end()) {
338-
ICEBERG_PRECHECK(
339-
ref_it->second->type() == SnapshotRefType::kBranch,
340-
"{} is a tag, not a branch. Tags cannot be targets for producing snapshots",
341-
branch);
342-
}
343-
344-
target_branch_ = branch;
345-
return {};
346-
}
347-
348334
Result<std::unordered_map<std::string, std::string>> SnapshotUpdate::ComputeSummary(
349335
const TableMetadata& previous) {
350336
std::unordered_map<std::string, std::string> summary = Summary();

src/iceberg/update/snapshot_update.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,21 @@ class ICEBERG_EXPORT SnapshotUpdate : public PendingUpdate {
8080
///
8181
/// \param branch Which is name of SnapshotRef of type branch
8282
/// \return Reference to this for method chaining
83-
auto& ToBranch(this auto& self, const std::string& branch) {
84-
auto status = self.SetTargetBranch(branch);
85-
if (!status.has_value()) {
86-
return self.AddError(status.error());
83+
auto& SetTargetBranch(this auto& self, const std::string& branch) {
84+
if (branch.empty()) [[unlikely]] {
85+
return self.AddError(ErrorKind::kInvalidArgument, "Branch name cannot be empty");
8786
}
87+
88+
if (auto ref_it = self.base().refs.find(branch); ref_it != self.base().refs.end()) {
89+
if (ref_it->second->type() != SnapshotRefType::kBranch) {
90+
return self.AddError(ErrorKind::kInvalidArgument,
91+
"{} is a tag, not a branch. Tags cannot be targets for "
92+
"producing snapshots",
93+
branch);
94+
}
95+
}
96+
97+
self.target_branch_ = branch;
8898
return self;
8999
}
90100

@@ -133,7 +143,6 @@ class ICEBERG_EXPORT SnapshotUpdate : public PendingUpdate {
133143
std::span<const std::shared_ptr<DataFile>> files,
134144
const std::shared_ptr<PartitionSpec>& spec);
135145

136-
Status SetTargetBranch(const std::string& branch);
137146
const std::string& target_branch() const { return target_branch_; }
138147
bool can_inherit_snapshot_id() const { return can_inherit_snapshot_id_; }
139148
const std::string& commit_uuid() const { return commit_uuid_; }

0 commit comments

Comments
 (0)