-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support DML auto-batching in Connection API (#3386)
* feat: support DML auto-batching in Connection API Adds support for automatically batching DML statements that are executed on a connection. This can be used in combination with frameworks like Hibernate to improve performance, especially on multi-region instances with high round-trip latencies. * chore: generate libraries at Sun Oct 6 06:00:17 UTC 2024 * feat: add update count verification * fix: add ignored diffs * test: add transaction retry test * chore: cleanup and add comments * chore: generate libraries at Fri Oct 11 15:21:53 UTC 2024 * feat: use connection variables for auto_batch_dml --------- Co-authored-by: cloud-java-bot <[email protected]>
- Loading branch information
1 parent
6dfc494
commit a1ce267
Showing
23 changed files
with
39,837 additions
and
32,551 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
68 changes: 68 additions & 0 deletions
68
...rc/main/java/com/google/cloud/spanner/DmlBatchUpdateCountVerificationFailedException.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,68 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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 com.google.cloud.spanner; | ||
|
||
import com.google.cloud.spanner.connection.Connection; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Exception thrown by a {@link Connection} when an automatic DML batch detects that one or more of | ||
* the update counts that it returned during the buffering of DML statements does not match with the | ||
* actual update counts that were returned after execution. | ||
*/ | ||
public class DmlBatchUpdateCountVerificationFailedException extends AbortedException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final long[] expected; | ||
|
||
private final long[] actual; | ||
|
||
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */ | ||
DmlBatchUpdateCountVerificationFailedException( | ||
DoNotConstructDirectly token, long[] expected, long[] actual) { | ||
super( | ||
token, | ||
String.format( | ||
"Actual update counts that were returned during execution do not match the previously returned update counts.\n" | ||
+ "Expected: %s\n" | ||
+ "Actual: %s\n" | ||
+ "Set auto_batch_dml_update_count_verification to false to skip this verification.", | ||
Arrays.stream(expected).mapToObj(Long::toString).collect(Collectors.joining()), | ||
Arrays.stream(actual).mapToObj(Long::toString).collect(Collectors.joining())), | ||
/* cause = */ null); | ||
this.expected = expected; | ||
this.actual = actual; | ||
} | ||
|
||
/** | ||
* The expected update counts. These were returned to the client application when the DML | ||
* statements were buffered. | ||
*/ | ||
public long[] getExpected() { | ||
return Arrays.copyOf(this.expected, this.expected.length); | ||
} | ||
|
||
/** | ||
* The actual update counts. These were returned by Spanner to the client when the DML statements | ||
* were actually executed, and are the update counts that the client application would have | ||
* received if auto-batching had not been enabled. | ||
*/ | ||
public long[] getActual() { | ||
return Arrays.copyOf(this.actual, this.actual.length); | ||
} | ||
} |
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
Oops, something went wrong.