-
Notifications
You must be signed in to change notification settings - Fork 74
feat: add BulkWriter #323
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
feat: add BulkWriter #323
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b1e063
fix: add bulkCommit() (#231)
db07700
fix: Add BulkWriter (#233)
7271a1e
fix: use sentinel on BulkWriter.delete() (#251)
3f250bf
fix: add BulkWriter system tests + pass BE error messages (#252)
115a184
fix: add pojo support (#265)
5972c94
fix: add retry on ABORTED errors (#286)
231be2f
chore: update clirr rules
BenWhitehead 305602c
resolve ben comments
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
55 changes: 55 additions & 0 deletions
55
google-cloud-firestore/src/main/java/com/google/cloud/firestore/BatchWriteResult.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,55 @@ | ||
| /* | ||
| * Copyright 2020 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.firestore; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import com.google.cloud.Timestamp; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * A BatchWriteResult wraps the write time and status returned by Firestore when making | ||
| * BatchWriteRequests. | ||
| */ | ||
| @InternalApi | ||
| public final class BatchWriteResult { | ||
| private final DocumentReference documentReference; | ||
| @Nullable private final Timestamp writeTime; | ||
| @Nullable private final Exception exception; | ||
|
|
||
| BatchWriteResult( | ||
| DocumentReference documentReference, | ||
| @Nullable Timestamp timestamp, | ||
| @Nullable Exception exception) { | ||
| this.documentReference = documentReference; | ||
| this.writeTime = timestamp; | ||
| this.exception = exception; | ||
| } | ||
|
|
||
| public DocumentReference getDocumentReference() { | ||
| return documentReference; | ||
| } | ||
|
|
||
| @Nullable | ||
| public Timestamp getWriteTime() { | ||
| return writeTime; | ||
| } | ||
|
|
||
| @Nullable | ||
| public Exception getException() { | ||
| return exception; | ||
| } | ||
| } | ||
63 changes: 63 additions & 0 deletions
63
google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkCommitBatch.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 2020 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.firestore; | ||
|
|
||
| import com.google.api.core.ApiFuture; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.base.Predicate; | ||
| import com.google.common.collect.FluentIterable; | ||
| import java.util.Set; | ||
|
|
||
| /** Used to represent a batch on the BatchQueue. */ | ||
| class BulkCommitBatch extends UpdateBuilder<ApiFuture<WriteResult>> { | ||
|
|
||
| BulkCommitBatch(FirestoreImpl firestore, int maxBatchSize) { | ||
| super(firestore, maxBatchSize); | ||
| } | ||
|
|
||
| BulkCommitBatch( | ||
| FirestoreImpl firestore, | ||
| BulkCommitBatch retryBatch, | ||
| final Set<DocumentReference> docsToRetry) { | ||
| super(firestore); | ||
| this.writes.addAll( | ||
| FluentIterable.from(retryBatch.writes) | ||
| .filter( | ||
| new Predicate<WriteOperation>() { | ||
| @Override | ||
| public boolean apply(WriteOperation writeOperation) { | ||
| return docsToRetry.contains(writeOperation.documentReference); | ||
| } | ||
| }) | ||
| .toList()); | ||
|
|
||
| Preconditions.checkState( | ||
| retryBatch.state == BatchState.SENT, | ||
| "Batch should be SENT when creating a new BulkCommitBatch for retry"); | ||
| this.state = retryBatch.state; | ||
| this.pendingOperations = retryBatch.pendingOperations; | ||
| } | ||
|
|
||
| ApiFuture<WriteResult> wrapResult(ApiFuture<WriteResult> result) { | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| boolean allowDuplicateDocs() { | ||
| return false; | ||
| } | ||
| } |
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.