Skip to content

Only fetch 50 documents per backfill #3193

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 22 commits into from
Dec 8, 2021
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Nov 30, 2021

This PR adds a dedicated API to the RemoteDocumentCache to fetch the next 50 documents per collection group. This is done with a giant UNION statement.

@google-cla google-cla bot added the cla: yes Override cla label Nov 30, 2021
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 30, 2021

Coverage Report

Affected SDKs

  • firebase-firestore

    SDK overall coverage changed from 45.20% (110b867) to 45.24% (4b5d63f4) by +0.04%.

    Filename Base (110b867) Head (4b5d63f4) Diff
    DeleteMutation.java 95.00% 90.00% -5.00%
    FieldIndex.java 100.00% 98.08% -1.92%
    IndexBackfiller.java 78.05% 76.00% -2.05%
    MemoryRemoteDocumentCache.java 100.00% 98.25% -1.75%
    PatchMutation.java 100.00% 98.39% -1.61%
    SQLiteIndexManager.java 99.37% 99.37% -0.00%
    SQLiteRemoteDocumentCache.java 95.88% 96.72% +0.85%
    SQLiteSchema.java 96.62% 96.67% +0.05%
    SetMutation.java 97.14% 94.29% -2.86%
    Util.java 66.14% 63.70% -2.44%

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (4b5d63f4) is created by Prow via merging commits: 110b867 a3a03b1.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 30, 2021

Binary Size Report

Affected SDKs

  • firebase-firestore

    Type Base (110b867) Head (4b5d63f4) Diff
    aar 1.23 MB 1.23 MB +1.72 kB (+0.1%)
    apk (release) 3.32 MB 3.33 MB +556 B (+0.0%)

Test Logs

Notes

Head commit (4b5d63f4) is created by Prow via merging commits: 110b867 a3a03b1.

@schmidt-sebastian
Copy link
Contributor Author

cc @thebrianchen

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/getnext branch 2 times, most recently from 778a22d to 2fed47b Compare December 1, 2021 17:47
@schmidt-sebastian schmidt-sebastian changed the base branch from master to mrschmidt/pathlength December 1, 2021 17:48
@schmidt-sebastian
Copy link
Contributor Author

/retest

Base automatically changed from mrschmidt/pathlength to master December 3, 2021 16:46
@schmidt-sebastian
Copy link
Contributor Author

FYI

EXPLAIN QUERY PLAN SELECT contents, read_time_seconds, read_time_nanos, path FROM remote_documents WHERE path >= 'a' AND path < 'b' AND path_length = 2 AND (read_time_seconds > 1 OR (read_time_seconds = 2 AND read_time_nanos > 3) OR ( read_time_seconds = 4 AND read_time_nanos = 5 and path > 'b')) UNION SELECT contents, read_time_seconds, read_time_nanos, path FROM remote_documents WHERE path >= 'a1' AND path < 'b1' AND path_length = 2 AND (read_time_seconds > 1 OR (read_time_seconds = 2 AND read_time_nanos > 3) OR ( read_time_seconds = 4 AND read_time_nanos = 5 and path > 'b1')) ORDER BY read_time_seconds, read_time_nanos, path LIMIT 2;
QUERY PLAN
`--MERGE (UNION)
   |--LEFT
   |  |--SEARCH remote_documents USING INDEX sqlite_autoindex_remote_documents_1 (path>? AND path<?)
   |  `--USE TEMP B-TREE FOR ORDER BY
   `--RIGHT
      |--SEARCH remote_documents USING INDEX sqlite_autoindex_remote_documents_1 (path>? AND path<?)
      `--USE TEMP B-TREE FOR ORDER BY

for (int i = 0; i < collections.size(); i += pageSize) {
results.putAll(
getAll(
collections.subList(i, Math.min(collections.size(), i + pageSize)), offset, count));
Copy link
Contributor

Choose a reason for hiding this comment

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

Each fan out call to getAll is called with count, then added directly to the result. So the result could be #collections * count?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only if collections > 100. The maximum number of documents returned is (Math.max(collections / 100) * 50). Do you think we should post-process this list?

Actually, let me just add this code. The list should only have 50 elements so there is very little overhead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I still think we should explain what pageSize is here, and I also feel there is a better name..

@wu-hui wu-hui assigned schmidt-sebastian and unassigned wu-hui Dec 8, 2021
Copy link
Contributor

@wu-hui wu-hui left a comment

Choose a reason for hiding this comment

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

LGTM.

@Override
public Map<DocumentKey, MutableDocument> getAll(
String collectionGroup, IndexOffset offset, int limit) {
// Note: This method is pretty inefficient, but t is not called since the method is only used
Copy link
Contributor

Choose a reason for hiding this comment

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

t -> it

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if this is the case then maybe just throw an exception here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to throw exception.

for (int i = 0; i < collections.size(); i += pageSize) {
results.putAll(
getAll(
collections.subList(i, Math.min(collections.size(), i + pageSize)), offset, count));
Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I still think we should explain what pageSize is here, and I also feel there is a better name..

@@ -366,4 +368,19 @@ public static StringBuilder repeatSequence(
private static <T> T advanceIterator(Iterator<T> it) {
return it.hasNext() ? it.next() : null;
}

/** Returns a map with the first {#code count} elements of {#code data} when sorted by comp. */
public static <K, V> Map<K, V> trimMap(Map<K, V> data, int count, Comparator<V> comp) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about firstNEntries?

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

@wu-hui wu-hui assigned schmidt-sebastian and unassigned wu-hui Dec 8, 2021
@schmidt-sebastian schmidt-sebastian merged commit 1986969 into master Dec 8, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/getnext branch December 8, 2021 20:19
@firebase firebase locked and limited conversation to collaborators Jan 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Override cla size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants