Skip to content
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

Add last updated timestamp and snapshotId for partition table #7581

Merged
merged 10 commits into from Jun 23, 2023

Conversation

dramaticlly
Copy link
Contributor

close #7560

What

add 2 column to partition metadata table

  • last_updated_at with timestamp with timezone type (similar to committed_at in snapshot metadata table)
  • last_updated_snapshot_id with long type

How

In Partition metadata table, we moved from iterating over ContentFiles from ManifestReader to ManifestEntry instead, since entry contain both content file and snapshotId, which are valuable to provide last updated timestamp and snapshot information. We group by file for each partition boundary and get the highest snapshot commit timestamp so that we know when exactly is the partition last modified.

Why

This can be potentially useful for iceberg table ingested by streaming application such as flink, to understand which iceberg partition is "sealed" based on timestamp. However, the write such as data compaction can also move the last update timestamp forward without actual data change, which snapshot id here can be useful for further analysis

@szehon-ho if you can help review your idea :)

@dramaticlly
Copy link
Contributor Author

CC @puchengy @ajantha-bhat if you guys are interested

"Partition last updated timestamp"),
Types.NestedField.required(
10,
"last_updated_snapshot_id",
Copy link
Member

Choose a reason for hiding this comment

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

a) Is it a good idea to keep the snapshot id? Because regularly running expire_snapshots can clean up the snapshots and we may not be able to map what operation these files were created from, even with the snapshot id.

b) There was also an ask for "latest sequence number" associated with that partition from the community users during partition stats discussion.

Do you think modified time is enough and no need for the sequence number?

Copy link
Member

Choose a reason for hiding this comment

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

also cc: @szehon-ho

Copy link
Collaborator

@szehon-ho szehon-ho May 23, 2023

Choose a reason for hiding this comment

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

Hm, what do we think to have both? (and null if its expired, as per discussion here #7581 (comment)). If we have snapshot_id, I feel its more useful than the last_update_time, but agree we don't always have it.

I think sequence number will be good too, but do you mean fileSequenceNumber or dataSequenceNumber? Maybe worth another pr if there's more discussion there?

Copy link
Member

Choose a reason for hiding this comment

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

I am just worried that most of the snapshots will be expired and we end up not using that field much.
The main purpose of storing the snapshot id is for finding what operation has last updated this partition id? In that case, we can store the operation type itself directly maybe.

I think sequence number will be good too, but do you mean fileSequenceNumber or dataSequenceNumber? Maybe worth another pr if there's more discussion there?

I guess it is fileSequenceNumber.

Yeah, we can have a separate discussion. I think data_file_size_in_bytes per partition can also be one more good candidate for storing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a) Is it a good idea to keep the snapshot id? Because regularly running expire_snapshots can clean up the snapshots and we may not be able to map what operation these files were created from, even with the snapshot id.

b) There was also an ask for "latest sequence number" associated with that partition from the community users during partition stats discussion.

Do you think modified time is enough and no need for the sequence number?

My initial thought process is like the last updated timestamp is helpful by itself but if there's doubt around the timestamp, it's better to provide a reference to allow for further investigation. Here we derived last updated timestamp from snapshot, so providing snapshotId enable a way to look up further information about snapshot (if it's a rewrite data operation or is it an append from late arrival data).

With respect to the periodic snapshot expiration, I think partition can have null snapshot based on referenced snapshotId if it was already expired, but it seems only applicable to your data outlive your snapshot. i.e if you run data compaction along side your snapshot expiration, or if you also periodically delete your partition (like if it's daily partitioned and your dataset have a retention period) together with your snapshot expiration, it seem to be fine.

As for file sequence number, I think it might be helpful but by itself it seem to be hard to use compare to timestamp and snapshotId.

Copy link
Collaborator

@szehon-ho szehon-ho May 23, 2023

Choose a reason for hiding this comment

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

@RussellSpitzer @aokolnychyi @flyrain any thoughts here, what would make more sense on Partition table?

Copy link
Collaborator

@szehon-ho szehon-ho May 27, 2023

Choose a reason for hiding this comment

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

After some thoughts, I think both will be null if the snapshot is expired. But I think we are no worse off than the alternative, which is to join the entries + snapshots table for the user to find the last update time. This also will be null if snapshot is expired.

Perhaps we can have some more persistent storage of snapshot metadata , even after expire?

I think for this case (lastUpdateTime, lastSnapshotId), it is ok to proceed, typically snapshots live several days at least, and I would imagine the user of the tool is interested in the last updated partition, and can run it before the snapshot is expired.

Steve Zhang added 2 commits June 21, 2023 14:52
…stamp with respect to rewrite manifests and expire snapshot
Copy link
Collaborator

@szehon-ho szehon-ho left a comment

Choose a reason for hiding this comment

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

Looking good and getting close, thanks !

Copy link
Collaborator

@szehon-ho szehon-ho left a comment

Choose a reason for hiding this comment

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

Thanks @dramaticlly sorry i had one more comment, just raelized

core/src/main/java/org/apache/iceberg/PartitionsTable.java Outdated Show resolved Hide resolved
Copy link
Collaborator

@szehon-ho szehon-ho left a comment

Choose a reason for hiding this comment

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

Looks great to me, just a few more minor nits

@szehon-ho
Copy link
Collaborator

Looks great, will merge tomorrow if tests pass and to wait any other comments.

@szehon-ho szehon-ho merged commit a29c6ce into apache:master Jun 23, 2023
41 checks passed
@szehon-ho
Copy link
Collaborator

Merged, thanks @dramaticlly for the great work !

@dramaticlly dramaticlly deleted the lastUpdatedSnapshot branch June 23, 2023 21:52
@miR172
Copy link

miR172 commented Sep 15, 2023

This is great! Thank you so much for adding this stat -- it is making our life so much easier.

When can we expect it to be included in a release? I noticed this wasn't in 1.3.1

@ajantha-bhat
Copy link
Member

Yes, It will be in the upcoming 1.4.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Last Updated Timestamp for Partition Metadata Table
5 participants