-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3.2][Kernel][Writes] Support idempotent writes (#3051)
(Split from #2944) Adds an API on `TransactionBuilder` to take the transaction identifier for idempotent writes ``` /* * Set the transaction identifier for idempotent writes. Incremental processing systems (e.g., * streaming systems) that track progress using their own application-specific versions need to * record what progress has been made, in order to avoid duplicating data in the face of * failures and retries during writes. By setting the transaction identifier, the Delta table * can ensure that the data with same identifier is not written multiple times. For more * information refer to the Delta protocol section <a * href="https://github.com/delta-io/delta/blob/master/PROTOCOL.md#transaction-identifiers"> * Transaction Identifiers</a>. * * @param engine {@link Engine} instance to use. * @param applicationId The application ID that is writing to the table. * @param transactionVersion The version of the transaction. This should be monotonically * increasing with each write for the same application ID. * @return updated {@link TransactionBuilder} instance. */ TransactionBuilder withTransactionId( Engine engine, String applicationId, long transactionVersion); ``` During the transaction build, check the latest txn version of the given AppId. If it is not monotonically increasing throw `ConcurrentTransactionException`. Added to `DeltaTableWriteSuite.scala`
- Loading branch information
1 parent
f365eb0
commit 4ae6df6
Showing
7 changed files
with
186 additions
and
6 deletions.
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
45 changes: 45 additions & 0 deletions
45
...l/kernel-api/src/main/java/io/delta/kernel/exceptions/ConcurrentTransactionException.java
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (2024) 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.exceptions; | ||
|
||
import io.delta.kernel.TransactionBuilder; | ||
import io.delta.kernel.annotation.Evolving; | ||
import io.delta.kernel.engine.Engine; | ||
|
||
/** | ||
* Thrown when concurrent transaction both attempt to update the table with same transaction | ||
* identifier set through {@link TransactionBuilder#withTransactionId(Engine, String, long)} | ||
* (String)}. | ||
* <p> | ||
* Incremental processing systems (e.g., streaming systems) that track progress using their own | ||
* application-specific versions need to record what progress has been made, in order to avoid | ||
* duplicating data in the face of failures and retries during writes. For more information refer to | ||
* the Delta protocol section <a | ||
* href="https://github.com/delta-io/delta/blob/master/PROTOCOL.md#transaction-identifiers"> | ||
* Transaction Identifiers</a> | ||
* | ||
* @since 3.2.0 | ||
*/ | ||
@Evolving | ||
public class ConcurrentTransactionException extends ConcurrentWriteException { | ||
private static final String message = "This error occurs when multiple updates are " + | ||
"using the same transaction identifier to write into this table.\n" + | ||
"Application ID: %s, Attempted version: %s, Latest version in table: %s"; | ||
|
||
public ConcurrentTransactionException(String appId, long txnVersion, long lastUpdated) { | ||
super(String.format(message, appId, txnVersion, lastUpdated)); | ||
} | ||
} |
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
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
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