-
Notifications
You must be signed in to change notification settings - Fork 80
feat: implement set snapshot #509
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?
Conversation
9c831cb to
107cd63
Compare
|
|
||
| /// \brief Create a new SetSnapshot to set the current snapshot or rollback to a | ||
| /// previous snapshot and commit the changes. | ||
| virtual Result<std::shared_ptr<SetSnapshot>> NewSetSnapshot(); |
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.
Please remove this since the Java impl only adds to transaction not table.
| class UpdateSchema; | ||
| class UpdateSortOrder; | ||
| class ExpireSnapshots; | ||
| class SetSnapshot; |
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.
Put it before SnapshotUpdate
|
|
||
| std::optional<std::shared_ptr<Snapshot>> last_snapshot = std::nullopt; | ||
| ICEBERG_ASSIGN_OR_RAISE(auto ancestors, AncestorsOf(table, current)); | ||
| 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.
Let's revert this change.
| int64_t invalid_snapshot_id = 9999999999999999; | ||
| set_snapshot->SetCurrentSnapshot(invalid_snapshot_id); | ||
|
|
||
| // Should fail during Apply |
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.
| // Should fail during Apply |
| // Rollback to the oldest snapshot (which is an ancestor) | ||
| set_snapshot->RollbackTo(kOldestSnapshotId); | ||
|
|
||
| // Apply and verify |
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.
| // Apply and verify |
| TEST_F(SetSnapshotTest, RollbackToTimeExactMatch) { | ||
| ICEBERG_UNWRAP_OR_FAIL(auto set_snapshot, table_->NewSetSnapshot()); | ||
| // Rollback to a timestamp just after the oldest snapshot | ||
| // This should return the oldest snapshot (the latest one before this time) |
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.
| // This should return the oldest snapshot (the latest one before this time) |
| // Apply without making any changes (NOOP) | ||
| ICEBERG_UNWRAP_OR_FAIL(auto snapshot_id, set_snapshot->Apply()); | ||
|
|
||
| // Should return 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.
| // Apply without making any changes (NOOP) | |
| ICEBERG_UNWRAP_OR_FAIL(auto snapshot_id, set_snapshot->Apply()); | |
| // Should return current snapshot | |
| ICEBERG_UNWRAP_OR_FAIL(auto snapshot_id, set_snapshot->Apply()); |
| // Should return current snapshot | ||
| EXPECT_EQ(snapshot_id, kCurrentSnapshotId); | ||
|
|
||
| // Commit NOOP and verify nothing changed |
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.
| // Commit NOOP and verify nothing changed |
| } | ||
| auto current_timestamp = snapshot->timestamp_ms; | ||
| if (current_timestamp < target_timestamp && current_timestamp > latest_timestamp) { | ||
| latest_timestamp = current_timestamp; // Save timestamp before move |
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 think this function can return Result<std::optional<int64_t> now.
| auto current_result = metadata.Snapshot(); | ||
| ICEBERG_ACTION_FOR_NOT_FOUND(current_result, return {}); |
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.
Shouldn't we return the error as is if current snapshot is missing? The current approach may confuse the caller that the current snapshot exists but it does not have any ancestor.
No description provided.