Skip to content

Index-Free (4/6): Filter document queries by read time #617

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 3 commits into from
Aug 8, 2019

Conversation

schmidt-sebastian
Copy link
Contributor

This is the fourth of six PRs for "index-free" queries.

This PR adds the ability to getAllDocumentsMatchingQuery() to skip documents older than a given update time. This allows us to only scan for documents that have been modified since the Query's Target Mapping has been persisted.

@schmidt-sebastian
Copy link
Contributor Author

/retest

@schmidt-sebastian schmidt-sebastian changed the title Filter document queries by update time Index-Free (4/6): Filter document queries by update time Jul 15, 2019
@schmidt-sebastian
Copy link
Contributor Author

/test check-changed

@schmidt-sebastian
Copy link
Contributor Author

/test new-smoke-tests

@schmidt-sebastian
Copy link
Contributor Author

Unassigning while I am waiting for PRs that this depends upon.

@schmidt-sebastian schmidt-sebastian changed the base branch from mrschmidt/indexfree-3 to mrschmidt/indexfree-master August 7, 2019 23:45
@schmidt-sebastian schmidt-sebastian changed the title Index-Free (4/6): Filter document queries by update time Index-Free (4/6): Filter document queries by read time Aug 7, 2019
* Performs a query against the local view of all documents.
*
* @param query The query to match documents against.
* @param sinceUpdateTime If not set to SnapshotVersion.MIN, return only documents that have been
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this read time now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. Yes. Fixed here and everywhere.

@@ -112,6 +113,11 @@ public MaybeDocument get(DocumentKey key) {
continue;
}

SnapshotVersion readTime = entry.getValue().second;
if (readTime.compareTo(sinceUpdateTime) <= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If there exist documents with a read time of zero and you pass SnapshotVersion.MIN, won't this skip them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will, but SnapshotVersion.NONE is already special-cased in the client and usually indicates that we do not know the SnapshotVersion. Any document that gets written into the RemoteDocumentCache should have a known snapshot version - either the global snapshot version from Watch, or as the commit time from the WriteStream.

I added asserts to the code here to make sure that readTime is never zero, but this won't pass our tests until #695 lands.

Copy link
Contributor

Choose a reason for hiding this comment

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

The migration in #686 didn't populate read time, so all existing documents in the cache will have a zero read time.

Could you add tests for how this is expected to work against pre-existing documents?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't really have good testing infrastructure (yet) that tests client functionality after migration. We have some tests that pretend to do client like queries before and after a schema migration, but they are all low level. I'm not opposed to adding tests like this, but:

  • the MemoryRemoteDocumentCache will not have any existing documents and is not affected by migrations
  • the SQLiteRemoteDocumentCache reads all documents with NULL version numbers.

Let me know if you want me to add a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

At some level we should prove to ourselves that this works and that it's going to stay working. I see the NULL check on the read_time so I think you're right that this is functional.

On some level this could just be a test that validates the migration behaves as we expect. If it's straightforward to do so, it would be useful to stand up a SQLiteRemoteDocumentCache in the SQLiteSchemaTest and validate that migrated documents always match queries regardless of the update time you pass.

If you also deleted NoDocuments with a zero time in that migration you could validate that they don't exist post as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, to be clear: If it costs too much time or effort to make it work I'm fine with skipping it but I think it's probably worth trying.

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian Aug 8, 2019

Choose a reason for hiding this comment

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

I hacked together a test. It wasn't as bad as I thought it would be, but in return it is also not very pretty :) I am not yet validating NoDocument deletions (or deleting them for that matter).

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Aug 8, 2019
@schmidt-sebastian schmidt-sebastian merged commit 47d0230 into mrschmidt/indexfree-master Aug 8, 2019
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 8, 2019

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

Test name Commit Details Rerun command
check-changed 6c23083 link /test 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.

@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/indexfree-4 branch August 27, 2019 23:45
@firebase firebase locked and limited conversation to collaborators Oct 9, 2019
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.

4 participants