Skip to content

Change the order of checks in applyRemoteEvent() #802

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 2 commits into from
Sep 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,23 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyRemoteEvent(RemoteEve
MaybeDocument doc = entry.getValue();
MaybeDocument existingDoc = existingDocs.get(key);

if (existingDoc == null
// Note: The order of the steps below is important, since we want to ensure that
// rejected limbo resolutions (which fabricate NoDocuments with SnapshotVersion.NONE)
// never add documents to cache.
if (doc instanceof NoDocument && doc.getVersion().equals(SnapshotVersion.NONE)) {
// NoDocuments with SnapshotVersion.NONE are used in manufactured events. We remove
// these documents from cache since we lost access.
remoteDocuments.remove(doc.getKey());
changedDocs.put(key, doc);
} else if (existingDoc == null
|| doc.getVersion().compareTo(existingDoc.getVersion()) > 0
|| (doc.getVersion().compareTo(existingDoc.getVersion()) == 0
&& existingDoc.hasPendingWrites())) {
// TODO(index-free): Comment in this assert when we enable Index-Free queries
// hardAssert(!SnapshotVersion.NONE.equals(remoteEvent.getSnapshotVersion()), "Cannot
// add a document when the remote version is zero");
remoteDocuments.add(doc, remoteEvent.getSnapshotVersion());
changedDocs.put(key, doc);
} else if (doc instanceof NoDocument && doc.getVersion().equals(SnapshotVersion.NONE)) {
// NoDocuments with SnapshotVersion.MIN are used in manufactured events (e.g. in the
// case of a limbo document resolution failing). We remove these documents from cache
// since we lost access.
remoteDocuments.remove(doc.getKey());
changedDocs.put(key, doc);
} else {
Logger.debug(
"LocalStore",
Expand Down