-
Notifications
You must be signed in to change notification settings - Fork 66
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
fix: bulkWriter: writing to the same doc doesn't create a new batch #394
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,21 +26,18 @@ | |
*/ | ||
@InternalApi | ||
public final class BatchWriteResult { | ||
private final DocumentReference documentReference; | ||
private final String key; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also s/key/documentKey since this is not apparent from the classes context (or documentPath - see below). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks to IntelliJ, realized this field is no longer needed. Will remove in Node as well. |
||
@Nullable private final Timestamp writeTime; | ||
@Nullable private final Exception exception; | ||
|
||
BatchWriteResult( | ||
DocumentReference documentReference, | ||
@Nullable Timestamp timestamp, | ||
@Nullable Exception exception) { | ||
this.documentReference = documentReference; | ||
BatchWriteResult(String key, @Nullable Timestamp timestamp, @Nullable Exception exception) { | ||
this.key = key; | ||
this.writeTime = timestamp; | ||
this.exception = exception; | ||
} | ||
|
||
public DocumentReference getDocumentReference() { | ||
return documentReference; | ||
public String getKey() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/getKey/getDocumentKey There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
return key; | ||
} | ||
|
||
@Nullable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,6 @@ | |
|
||
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>> { | ||
|
@@ -29,21 +26,13 @@ class BulkCommitBatch extends UpdateBuilder<ApiFuture<WriteResult>> { | |
super(firestore, maxBatchSize); | ||
} | ||
|
||
BulkCommitBatch( | ||
FirestoreImpl firestore, | ||
BulkCommitBatch retryBatch, | ||
final Set<DocumentReference> docsToRetry) { | ||
BulkCommitBatch(FirestoreImpl firestore, BulkCommitBatch retryBatch) { | ||
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()); | ||
|
||
// Create a new BulkCommitBatch containing only the indexes from the provided indexes to retry. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. This is different from Node, but likely better. Should we update the Node SDK to match? This might make porting simpler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funny how having more tools at your disposal does not translate to writing better code. Will create a small node PR for that later. |
||
for (int index : retryBatch.getPendingIndexes()) { | ||
this.writes.add(retryBatch.writes.get(index)); | ||
} | ||
|
||
Preconditions.checkState( | ||
retryBatch.state == BatchState.SENT, | ||
|
@@ -55,9 +44,4 @@ public boolean apply(WriteOperation writeOperation) { | |
ApiFuture<WriteResult> wrapResult(ApiFuture<WriteResult> result) { | ||
return result; | ||
} | ||
|
||
@Override | ||
boolean allowDuplicateDocs() { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
BatchWriteResult
could be package-private, which would avoid the CLIRR violation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It added another CLIRR violation for changing to package private, but I changed the rule.