-
Notifications
You must be signed in to change notification settings - Fork 76
feat: add snapshot util #420
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
Conversation
wgtmac
left a comment
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.
I haven't finished my review yet. Just post my findings so far. Will review it later.
src/iceberg/util/snapshot_util.cc
Outdated
| const Table& table, int64_t snapshot_id) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto start, table.SnapshotById(snapshot_id)); | ||
| if (!start) { | ||
| return InvalidArgument("Cannot find snapshot: {}", snapshot_id); |
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.
| return InvalidArgument("Cannot find snapshot: {}", snapshot_id); | |
| return NotFound("Cannot find snapshot: {}", snapshot_id); |
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.
BTW, perhaps this should be a ICEBERG_DCHECK.
src/iceberg/util/snapshot_util.cc
Outdated
| break; | ||
| } | ||
| auto parent_result = table.SnapshotById(current->parent_snapshot_id.value()); | ||
| if (!parent_result.has_value()) { |
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.
We might need to check if the error is NotFound and return the original error for other kind of errors.
src/iceberg/util/snapshot_util.cc
Outdated
| // Parent snapshot not found (e.g., expired), stop traversal | ||
| break; | ||
| } | ||
| current = parent_result.value(); |
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.
| current = parent_result.value(); | |
| current = std::move(parent_result.value()); |
| /// Snapshot. | ||
| /// | ||
| /// \param table The table | ||
| /// \return The oldest snapshot, or nullopt if there is no current snapshot |
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.
It would be good to document that all returned std::shared_ptr<Snapshot> cannot be nullptr.
src/iceberg/util/snapshot_util.cc
Outdated
|
|
||
| Result<std::optional<std::shared_ptr<Snapshot>>> SnapshotUtil::OldestAncestorAfter( | ||
| const Table& table, TimePointMs timestamp_ms) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto current, table.current_snapshot()); |
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.
Actually it is not an error if current snapshot is not found. We can return std::nullopt when the result error is NotFound.
src/iceberg/util/snapshot_util.cc
Outdated
| Result<std::optional<std::shared_ptr<Snapshot>>> SnapshotUtil::OldestAncestorAfter( | ||
| const Table& table, TimePointMs timestamp_ms) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto current, table.current_snapshot()); | ||
| if (!current) { |
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.
table.current_snapshot() should not return a nullptr, so this should be an error instead.
src/iceberg/util/snapshot_util.cc
Outdated
| Result<bool> SnapshotUtil::IsAncestorOf(const Table& table, int64_t snapshot_id, | ||
| int64_t ancestor_snapshot_id) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto ancestors, AncestorsOf(table, snapshot_id)); | ||
| for (const auto& snapshot : ancestors) { |
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.
nit: use std::ranges for this kind of processing.
src/iceberg/util/snapshot_util.cc
Outdated
| return std::nullopt; | ||
| } | ||
|
|
||
| std::shared_ptr<Snapshot> last_snapshot = nullptr; |
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.
What about using std::optional<std::shared_ptr<Snapshot>> so we don't need to check at line 111.
src/iceberg/util/snapshot_util.cc
Outdated
| return last_snapshot; | ||
| } | ||
|
|
||
| return ValidationFailed("Cannot find snapshot older than {}", |
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.
| return ValidationFailed("Cannot find snapshot older than {}", | |
| return NotFound("Cannot find snapshot older than {}", |
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.
I'm undecided which is better, ValidationFailed, NotFound or Invalid.
src/iceberg/util/snapshot_util.cc
Outdated
| int64_t to_snapshot_id) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto to_snapshot, table.SnapshotById(to_snapshot_id)); | ||
| if (!to_snapshot) { | ||
| return InvalidArgument("Cannot find snapshot: {}", to_snapshot_id); |
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.
InvalidArgument should be used for input argument. This is an invalid state so perhaps return Invalid?
79b4b5c to
2dc17d0
Compare
wgtmac
left a comment
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.
Thanks for working on this!
No description provided.