-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Kernel] Add Snapshot::getTimestamp
public API
#3791
Merged
scottsand-db
merged 4 commits into
delta-io:master
from
scottsand-db:delta_kernel_snapshot_timestamp_public_api
Dec 4, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,11 +64,44 @@ public SnapshotImpl( | |
this.inCommitTimestampOpt = Optional.empty(); | ||
} | ||
|
||
///////////////// | ||
// Public APIs // | ||
///////////////// | ||
|
||
@Override | ||
public long getVersion(Engine engine) { | ||
return version; | ||
} | ||
|
||
/** | ||
* Get the timestamp (in milliseconds since the Unix epoch) of the latest commit in this Snapshot. | ||
* If the table does not yet exist (i.e. this Snapshot is being used to create the new table), | ||
* this method returns -1. Note that this -1 value will never be exposed to users - either they | ||
* get a valid snapshot for a table or they get an exception. | ||
* | ||
* <p>When InCommitTimestampTableFeature is enabled, the timestamp is retrieved from the | ||
* CommitInfo of the latest commit in this Snapshot, which can result in an IO operation. | ||
* | ||
* <p>For non-ICT tables, this is the same as the file modification time of the latest commit in | ||
* this Snapshot. | ||
*/ | ||
@Override | ||
public long getTimestamp(Engine engine) { | ||
if (IN_COMMIT_TIMESTAMPS_ENABLED.fromMetadata(metadata)) { | ||
if (!inCommitTimestampOpt.isPresent()) { | ||
Optional<CommitInfo> commitInfoOpt = | ||
CommitInfo.getCommitInfoOpt(engine, logPath, logSegment.version); | ||
inCommitTimestampOpt = | ||
Optional.of( | ||
CommitInfo.getRequiredInCommitTimestamp( | ||
commitInfoOpt, String.valueOf(logSegment.version), dataPath)); | ||
} | ||
return inCommitTimestampOpt.get(); | ||
} else { | ||
return logSegment.lastCommitTimestamp; | ||
} | ||
} | ||
|
||
@Override | ||
public StructType getSchema(Engine engine) { | ||
return getMetadata().getSchema(); | ||
|
@@ -79,8 +112,16 @@ public ScanBuilder getScanBuilder(Engine engine) { | |
return new ScanBuilderImpl(dataPath, protocol, metadata, getSchema(engine), logReplay, engine); | ||
} | ||
|
||
public Metadata getMetadata() { | ||
return metadata; | ||
/////////////////// | ||
// Internal APIs // | ||
/////////////////// | ||
|
||
public Path getLogPath() { | ||
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.
|
||
return logPath; | ||
} | ||
|
||
public Path getDataPath() { | ||
return dataPath; | ||
} | ||
|
||
public Protocol getProtocol() { | ||
|
@@ -102,6 +143,14 @@ public Map<String, DomainMetadata> getDomainMetadataMap() { | |
return logReplay.getDomainMetadataMap(); | ||
} | ||
|
||
public Metadata getMetadata() { | ||
return metadata; | ||
} | ||
|
||
public LogSegment getLogSegment() { | ||
return logSegment; | ||
} | ||
|
||
public CreateCheckpointIterator getCreateCheckpointIterator(Engine engine) { | ||
long minFileRetentionTimestampMillis = | ||
System.currentTimeMillis() - TOMBSTONE_RETENTION.fromMetadata(metadata); | ||
|
@@ -122,47 +171,6 @@ public Optional<Long> getLatestTransactionVersion(Engine engine, String applicat | |
return logReplay.getLatestTransactionIdentifier(engine, applicationId); | ||
} | ||
|
||
public LogSegment getLogSegment() { | ||
return logSegment; | ||
} | ||
|
||
public Path getLogPath() { | ||
return logPath; | ||
} | ||
|
||
public Path getDataPath() { | ||
return dataPath; | ||
} | ||
|
||
/** | ||
* Returns the timestamp of the latest commit of this snapshot. For an uninitialized snapshot, | ||
* this returns -1. | ||
* | ||
* <p>When InCommitTimestampTableFeature is enabled, the timestamp is retrieved from the | ||
* CommitInfo of the latest commit which can result in an IO operation. | ||
* | ||
* <p>For non-ICT tables, this is the same as the file modification time of the latest commit in | ||
* the snapshot. | ||
* | ||
* @param engine the engine to use for IO operations | ||
* @return the timestamp of the latest commit | ||
*/ | ||
public long getTimestamp(Engine engine) { | ||
if (IN_COMMIT_TIMESTAMPS_ENABLED.fromMetadata(metadata)) { | ||
if (!inCommitTimestampOpt.isPresent()) { | ||
Optional<CommitInfo> commitInfoOpt = | ||
CommitInfo.getCommitInfoOpt(engine, logPath, logSegment.version); | ||
inCommitTimestampOpt = | ||
Optional.of( | ||
CommitInfo.getRequiredInCommitTimestamp( | ||
commitInfoOpt, String.valueOf(logSegment.version), dataPath)); | ||
} | ||
return inCommitTimestampOpt.get(); | ||
} else { | ||
return logSegment.lastCommitTimestamp; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the commit coordinator client handler based on the table metadata in this snapshot. | ||
* | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 comment seems misleading. Even if this line says "Internal", 3rd party developers may call the subsequent method as they are public.