@@ -380,18 +380,23 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyRemoteEvent(RemoteEve
380
380
MaybeDocument doc = entry .getValue ();
381
381
MaybeDocument existingDoc = existingDocs .get (key );
382
382
383
- if (existingDoc == null
383
+ // Note: The order of the steps below is important, since we want to ensure that
384
+ // rejected limbo resolutions (which fabricate NoDocuments with SnapshotVersion.NONE)
385
+ // never add documents to cache.
386
+ if (doc instanceof NoDocument && doc .getVersion ().equals (SnapshotVersion .NONE )) {
387
+ // NoDocuments with SnapshotVersion.NONE are used in manufactured events. We remove
388
+ // these documents from cache since we lost access.
389
+ remoteDocuments .remove (doc .getKey ());
390
+ changedDocs .put (key , doc );
391
+ } else if (existingDoc == null
384
392
|| doc .getVersion ().compareTo (existingDoc .getVersion ()) > 0
385
393
|| (doc .getVersion ().compareTo (existingDoc .getVersion ()) == 0
386
394
&& existingDoc .hasPendingWrites ())) {
395
+ // TODO(index-free): Comment in this assert when we enable Index-Free queries
396
+ // hardAssert(!SnapshotVersion.NONE.equals(remoteEvent.getSnapshotVersion()), "Cannot
397
+ // add a document when the remote version is zero");
387
398
remoteDocuments .add (doc , remoteEvent .getSnapshotVersion ());
388
399
changedDocs .put (key , doc );
389
- } else if (doc instanceof NoDocument && doc .getVersion ().equals (SnapshotVersion .NONE )) {
390
- // NoDocuments with SnapshotVersion.MIN are used in manufactured events (e.g. in the
391
- // case of a limbo document resolution failing). We remove these documents from cache
392
- // since we lost access.
393
- remoteDocuments .remove (doc .getKey ());
394
- changedDocs .put (key , doc );
395
400
} else {
396
401
Logger .debug (
397
402
"LocalStore" ,
0 commit comments