-
Notifications
You must be signed in to change notification settings - Fork 624
Use sequence numbers instead of read time in collection group #3111
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Submodule crashpad
updated
from e5e47b to 36d4bb
Submodule mini_chromium
updated
from 0e22ee to 76a9bb
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 |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
|
||
import androidx.annotation.Nullable; | ||
import androidx.annotation.VisibleForTesting; | ||
import com.google.firebase.Timestamp; | ||
import com.google.firebase.database.collection.ImmutableSortedMap; | ||
import com.google.firebase.firestore.core.Query; | ||
import com.google.firebase.firestore.model.Document; | ||
|
@@ -140,24 +139,30 @@ public Results backfill() { | |
/** Writes index entries until the cap is reached. Returns the number of documents processed. */ | ||
private int writeIndexEntries(LocalDocumentsView localDocumentsView) { | ||
int documentsProcessed = 0; | ||
Timestamp startingTimestamp = Timestamp.now(); | ||
|
||
while (documentsProcessed < maxDocumentsToProcess) { | ||
// Track the starting collection group to ensure that the backfill stops after looping through | ||
// all collections a single time. | ||
String startingCollectionGroup = indexManager.getNextCollectionGroupToUpdate(); | ||
|
||
// TODO(indexing): Handle pausing and resuming from the correct document if backfilling hits the | ||
// max doc limit while processing docs for a certain read time. | ||
String collectionGroup = startingCollectionGroup; | ||
while (collectionGroup != null && documentsProcessed < maxDocumentsToProcess) { | ||
int documentsRemaining = maxDocumentsToProcess - documentsProcessed; | ||
String collectionGroup = indexManager.getNextCollectionGroupToUpdate(startingTimestamp); | ||
if (collectionGroup == null) { | ||
break; | ||
} | ||
documentsProcessed += | ||
writeEntriesForCollectionGroup(localDocumentsView, collectionGroup, documentsRemaining); | ||
collectionGroup = indexManager.getNextCollectionGroupToUpdate(); | ||
if (collectionGroup == null || collectionGroup.equals(startingCollectionGroup)) { | ||
break; | ||
} | ||
} | ||
|
||
return documentsProcessed; | ||
} | ||
|
||
/** Writes entries for the fetched field indexes. */ | ||
private int writeEntriesForCollectionGroup( | ||
LocalDocumentsView localDocumentsView, String collectionGroup, int entriesRemainingUnderCap) { | ||
LocalDocumentsView localDocumentsView, String collectionGroup, int documentsRemaining) { | ||
Query query = new Query(ResourcePath.EMPTY, collectionGroup); | ||
|
||
// Use the earliest updateTime of all field indexes as the base updateTime. | ||
|
@@ -169,8 +174,15 @@ private int writeEntriesForCollectionGroup( | |
ImmutableSortedMap<DocumentKey, Document> documents = | ||
localDocumentsView.getDocumentsMatchingQuery(query, earliestUpdateTime); | ||
|
||
Queue<Document> oldestDocuments = getOldestDocuments(documents, entriesRemainingUnderCap); | ||
Queue<Document> oldestDocuments = getOldestDocuments(documents, documentsRemaining); | ||
indexManager.updateIndexEntries(oldestDocuments); | ||
|
||
// Mark the collection group as fully indexed if all documents in the collection have been | ||
// indexed during this backfill iteration. | ||
if (documentsRemaining >= documents.size()) { | ||
indexManager.markCollectionGroupIndexed(collectionGroup); | ||
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. This is different from how I implemented it. I always increment the sequence number regardless of whether I am done or not - it's a tiny bit simpler but may not be as optimal as what you are doing. We should discuss. |
||
} | ||
|
||
return oldestDocuments.size(); | ||
} | ||
|
||
|
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.
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.
That's a very big todo :)
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.
Just backfilling it in from before :)
Will tackle this in a subsequent PR