-
Notifications
You must be signed in to change notification settings - Fork 132
feat: add support for BatchWriteAtLeastOnce #2520
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
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7ff7cb2
feat: add support for BatchWriteAtleastOnce
rajatbhatta 43c4f63
test: add batchwrite() support to MockSpannerServiceImpl
rajatbhatta abedd15
test: add commit timestamp to proto
rajatbhatta 21d8f67
test: add commit timestamp to proto
rajatbhatta 4858965
test: add commit timestamp to proto
rajatbhatta 81743a7
consume the stream in tests
rajatbhatta 65abc96
refactor tests
rajatbhatta 8d76346
refactor tests
rajatbhatta a3569ae
test if mutations are correctly applied
rajatbhatta 4cb0ada
null check
rajatbhatta 5401b7d
skip for emulator
rajatbhatta 5103b5c
Merge branch 'googleapis:main' into batch-write
rajatbhatta 95c3326
add method documentation
rajatbhatta 5678207
add method documentation
rajatbhatta 347e9c3
add method documentation
rajatbhatta 4c7251f
Merge branch 'googleapis:main' into batch-write
rajatbhatta 1deaa29
remove autogenerated code
rajatbhatta acece36
remove autogenerated tests
rajatbhatta 5f04154
batchWriteAtleastOnce -> batchWriteAtLeastOnce
rajatbhatta 8e15c5c
batchWriteAtleastOnceWithOptions -> batchWriteAtLeastOnceWithOptions
rajatbhatta 56f3929
changes based on updated batch write API
rajatbhatta 356849e
add copyright and doc
rajatbhatta 07f3bfb
Merge branch 'main' into batch-write-review
rajatbhatta 1ca0d31
address review comments
rajatbhatta c3e3d7b
address review comments
rajatbhatta a036ced
add more documentation
rajatbhatta d8ef791
Merge branch 'googleapis:main' into batch-write-review
rajatbhatta 7c4c73d
Merge branch 'googleapis:main' into batch-write-review
arpan14 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
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
63 changes: 63 additions & 0 deletions
63
google-cloud-spanner/src/main/java/com/google/cloud/spanner/MutationGroup.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,63 @@ | ||
/* | ||
* Copyright 2023 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.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.spanner.v1.BatchWriteRequest; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** Represents a group of Cloud Spanner mutations to be committed together. */ | ||
public class MutationGroup { | ||
private final ImmutableList<Mutation> mutations; | ||
|
||
private MutationGroup(ImmutableList<Mutation> mutations) { | ||
this.mutations = mutations; | ||
} | ||
|
||
/** Creates a {@code MutationGroup} given a vararg of mutations. */ | ||
public static MutationGroup of(Mutation... mutations) { | ||
rajatbhatta marked this conversation as resolved.
Show resolved
Hide resolved
rajatbhatta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Preconditions.checkArgument(mutations.length > 0, "Should pass in at least one mutation."); | ||
return new MutationGroup(ImmutableList.copyOf(mutations)); | ||
} | ||
|
||
/** Creates a {@code MutationGroup} given an iterable of mutations. */ | ||
public static MutationGroup of(Iterable<Mutation> mutations) { | ||
return new MutationGroup(ImmutableList.copyOf(mutations)); | ||
} | ||
|
||
/** Returns corresponding mutations for this MutationGroup. */ | ||
public ImmutableList<Mutation> getMutations() { | ||
return mutations; | ||
} | ||
|
||
static BatchWriteRequest.MutationGroup toProto(final MutationGroup mutationGroup) { | ||
List<com.google.spanner.v1.Mutation> mutationsProto = new ArrayList<>(); | ||
Mutation.toProto(mutationGroup.getMutations(), mutationsProto); | ||
return BatchWriteRequest.MutationGroup.newBuilder().addAllMutations(mutationsProto).build(); | ||
olavloite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
static List<BatchWriteRequest.MutationGroup> toListProto( | ||
final Iterable<MutationGroup> mutationGroups) { | ||
List<BatchWriteRequest.MutationGroup> mutationGroupsProto = new ArrayList<>(); | ||
for (MutationGroup group : mutationGroups) { | ||
mutationGroupsProto.add(toProto(group)); | ||
} | ||
return mutationGroupsProto; | ||
} | ||
} |
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
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
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
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
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.
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.