-
Notifications
You must be signed in to change notification settings - Fork 624
Store per-user state for indexes #3153
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
Store per-user state for indexes #3153
Conversation
d69fbd5
to
851de4f
Compare
Coverage ReportAffected SDKs
Test Logs
NotesHTML coverage reports can be produced locally with Head commit (fef3bbbe) is created by Prow via merging commits: a8f8dd9 8152115. |
Binary Size ReportAffected SDKs
Test Logs
NotesHead commit (fef3bbbe) is created by Prow via merging commits: a8f8dd9 8152115. |
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.
First pass. Haven't looked at the tests yet, but had some initial feedback for the implementation + some questions.
@@ -340,7 +339,8 @@ public FirebaseApp getApp() { | |||
} | |||
} | |||
|
|||
parsedIndices.add(FieldIndex.create(-1, collectionGroup, segments, SnapshotVersion.NONE)); | |||
parsedIndices.add( | |||
FieldIndex.create(-1, collectionGroup, segments, FieldIndex.IndexState.DEFAULT)); |
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.
nit: can we use a static global var for -1?
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.
Done.
@@ -131,71 +135,87 @@ public Results backfill() { | |||
return persistence.runTransaction( | |||
"Backfill Indexes", | |||
() -> { | |||
// TODO(indexing): Handle field indexes that are removed by the user. |
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.
Did you mean to remove this TODO? It seems like we haven't handled deleting field indexes yet.
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 was handled in another PR: #3118
firebase-firestore/src/main/java/com/google/firebase/firestore/local/IndexBackfiller.java
Show resolved
Hide resolved
return oldestDocuments.size(); | ||
} | ||
|
||
/** Returns the new read time for the index. */ |
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.
nit: add comment that documents input needs to be sorted by read time.
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.
Done
firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteIndexManager.java
Show resolved
Hide resolved
() -> { | ||
// TODO(indexing): Do we need to store a different update time per user? We need to ensure | ||
// that we index mutations entries for all users. | ||
// Global configuration for all existing indices |
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.
s/indices/field indexes
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.
Done
firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteIndexManager.java
Show resolved
Hide resolved
firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteIndexManager.java
Show resolved
Hide resolved
+ "FROM index_state WHERE uid = ?") | ||
.forEach( | ||
row -> { | ||
int indexId = row.getInt(1); |
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.
row.getInt(0) maps to indexid
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.
Thanks for catching. Fixed and tested.
firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteIndexManager.java
Show resolved
Hide resolved
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.
lgtm, thanks for explaining some of the questions i had
db.execute( | ||
"REPLACE INTO index_state (index_id, uid, sequence_number, " | ||
+ "read_time_seconds, read_time_nanos) VALUES(?, ?, ?, ?, ?)", | ||
collectionGroup, |
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.
Should we be passing in updatedIndex.getIndexId()
instead of collectionGroup
here? If so, please add test.
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.
Holy !$#1! So there was a test for this that should have caught this - the testChangeUser()
. The only problem is that it called updateCollectionGroup
with the first index. When we then call start()
we call row.getInt()
. The value is actually coll1
, but getInt()
returns 0
, which happens to be the right value. I changed the test to modify the second index instead.
Thanks so much for spotting!
assertEquals("coll3", collectionGroups.get(0)); | ||
assertEquals("coll1", collectionGroups.get(1)); | ||
assertEquals("coll2", collectionGroups.get(2)); | ||
collectionGroup = indexManager.getNextCollectionGroupToUpdate(); |
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.
nit: remove outdated comment
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.
Done
FieldIndex fieldIndex = | ||
fieldIndex( | ||
collectionGroup, | ||
-1, |
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.
nit: use FieldIndex const values here and below
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.
Done
assertEquals(2, collectionGroups.size()); | ||
assertEquals("coll1", collectionGroups.get(0)); | ||
assertEquals("coll2", collectionGroups.get(1)); | ||
indexManager.addFieldIndex( |
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.
nit: update test name to reflect this test
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.
Done
/test device-check-changed |
@schmidt-sebastian: The following test failed, say
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. |
This PR moves the "how updated is the index?" state from the index table to a per-user table and adds a sequence number. This allows the backfiller to process all index entries independently for each user.