-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Core: Replace SnapshotUtil firstSnapshotAfterTimestamp #3775
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
Changes from 1 commit
448238e
f35a708
5d26e8a
e638b67
d6dfa77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,43 +102,35 @@ public static Iterable<Snapshot> ancestorsOf(long snapshotId, Function<Long, Sna | |
| } | ||
|
|
||
| /** | ||
| * Traverses the history of the table's current snapshot and: | ||
| * 1. returns null, if no snapshot exists or target timestamp is more recent than the current snapshot. | ||
| * 2. else return the first snapshot which satisfies {@literal >=} targetTimestamp. | ||
| * <p> | ||
| * Given the snapshots (with timestamp): [S1 (10), S2 (11), S3 (12), S4 (14)] | ||
| * <p> | ||
| * firstSnapshotAfterTimestamp(table, x {@literal <=} 10) = S1 | ||
| * firstSnapshotAfterTimestamp(table, 11) = S2 | ||
| * firstSnapshotAfterTimestamp(table, 13) = S4 | ||
| * firstSnapshotAfterTimestamp(table, 14) = S4 | ||
| * firstSnapshotAfterTimestamp(table, x {@literal >} 14) = null | ||
| * <p> | ||
| * where x is the target timestamp in milliseconds and Si is the snapshot | ||
| * Traverses the history of the table's current snapshot and finds the first snapshot after the given timestamp. | ||
| * | ||
| * @param table a table | ||
| * @param targetTimestampMillis a timestamp in milliseconds | ||
| * @return the first snapshot which satisfies {@literal >=} targetTimestamp, or null if the current snapshot is | ||
| * more recent than the target timestamp | ||
| * @param timestampMillis a timestamp in milliseconds | ||
| * @return the first snapshot after the given timestamp, or null if the current snapshot is older than the timestamp | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add the word "committed" again here and before all the "afters". I don't know why I can't handle both concepts in my head at the same time, but I keep visualizing a linked list fo snapshots.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to understand the removal of ">=" from this and other comments, is it intended? If so, it doens't seem to match the code below which still seems to return ">="
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replaced the previous Javadoc with the original one that I wrote. I can be more clear here if needed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, got it that it's a new method rather than change. To me the previous javadoc is more clear, as "older" gives the impression of strictly greater than. |
||
| * @throws IllegalStateException if the first ancestor after the given time can't be determined | ||
| */ | ||
| public static Snapshot firstSnapshotAfterTimestamp(Table table, Long targetTimestampMillis) { | ||
| Snapshot currentSnapshot = table.currentSnapshot(); | ||
| // Return null if no snapshot exists or target timestamp is more recent than the current snapshot | ||
| if (currentSnapshot == null || currentSnapshot.timestampMillis() < targetTimestampMillis) { | ||
| public static Snapshot oldestAncestorAfter(Table table, long timestampMillis) { | ||
| if (table.currentSnapshot() == null) { | ||
| // there are no snapshots or ancestors | ||
| return null; | ||
| } | ||
|
|
||
| // Return the oldest snapshot which satisfies >= targetTimestamp | ||
| Snapshot lastSnapshot = null; | ||
| for (Snapshot snapshot : currentAncestors(table)) { | ||
| if (snapshot.timestampMillis() < targetTimestampMillis) { | ||
| if (snapshot.timestampMillis() <= timestampMillis) { | ||
| return lastSnapshot; | ||
| } | ||
|
|
||
| lastSnapshot = snapshot; | ||
| } | ||
|
|
||
| // Return the oldest snapshot if the target timestamp is less than the oldest snapshot of the table | ||
| return lastSnapshot; | ||
| if (lastSnapshot != null && lastSnapshot.parentId() == null) { | ||
| // this is the first snapshot in the table, return it | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a little worried about having a function which works for a given input but only until the starting snapshot is expired. For example I think if we want to standardize this should probably also throw an exception
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point here, but the result is based on the table state that gets passed in. If the table state is missing information, then we can't make it consistent. Here's another way to think about it: I think that the behavior above is worse than throwing an exception based on the table state because it is silently inconsisent. At least throwing an exception tells you why it isn't returning the expected value.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that we should change it, I just think we can just always throw the exception so |
||
| return lastSnapshot; | ||
| } | ||
|
|
||
| throw new IllegalStateException( | ||
| "Cannot find snapshot older than " + DateTimeUtil.formatTimestampMillis(timestampMillis)); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.