Skip to content

Clear the lastLimboFreeSnapshot version on existence filter mismatch #3267

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 6 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -417,20 +417,24 @@ public ImmutableSortedMap<DocumentKey, Document> applyRemoteEvent(RemoteEvent re
targetCache.removeMatchingKeys(change.getRemovedDocuments(), targetId);
targetCache.addMatchingKeys(change.getAddedDocuments(), targetId);

ByteString resumeToken = change.getResumeToken();
// Update the resume token if the change includes one.
if (!resumeToken.isEmpty()) {
TargetData newTargetData =
oldTargetData
.withResumeToken(resumeToken, remoteEvent.getSnapshotVersion())
.withSequenceNumber(sequenceNumber);
queryDataByTarget.put(targetId, newTargetData);

// Update the query data if there are target changes (or if sufficient time has
// passed since the last update).
if (shouldPersistTargetData(oldTargetData, newTargetData, change)) {
targetCache.updateTargetData(newTargetData);
}
TargetData newTargetData = oldTargetData.withSequenceNumber(sequenceNumber);
if (remoteEvent.getTargetMismatches().contains(targetId)) {
newTargetData =
newTargetData
.withResumeToken(ByteString.EMPTY, SnapshotVersion.NONE)
.withLastLimboFreeSnapshotVersion(SnapshotVersion.NONE);
} else if (!change.getResumeToken().isEmpty()) {
newTargetData =
newTargetData.withResumeToken(
change.getResumeToken(), remoteEvent.getSnapshotVersion());
}

queryDataByTarget.put(targetId, newTargetData);

// Update the query data if there are target changes (or if sufficient time has passed
// since the last update).
if (shouldPersistTargetData(oldTargetData, newTargetData, change)) {
targetCache.updateTargetData(newTargetData);
}
}

Expand Down Expand Up @@ -554,10 +558,6 @@ private DocumentChangeResult populateDocumentChanges(
*/
private static boolean shouldPersistTargetData(
TargetData oldTargetData, TargetData newTargetData, TargetChange change) {
hardAssert(
!newTargetData.getResumeToken().isEmpty(),
"Attempted to persist query data with empty resume token");

// Always persist query data if we don't already have a resume token.
if (oldTargetData.getResumeToken().isEmpty()) return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private void raiseWatchSnapshot(SnapshotVersion snapshotVersion) {
}
}

// Re-establish listens for the targets that have been invalidated by existence filter
// Re-establish listens for the targets that have been invalidated by existence filter
// mismatches.
for (int targetId : remoteEvent.getTargetMismatches()) {
TargetData targetData = this.listenTargets.get(targetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,242 @@
}
]
},
"Existence filter mismatch invalidates index-free query": {
"describeName": "Existence Filters:",
"itName": "Existence filter clears resume token",
"tags": [
"durable-persistence"
],
"config": {
"numClients": 1,
"useGarbageCollection": true
},
"steps": [
{
"userListen": {
"query": {
"filters": [
],
"orderBys": [
],
"path": "collection"
},
"targetId": 2
},
"expectedState": {
"activeTargets": {
"2": {
"queries": [
{
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"resumeToken": ""
}
}
}
},
{
"watchAck": [
2
]
},
{
"watchEntity": {
"docs": [
{
"key": "collection/1",
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": false
},
"value": {
"v": 1
},
"version": 1000
},
{
"key": "collection/2",
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": false
},
"value": {
"v": 2
},
"version": 1000
}
],
"targets": [
2
]
}
},
{
"watchCurrent": [
[
2
],
"resume-token-1000"
]
},
{
"watchSnapshot": {
"targetIds": [
],
"version": 1000
},
"expectedSnapshotEvents": [
{
"added": [
{
"key": "collection/1",
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": false
},
"value": {
"v": 1
},
"version": 1000
},
{
"key": "collection/2",
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": false
},
"value": {
"v": 2
},
"version": 1000
}
],
"errorCode": 0,
"fromCache": false,
"hasPendingWrites": false,
"query": {
"filters": [
],
"orderBys": [
],
"path": "collection"
}
}
]
},
{
"watchFilter": [
[
2
],
"collection/1"
]
},
{
"watchSnapshot": {
"targetIds": [
],
"version": 2000
},
"expectedSnapshotEvents": [
{
"errorCode": 0,
"fromCache": true,
"hasPendingWrites": false,
"query": {
"filters": [
],
"orderBys": [
],
"path": "collection"
}
}
]
},
{
"restart": true,
"expectedState": {
"activeLimboDocs": [
],
"activeTargets": {
},
"enqueuedLimboDocs": [
]
}
},
{
"userListen": {
"query": {
"filters": [
],
"orderBys": [
],
"path": "collection"
},
"targetId": 2
},
"expectedSnapshotEvents": [
{
"added": [
{
"key": "collection/1",
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": false
},
"value": {
"v": 1
},
"version": 1000
},
{
"key": "collection/2",
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": false
},
"value": {
"v": 2
},
"version": 1000
}
],
"errorCode": 0,
"fromCache": true,
"hasPendingWrites": false,
"query": {
"filters": [
],
"orderBys": [
],
"path": "collection"
}
}
],
"expectedState": {
"activeTargets": {
"2": {
"queries": [
{
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"resumeToken": ""
}
}
}
}
]
},
"Existence filter mismatch triggers re-run of query": {
"describeName": "Existence Filters:",
"itName": "Existence filter mismatch triggers re-run of query",
Expand Down