Skip to content

Support procedure expire_snapshots for iceberg#22609

Merged
hantangwangd merged 2 commits intoprestodb:masterfrom
hantangwangd:support_expire_snapshots
May 7, 2024
Merged

Support procedure expire_snapshots for iceberg#22609
hantangwangd merged 2 commits intoprestodb:masterfrom
hantangwangd:support_expire_snapshots

Conversation

@hantangwangd
Copy link
Member

@hantangwangd hantangwangd commented Apr 25, 2024

Description

This PR support the procedure expire_snapshots for iceberg. It can be used to remove older snapshots or specified snapshots and their files which are no longer needed.

See examples as follow:

  • Remove snapshots older than specific day and time, but retain the last 10 snapshots::
CALL iceberg.system.expire_snapshots('schema_name', 'table_name', TIMESTAMP '2023-08-31 00:00:00.000', 10);
  • Remove snapshots with snapshot ID 10001 and 10002 (note that this snapshot ID should not be the current snapshot)::
CALL iceberg.system.expire_snapshots(schema => 'schema_name', table_name => 'table_name', snapshot_ids => ARRAY[10001, 10002]);

Motivation and Context

Support expiring snapshots for iceberg

Test Plan

  • Newly added test cases in TestExpireSnapshotProcedure

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

== RELEASE NOTES ==


Iceberg Connector Changes
* Add procedure `expire_snapshots` to remove old snapshots in Iceberg. :pr:`22609`

@hantangwangd hantangwangd requested review from a team and steveburnett as code owners April 25, 2024 04:11
@hantangwangd hantangwangd requested a review from presto-oss April 25, 2024 04:11
@github-actions
Copy link

github-actions bot commented Apr 25, 2024

Codenotify: Notifying subscribers in CODENOTIFY files for diff 152f962...5fbfac8.

No notifications.

Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the doc! Looks good, I made a few suggestions. Let me know what you think.

``retain_last`` int Number of ancestor snapshots to preserve regardless of older_than
(defaults to 1)

``snapshot_ids`` array of long Array of snapshot IDs to expire
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a word missing after "array of long"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, what I want to express is that the type is array of long. Is it OK with this expression in your opinion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine! I was unfamiliar with the phrase and I should have looked it up first. This is good as is. Thanks!

steveburnett
steveburnett previously approved these changes Apr 26, 2024
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! (docs)

Pull updated branch, new local docs build, everything looks good. Thanks!

@steveburnett
Copy link
Contributor

Suggest minor changes to the release note entry, following the Order of Changes and Section naming in Release Notes Guidelines.

== RELEASE NOTES ==

Iceberg Connector Changes
* Add procedure `expire_snapshots` to remove old snapshots in Iceberg. :pr:`22609`

@hantangwangd
Copy link
Member Author

@steveburnett Thanks for the standardization of the release note, fixed!

Copy link
Contributor

@kiersten-stokes kiersten-stokes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! All the expiry options seem at first like they're going to require a lot of explanation, but it's very clear and concise 😄

Copy link
Contributor

@tdcmeehan tdcmeehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a couple of questions.


protected long waitUntilAfter(long timestampMillis)
{
long current = System.currentTimeMillis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is run in a hot loop. I don't see where we actually wait though--this seems to always wait until after the timestamp of the snapshot. Do we need it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need this. Iceberg's ExpireSnapshots.expireOlderThan(timestamp) will expires all snapshots older than the given milliseconds timestamp, that means the snapshot with the same timestamp would not be expired. So for the sake of stability in testing, we'd better wait for this millisecond to pass, in case that all things happen in the same millisecond.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just use Thread.sleep(1) in place of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I referred to Iceberg's test cases which use this spinning wait. In my opinion, when the wait time is very short, for example shorter than 1ms in this case, a spinning wait may be better than a block wait. It could avoid thread scheduling and context switching which may be triggered by Thread.sleep(ts), that might cause the waiting time more longer than expected.

Besides, should we obey the test standards to avoid using Thread.sleep? Referring to https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md?plain=1#L374

Copy link
Contributor

@tdcmeehan tdcmeehan May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's shorter than 1ms, let's add a precondition which asserts that, so that the test fails rather than busy waits? Perhaps a boundary of ~10ms is reasonable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense! Fixed.

@hantangwangd hantangwangd dismissed stale reviews from kiersten-stokes and steveburnett via 7df0a18 May 2, 2024 02:45
@hantangwangd hantangwangd force-pushed the support_expire_snapshots branch from efb9853 to 7df0a18 Compare May 2, 2024 02:45
Copy link
Contributor

@ZacBlanco ZacBlanco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few minor things, otherwise LGTM


protected long waitUntilAfter(long timestampMillis)
{
long current = System.currentTimeMillis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just use Thread.sleep(1) in place of this?

@hantangwangd hantangwangd force-pushed the support_expire_snapshots branch 2 times, most recently from 938433a to c55b898 Compare May 7, 2024 00:31
ZacBlanco
ZacBlanco previously approved these changes May 7, 2024
Copy link
Contributor

@tdcmeehan tdcmeehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nit, otherwise LGTM

@hantangwangd hantangwangd merged commit f78f6f1 into prestodb:master May 7, 2024
@hantangwangd hantangwangd deleted the support_expire_snapshots branch May 7, 2024 23:12
@wanglinsong wanglinsong mentioned this pull request Jun 25, 2024
36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants