-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Kernel] [CatalogManaged] New Transaction and Committer etc. APIs #4814
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
Merged
scottsand-db
merged 10 commits into
delta-io:master
from
scottsand-db:stack/kernel_catalog_managed_writes_1
Jul 14, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
56ac3b9
done first pass
scottsand-db 81a8dd1
make CommitFailedException member fields final
scottsand-db 3056f5f
add method comment
scottsand-db 2b699f4
implement pr feedback; public getters
scottsand-db 57bb2d5
add new txn APIs; add javadocs
scottsand-db a8c24aa
minor javadoc update
scottsand-db 9470b18
minor javadoc update
scottsand-db cff5da7
fix typo
scottsand-db 230779b
pr feedback: javadocs
scottsand-db de9c419
update javadocs
scottsand-db 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 hidden or 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
60 changes: 60 additions & 0 deletions
60
kernel/kernel-api/src/main/java/io/delta/kernel/commit/CommitContext.java
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (2025) The Delta Lake Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.delta.kernel.commit; | ||
|
||
import io.delta.kernel.annotation.Experimental; | ||
import io.delta.kernel.data.Row; | ||
import io.delta.kernel.transaction.TransactionV2; | ||
import io.delta.kernel.utils.CloseableIterator; | ||
|
||
/** | ||
* A container class for all the information that an engine needs to commit to a table. | ||
* | ||
* <p>This interface encapsulates both the actions to be committed and the associated metadata | ||
* required for the commit process. Engines use this context to provide inputs to the {@link | ||
* Committer#commit} method. | ||
* | ||
* @see TransactionV2#getInitialCommitContext | ||
*/ | ||
@Experimental | ||
public interface CommitContext { | ||
|
||
/** | ||
* Returns the finalized actions that the engine must forward to the {@link Committer} to commit | ||
* to the table. | ||
* | ||
* <p>These actions represent the changes this transaction will make, including data file | ||
* additions, metadata updates, and protocol changes. | ||
* | ||
* <p><b>Important limitations:</b> | ||
* | ||
* <ul> | ||
* <li>This iterator can only be accessed and consumed once | ||
* <li>For retry support, engines must materialize these actions before each commit attempt, | ||
* allowing them to be replayed and then updated during conflict resolution with the latest | ||
* table state | ||
* </ul> | ||
*/ | ||
CloseableIterator<Row> getFinalizedActions(); | ||
|
||
/** | ||
* Returns the {@link CommitMetadata} associated with this commit, which contains additional | ||
* metadata required to commit the finalized actions to the table, such as the commit version, | ||
* Delta log path, and more. | ||
*/ | ||
CommitMetadata getCommitMetadata(); | ||
} |
62 changes: 62 additions & 0 deletions
62
kernel/kernel-api/src/main/java/io/delta/kernel/commit/CommitFailedException.java
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (2025) The Delta Lake Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.delta.kernel.commit; | ||
|
||
import io.delta.kernel.annotation.Experimental; | ||
|
||
/** | ||
* Exception raised by {@link Committer#commit}. | ||
* | ||
* <pre> | ||
* | retryable | conflict | meaning | | ||
* | no | no | something bad happened (e.g. auth failure) | | ||
* | no | yes | permanent transaction conflict (e.g. multi-table commit failed) | | ||
* | yes | no | transient error (e.g. network hiccup) | | ||
* | yes | yes | physical conflict (allowed to rebase and retry) | | ||
* </pre> | ||
*/ | ||
@Experimental | ||
public class CommitFailedException extends Exception { | ||
scottsand-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final boolean retryable; | ||
private final boolean conflict; | ||
|
||
// TODO: [delta-io/delta#4908] Include the winning, conflicting catalog ratified commits here | ||
|
||
public CommitFailedException(boolean retryable, boolean conflict, String message) { | ||
super(message); | ||
this.retryable = retryable; | ||
this.conflict = conflict; | ||
} | ||
|
||
public CommitFailedException( | ||
boolean retryable, boolean conflict, String message, Throwable cause) { | ||
super(message, cause); | ||
this.retryable = retryable; | ||
this.conflict = conflict; | ||
} | ||
|
||
/** Returns whether the commit can be retried. */ | ||
public boolean isRetryable() { | ||
return retryable; | ||
} | ||
|
||
/** Returns whether the commit failed due to a conflict. */ | ||
public boolean isConflict() { | ||
return conflict; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
kernel/kernel-api/src/main/java/io/delta/kernel/commit/CommitMetadata.java
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (2025) The Delta Lake Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.delta.kernel.commit; | ||
|
||
import static io.delta.kernel.internal.util.Preconditions.checkArgument; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import io.delta.kernel.annotation.Experimental; | ||
import io.delta.kernel.internal.actions.CommitInfo; | ||
import io.delta.kernel.internal.actions.Metadata; | ||
import io.delta.kernel.internal.actions.Protocol; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Contains all information (excluding the iterator of finalized actions) required to commit changes | ||
* to a Delta table. | ||
*/ | ||
@Experimental | ||
public class CommitMetadata { | ||
|
||
private final long version; | ||
private final String logPath; | ||
private final CommitInfo commitInfo; | ||
private final Optional<Protocol> readProtocolOpt; | ||
private final Optional<Metadata> readMetadataOpt; | ||
private final Optional<Protocol> newProtocolOpt; | ||
private final Optional<Metadata> newMetadataOpt; | ||
|
||
public CommitMetadata( | ||
scottsand-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
long version, | ||
String logPath, | ||
CommitInfo commitInfo, | ||
Optional<Protocol> readProtocolOpt, | ||
Optional<Metadata> readMetadataOpt, | ||
Optional<Protocol> newProtocolOpt, | ||
Optional<Metadata> newMetadataOpt) { | ||
scottsand-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
checkArgument(version >= 0, "version must be non-negative: %d", version); | ||
this.version = version; | ||
this.logPath = requireNonNull(logPath, "logPath is null"); | ||
this.commitInfo = requireNonNull(commitInfo, "commitInfo is null"); | ||
this.readProtocolOpt = requireNonNull(readProtocolOpt, "readProtocolOpt is null"); | ||
this.readMetadataOpt = requireNonNull(readMetadataOpt, "readMetadataOpt is null"); | ||
this.newProtocolOpt = requireNonNull(newProtocolOpt, "newProtocolOpt is null"); | ||
this.newMetadataOpt = requireNonNull(newMetadataOpt, "newMetadataOpt is null"); | ||
} | ||
|
||
/** The version of the Delta table this commit is targeting. */ | ||
public long getVersion() { | ||
return version; | ||
} | ||
|
||
/** The path to the Delta log directory, located at {@code <table_root>/_delta_log}. */ | ||
public String getDeltaLogDirPath() { | ||
return logPath; | ||
} | ||
|
||
/** The {@link CommitInfo} that is being written as part of this commit. */ | ||
public CommitInfo getCommitInfo() { | ||
return commitInfo; | ||
} | ||
|
||
/** | ||
* The {@link Protocol} that was read at the beginning of the commit. Empty if a new table is | ||
* being created. | ||
*/ | ||
public Optional<Protocol> getReadProtocolOpt() { | ||
return readProtocolOpt; | ||
} | ||
|
||
/** | ||
* The {@link Metadata} that was read at the beginning of the commit. Empty if a new table is | ||
* being created. | ||
scottsand-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public Optional<Metadata> getReadMetadataOpt() { | ||
return readMetadataOpt; | ||
} | ||
|
||
/** | ||
* The {@link Protocol} that is being written as part of this commit. Empty if the protocol is not | ||
* being changed. | ||
*/ | ||
public Optional<Protocol> getNewProtocolOpt() { | ||
return newProtocolOpt; | ||
} | ||
|
||
/** | ||
* The {@link Metadata} that is being written as part of this commit. Empty if the metadata is not | ||
* being changed. | ||
*/ | ||
public Optional<Metadata> getNewMetadataOpt() { | ||
return newMetadataOpt; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
kernel/kernel-api/src/main/java/io/delta/kernel/commit/CommitResponse.java
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (2025) The Delta Lake Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.delta.kernel.commit; | ||
|
||
import io.delta.kernel.annotation.Experimental; | ||
import io.delta.kernel.internal.files.ParsedLogData; | ||
|
||
/** Response container for the result of a commit operation. */ | ||
@Experimental | ||
public class CommitResponse { | ||
|
||
// TODO: Create a DeltaLogData extends ParsedLogData that includes commit timestamp information. | ||
private final ParsedLogData commitLogData; | ||
|
||
public CommitResponse(ParsedLogData commitLogData) { | ||
this.commitLogData = commitLogData; | ||
} | ||
|
||
/** | ||
* The parsed log data resulting from the commit operation. Note that for catalog-managed tables, | ||
* this may be the ratified staged commit, the ratified inline commit, or even a published Delta | ||
* file that the {@link Committer} implementation decided to publish after committing to the | ||
* managing catalog. | ||
*/ | ||
public ParsedLogData getCommitLogData() { | ||
return commitLogData; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
kernel/kernel-api/src/main/java/io/delta/kernel/commit/Committer.java
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (2025) The Delta Lake Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.delta.kernel.commit; | ||
|
||
import io.delta.kernel.annotation.Experimental; | ||
import io.delta.kernel.data.Row; | ||
import io.delta.kernel.engine.Engine; | ||
import io.delta.kernel.utils.CloseableIterator; | ||
|
||
/** | ||
* Interface for committing changes to Delta tables, supporting both filesystem-managed and | ||
* catalog-managed tables. | ||
*/ | ||
@Experimental | ||
public interface Committer { | ||
|
||
/** | ||
* Commits the given {@code finalizedActions} and {@code commitMetadata} to the table. | ||
* | ||
* <p>Filesystem-managed tables: Implementations must write the {@code finalizedActions} into a | ||
* new Delta JSON file at version {@link CommitMetadata#getVersion()} using atomic file operations | ||
* (PUT-if-absent semantics). | ||
* | ||
* <p>Catalog-managed tables: Implementations must follow the commit rules and requirements as | ||
* dictated by the managing catalog to ensure commit atomicity and consistency. This may involve: | ||
* | ||
* <ol> | ||
* <li>Writing the finalized actions into a staged commit file | ||
* <li>Calling catalog commit APIs with the staged commit location (or inline content) and | ||
* additional metadata (such as the commit Protocol and Metadata) | ||
* <li>Publishing ratified catalog commits into the Delta log | ||
* </ol> | ||
* | ||
* @param engine the {@link Engine} instance used for committing changes | ||
* @param finalizedActions the iterator of finalized actions to be committed, taken from {@link | ||
* CommitContext#getFinalizedActions()}. Callers must either | ||
* <ul> | ||
* <li>Pass the iterator directly from the {@link CommitContext} into this call site | ||
* <li>First materialize the iterator contents (e.g., into a {@link java.util.List}) and | ||
* then create a new iterator from the materialized data | ||
* </ul> | ||
* | ||
* @param commitMetadata the {@link CommitMetadata} associated with this commit, which contains | ||
* additional metadata required to commit the finalized actions to the table, such as the | ||
* commit version, Delta log path, and more. | ||
* @return CommitResponse containing the resultant commit | ||
* @throws CommitFailedException if the commit operation fails | ||
*/ | ||
CommitResponse commit( | ||
Engine engine, CloseableIterator<Row> finalizedActions, CommitMetadata commitMetadata) | ||
scottsand-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throws CommitFailedException; | ||
|
||
// TODO: API to get the required table properties | ||
} |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.