Skip to content

Backfill Mutations #3323

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 8 commits into from
Jan 24, 2022
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Jan 18, 2022

This is another version of #3202

It's a bit simpler:

  • It moves all IndexOffset logic to IndexBackfiller
  • It re-uses more code in the LocalDocumentsView
  • It removes the latest read time from the offset, as we can just keep the offset at the current read time

I also added a new LocalStoreTestCase that verifies our query processing.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jan 18, 2022

Coverage Report 1

Affected Products

  • firebase-firestore

    Overall coverage changed from 45.31% (28c950c) to 45.39% (c0f7f9b) by +0.08%.

    FilenameBase (28c950c)Merge (c0f7f9b)Diff
    AutoValue_FieldIndex_IndexState.java45.45%63.64%+18.18%
    AutoValue_FieldIndex_Segment.java33.33%54.17%+20.83%
    IndexBackfiller.java76.00%77.92%+1.92%
    LocalDocumentsResult.java?100.00%?
    MemoryRemoteDocumentCache.java98.31%98.21%-0.09%
    PatchMutation.java100.00%98.39%-1.61%
    SetMutation.java97.14%94.29%-2.86%
    SQLiteDocumentOverlayCache.java95.08%96.72%+1.64%
    SQLiteRemoteDocumentCache.java96.75%96.64%-0.11%
    Util.java65.00%67.13%+2.13%

Test Logs

Notes

  • Commit (c0f7f9b) is created by Prow via merging PR base commit (28c950c) and head commit (73d4808).
  • Run gradle <product>:checkCoverage to produce HTML coverage reports locally. After gradle commands finished, report files can be found under <product-build-dir>/reports/jacoco/.

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/b24m3DM3ci.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jan 18, 2022

Size Report 1

Affected Products

  • firebase-firestore

    TypeBase (28c950c)Merge (c0f7f9b)Diff
    aar1.24 MB1.24 MB+487 B (+0.0%)
    apk (release)3.33 MB3.33 MB+284 B (+0.0%)

Test Logs

Notes

  • Commit (c0f7f9b) is created by Prow via merging PR base commit (28c950c) and head commit (73d4808).

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/iMrTEmUrEF.html

This was referenced Jan 19, 2022
@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/simplifymutationidhandling branch from d25f862 to bba4249 Compare January 20, 2022 03:11
@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/simplifymutationidhandling branch from 49939d4 to 85eba03 Compare January 20, 2022 21:05
@schmidt-sebastian schmidt-sebastian changed the title Simplified Mutation Batch ID Handling Backfill Mutations Jan 20, 2022
@schmidt-sebastian
Copy link
Contributor Author

/test check-changed

Copy link

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

big brain 🤯

/** The result of a write to the local store. */
public final class LocalWriteResult {
private final int batchId;
/** The result of a applying local mutations. */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/of a/of

Optionally, include how this class is now being used to handle backfill.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
/** Returns the lowest offset for the provided index group. */
private IndexOffset getExistingOffset(Collection<FieldIndex> fieldIndexes) {
if (fieldIndexes.isEmpty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to assertion b/c fieldIndexes should never be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -281,4 +320,11 @@ void recalculateAndSaveOverlays(Set<DocumentKey> documentKeys) {

return results;
}

/** Returns a base document that can be used to apply `overlay`. */
private MutableDocument createBaseDocument(DocumentKey key, @Nullable Overlay overlay) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider renaming to getBaseDocument() since we're getting the base doc from remote doc cache, and then creating an invalid one if it's not found

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (this was also the original name)


IndexOffset newOffset = getNewOffset(documents, existingOffset);
IndexOffset newOffset = getNewOffset(existingOffset, nextBatch);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, please add some tests to verify offset correctness when a new fieldindex is added to a collection group that has already been partially indexed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, can we add a test to check that we call computeViews() to properly fetch the base doc for a patch mutation in an overlay without a corresponding base doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of tests to cover all these scenarios.

* @param collectionGroup The collection group for the documents.
* @param offset The offset to index into.
* @param count The number of documents to return
* @return A LocalDocumentsRResult with the documents that follow the provided offset and the last

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/RR/R

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -281,4 +320,11 @@ void recalculateAndSaveOverlays(Set<DocumentKey> documentKeys) {

return results;
}

/** Returns a base document that can be used to apply `overlay`. */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional reword: Returns the base document that corresponds to the provided overlay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped as "corresponds" doesn't sound correct when we return an invalid document for a set() even though there is actually a valid document in the cache.

}

public int getBatchId() {
return batchId;
public int getLargestBatchId() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, the "largest" batch id here lacks the surrounding context that it's the largest batch id processed by the index backfiller for a collection group. Add comment for context or separate it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed back to getBatchId().

@@ -141,7 +141,7 @@ public static IndexOffset create(
/**
* Creates an offset that matches all documents with a read time higher than {@code readTime}.
*/
public static IndexOffset create(SnapshotVersion readTime) {
public static IndexOffset create(SnapshotVersion readTime, int largestBatchId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: rename to avoid unintentional usage where caller expects offset to be the exact provided readtime.

some quick examples: createForNextReadTime/createSucessor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createSucessor() it is.

computeViews(docs, overlays, Collections.emptySet());
return new LocalDocumentsResult(largestBatchId, localDocs);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to follow along for getDocumentsMatchingCollectionQuery().

If we get the overlays in L298, don't we want to run createBaseDocument() to get the original remote base doc for the overlay rather than just use a newInvalidDocument()?

}

@Test
public void testBackfillUpdatesToLatestReadTimeInCollection() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is kind of useless now since we're already indexing a document.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. We have a similar test already (testBackfillWritesLatestReadTimeToFieldIndexOnCompletion)

@schmidt-sebastian schmidt-sebastian merged commit 2715647 into master Jan 24, 2022
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/simplifymutationidhandling branch January 24, 2022 19:52
@google-oss-bot
Copy link
Contributor

@schmidt-sebastian: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
device-check-changed 73d4808 link /test device-check-changed

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@firebase firebase locked and limited conversation to collaborators Feb 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants