Skip to content

Commit d09d166

Browse files
Rename sync -> consistent
1 parent dc4d4cd commit d09d166

File tree

24 files changed

+125
-81
lines changed

24 files changed

+125
-81
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/core/QueryListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void onViewSnapshot(ViewSnapshot newSnapshot) {
8080
documentChanges,
8181
newSnapshot.isFromCache(),
8282
newSnapshot.getMutatedKeys(),
83-
newSnapshot.isSynced(),
83+
newSnapshot.isConsistentWithBackend(),
8484
newSnapshot.didSyncStateChange(),
8585
/* excludesMetadataChanges= */ true);
8686
}
@@ -159,7 +159,7 @@ private void raiseInitialEvent(ViewSnapshot snapshot) {
159159
snapshot.getDocuments(),
160160
snapshot.getMutatedKeys(),
161161
snapshot.isFromCache(),
162-
snapshot.isSynced(),
162+
snapshot.isConsistentWithBackend(),
163163
snapshot.excludesMetadataChanges());
164164
raisedInitialEvent = true;
165165
listener.onEvent(snapshot, null);

firebase-firestore/src/main/java/com/google/firebase/firestore/core/View.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ public ViewChange applyChanges(DocumentChanges docChanges, TargetChange targetCh
296296
});
297297
applyTargetChange(targetChange);
298298
List<LimboDocumentChange> limboDocumentChanges = updateLimboDocuments();
299-
boolean synced = limboDocuments.size() == 0 && current;
299+
boolean consistentWithBackend = limboDocuments.size() == 0;
300+
boolean synced = consistentWithBackend && current;
300301
SyncState newSyncState = synced ? SyncState.SYNCED : SyncState.LOCAL;
301302
boolean syncStatedChanged = newSyncState != syncState;
302303
syncState = newSyncState;
@@ -311,7 +312,7 @@ public ViewChange applyChanges(DocumentChanges docChanges, TargetChange targetCh
311312
viewChanges,
312313
fromCache,
313314
docChanges.mutatedKeys,
314-
synced,
315+
consistentWithBackend,
315316
syncStatedChanged,
316317
/* excludesMetadataChanges= */ false);
317318
}

firebase-firestore/src/main/java/com/google/firebase/firestore/core/ViewSnapshot.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public enum SyncState {
3737
private final List<DocumentViewChange> changes;
3838
private final boolean isFromCache;
3939
private final ImmutableSortedSet<DocumentKey> mutatedKeys;
40-
private final boolean synced;
40+
private final boolean consistentWithBackend;
4141
private final boolean didSyncStateChange;
4242
private boolean excludesMetadataChanges;
4343

@@ -48,7 +48,7 @@ public ViewSnapshot(
4848
List<DocumentViewChange> changes,
4949
boolean isFromCache,
5050
ImmutableSortedSet<DocumentKey> mutatedKeys,
51-
boolean synced,
51+
boolean consistentWithBackend,
5252
boolean didSyncStateChange,
5353
boolean excludesMetadataChanges) {
5454
this.query = query;
@@ -57,7 +57,7 @@ public ViewSnapshot(
5757
this.changes = changes;
5858
this.isFromCache = isFromCache;
5959
this.mutatedKeys = mutatedKeys;
60-
this.synced = synced;
60+
this.consistentWithBackend = consistentWithBackend;
6161
this.didSyncStateChange = didSyncStateChange;
6262
this.excludesMetadataChanges = excludesMetadataChanges;
6363
}
@@ -68,7 +68,7 @@ public static ViewSnapshot fromInitialDocuments(
6868
DocumentSet documents,
6969
ImmutableSortedSet<DocumentKey> mutatedKeys,
7070
boolean fromCache,
71-
boolean synced,
71+
boolean consistentWithBackend,
7272
boolean excludesMetadataChanges) {
7373
List<DocumentViewChange> viewChanges = new ArrayList<>();
7474
for (Document doc : documents) {
@@ -81,7 +81,7 @@ public static ViewSnapshot fromInitialDocuments(
8181
viewChanges,
8282
fromCache,
8383
mutatedKeys,
84-
synced,
84+
consistentWithBackend,
8585
/* didSyncStateChange= */ true,
8686
excludesMetadataChanges);
8787
}
@@ -91,11 +91,11 @@ public Query getQuery() {
9191
}
9292

9393
/**
94-
* Returns whether the view was synced with the backend at the time the snapshot was raised. A
95-
* synced view is marked CURRENT and contains no Limbo documents.
94+
* Returns whether the documents in the view matched the backend's result set at the time the
95+
* snapshot was raised. A synced view contains no Limbo documents.
9696
*/
97-
public boolean isSynced() {
98-
return synced;
97+
public boolean isConsistentWithBackend() {
98+
return consistentWithBackend;
9999
}
100100

101101
public DocumentSet getDocuments() {
@@ -144,7 +144,7 @@ public final boolean equals(Object o) {
144144
if (isFromCache != that.isFromCache) {
145145
return false;
146146
}
147-
if (synced != that.synced) {
147+
if (consistentWithBackend != that.consistentWithBackend) {
148148
return false;
149149
}
150150
if (didSyncStateChange != that.didSyncStateChange) {
@@ -176,7 +176,7 @@ public int hashCode() {
176176
result = 31 * result + changes.hashCode();
177177
result = 31 * result + mutatedKeys.hashCode();
178178
result = 31 * result + (isFromCache ? 1 : 0);
179-
result = 31 * result + (synced ? 1 : 0);
179+
result = 31 * result + (consistentWithBackend ? 1 : 0);
180180
result = 31 * result + (didSyncStateChange ? 1 : 0);
181181
result = 31 * result + (excludesMetadataChanges ? 1 : 0);
182182
return result;
@@ -196,8 +196,8 @@ public String toString() {
196196
+ isFromCache
197197
+ ", mutatedKeys="
198198
+ mutatedKeys.size()
199-
+ ", synced="
200-
+ synced
199+
+ ", consistentWithBackend="
200+
+ consistentWithBackend
201201
+ ", didSyncStateChange="
202202
+ didSyncStateChange
203203
+ ", excludesMetadataChanges="

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalSerializer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ com.google.firebase.firestore.proto.Target encodeQueryData(QueryData queryData)
205205
result
206206
.setTargetId(queryData.getTargetId())
207207
.setLastListenSequenceNumber(queryData.getSequenceNumber())
208-
.setSynced(queryData.isSynced())
208+
.setConsistent(queryData.isConsistentWithLocalViews())
209209
.setSnapshotVersion(rpcSerializer.encodeVersion(queryData.getSnapshotVersion()))
210210
.setResumeToken(queryData.getResumeToken());
211211

@@ -224,7 +224,7 @@ QueryData decodeQueryData(com.google.firebase.firestore.proto.Target target) {
224224
SnapshotVersion version = rpcSerializer.decodeVersion(target.getSnapshotVersion());
225225
ByteString resumeToken = target.getResumeToken();
226226
long sequenceNumber = target.getLastListenSequenceNumber();
227-
boolean synced = target.getSynced();
227+
boolean consistent = target.getConsistent();
228228

229229
Query query;
230230
switch (target.getTargetTypeCase()) {
@@ -241,6 +241,6 @@ QueryData decodeQueryData(com.google.firebase.firestore.proto.Target target) {
241241
}
242242

243243
return new QueryData(
244-
query, targetId, sequenceNumber, synced, QueryPurpose.LISTEN, version, resumeToken);
244+
query, targetId, sequenceNumber, consistent, QueryPurpose.LISTEN, version, resumeToken);
245245
}
246246
}

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyRemoteEvent(RemoteEve
363363
remoteEvent.getSnapshotVersion(),
364364
resumeToken,
365365
sequenceNumber,
366-
oldQueryData.isSynced());
366+
/* consistentWithLocalViews */ false);
367367
targetIds.put(boxedTargetId, queryData);
368368

369369
if (shouldPersistQueryData(oldQueryData, queryData, change)) {
@@ -491,7 +491,7 @@ public void notifyLocalViewChanges(List<LocalViewChanges> viewChanges) {
491491
queryData.getSnapshotVersion(),
492492
queryData.getResumeToken(),
493493
queryData.getSequenceNumber(),
494-
viewChange.isSynced());
494+
viewChange.isConsistentWithBackend());
495495
targetIds.put(targetId, updatedQueryData);
496496
}
497497
});
@@ -573,7 +573,8 @@ public void releaseQuery(Query query) {
573573
// conditions and rationale) we need to persist the token now because there will no
574574
// longer be an in-memory version to fall back on.
575575
needsUpdate = true;
576-
} else if (cachedQueryData.isSynced() != queryData.isSynced()) {
576+
} else if (cachedQueryData.isConsistentWithLocalViews()
577+
!= queryData.isConsistentWithLocalViews()) {
577578
needsUpdate = true;
578579
}
579580

@@ -608,7 +609,7 @@ public void markNeedsRefill(int targetId) {
608609
queryData.getSnapshotVersion(),
609610
queryData.getResumeToken(),
610611
queryData.getSequenceNumber(),
611-
/* synced= */ false);
612+
/* consistentWithLocalViews= */ false);
612613
targetIds.put(targetId, updatedQueryData);
613614
}
614615

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalViewChanges.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,23 @@ public static LocalViewChanges fromViewSnapshot(int targetId, ViewSnapshot snaps
4949
}
5050
}
5151

52-
return new LocalViewChanges(targetId, snapshot.isSynced(), addedKeys, removedKeys);
52+
return new LocalViewChanges(
53+
targetId, snapshot.isConsistentWithBackend(), addedKeys, removedKeys);
5354
}
5455

5556
private final int targetId;
56-
private final boolean synced;
57+
private final boolean consistentWithBackend;
5758

5859
private final ImmutableSortedSet<DocumentKey> added;
5960
private final ImmutableSortedSet<DocumentKey> removed;
6061

6162
public LocalViewChanges(
6263
int targetId,
63-
boolean synced,
64+
boolean consistentWithBackend,
6465
ImmutableSortedSet<DocumentKey> added,
6566
ImmutableSortedSet<DocumentKey> removed) {
6667
this.targetId = targetId;
67-
this.synced = synced;
68+
this.consistentWithBackend = consistentWithBackend;
6869
this.added = added;
6970
this.removed = removed;
7071
}
@@ -74,8 +75,8 @@ public int getTargetId() {
7475
}
7576

7677
/** Returns whether the local query view is in sync with the backend. * */
77-
public boolean isSynced() {
78-
return synced;
78+
public boolean isConsistentWithBackend() {
79+
return consistentWithBackend;
7980
}
8081

8182
public ImmutableSortedSet<DocumentKey> getAdded() {

firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryLruReferenceDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void removeTarget(QueryData queryData) {
140140
queryData.getSnapshotVersion(),
141141
queryData.getResumeToken(),
142142
getCurrentSequenceNumber(),
143-
queryData.isSynced());
143+
queryData.isConsistentWithLocalViews());
144144
persistence.getQueryCache().updateQueryData(updated);
145145
}
146146

firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryData.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public final class QueryData {
2626
private final Query query;
2727
private final int targetId;
2828
private final long sequenceNumber;
29-
private final boolean synced;
29+
private final boolean consistentWithLocalViews;
3030
private final QueryPurpose purpose;
3131
private final SnapshotVersion snapshotVersion;
3232
private final ByteString resumeToken;
@@ -38,7 +38,8 @@ public final class QueryData {
3838
* @param targetId The target to which the query corresponds, assigned by the LocalStore for user
3939
* queries or the SyncEngine for limbo queries.
4040
* @param sequenceNumber The sequence number, denoting the last time this query was used.
41-
* @param synced Whether the query's local state is in sync with the backend.
41+
* @param consistentWithLocalViews Whether the query's local result set is in consistent with the
42+
* backend's.
4243
* @param purpose The purpose of the query.
4344
* @param snapshotVersion The latest snapshot version seen for this target.
4445
* @param resumeToken An opaque, server-assigned token that allows watching a query to be resumed
@@ -50,14 +51,14 @@ public QueryData(
5051
Query query,
5152
int targetId,
5253
long sequenceNumber,
53-
boolean synced,
54+
boolean consistentWithLocalViews,
5455
QueryPurpose purpose,
5556
SnapshotVersion snapshotVersion,
5657
ByteString resumeToken) {
5758
this.query = checkNotNull(query);
5859
this.targetId = targetId;
5960
this.sequenceNumber = sequenceNumber;
60-
this.synced = synced;
61+
this.consistentWithLocalViews = consistentWithLocalViews;
6162
this.purpose = purpose;
6263
this.snapshotVersion = checkNotNull(snapshotVersion);
6364
this.resumeToken = checkNotNull(resumeToken);
@@ -69,7 +70,7 @@ public QueryData(Query query, int targetId, long sequenceNumber, QueryPurpose pu
6970
query,
7071
targetId,
7172
sequenceNumber,
72-
/* synced= */ false,
73+
/* consistentWithLocalViews= */ false,
7374
purpose,
7475
SnapshotVersion.NONE,
7576
WatchStream.EMPTY_RESUME_TOKEN);
@@ -99,9 +100,9 @@ public ByteString getResumeToken() {
99100
return resumeToken;
100101
}
101102

102-
/** Whether the query's local state is in sync with the backend. */
103-
public boolean isSynced() {
104-
return synced;
103+
/** Whether the query's local result set is consistent with the backend. */
104+
public boolean isConsistentWithLocalViews() {
105+
return consistentWithLocalViews;
105106
}
106107

107108
@Override
@@ -117,7 +118,7 @@ public boolean equals(Object o) {
117118
return query.equals(queryData.query)
118119
&& targetId == queryData.targetId
119120
&& sequenceNumber == queryData.sequenceNumber
120-
&& synced == queryData.synced
121+
&& consistentWithLocalViews == queryData.consistentWithLocalViews
121122
&& purpose.equals(queryData.purpose)
122123
&& snapshotVersion.equals(queryData.snapshotVersion)
123124
&& resumeToken.equals(queryData.resumeToken);
@@ -128,7 +129,7 @@ public int hashCode() {
128129
int result = query.hashCode();
129130
result = 31 * result + targetId;
130131
result = 31 * result + (int) sequenceNumber;
131-
result = 31 * result + (synced ? 1 : 0);
132+
result = 31 * result + (consistentWithLocalViews ? 1 : 0);
132133
result = 31 * result + purpose.hashCode();
133134
result = 31 * result + snapshotVersion.hashCode();
134135
result = 31 * result + resumeToken.hashCode();
@@ -144,8 +145,8 @@ public String toString() {
144145
+ targetId
145146
+ ", sequenceNumber="
146147
+ sequenceNumber
147-
+ ", isSynced="
148-
+ synced
148+
+ ", consistentWithLocalViews="
149+
+ consistentWithLocalViews
149150
+ ", purpose="
150151
+ purpose
151152
+ ", snapshotVersion="
@@ -163,8 +164,14 @@ public QueryData copy(
163164
SnapshotVersion snapshotVersion,
164165
ByteString resumeToken,
165166
long sequenceNumber,
166-
boolean synced) {
167+
boolean consistentWithLocalViews) {
167168
return new QueryData(
168-
query, targetId, sequenceNumber, synced, purpose, snapshotVersion, resumeToken);
169+
query,
170+
targetId,
171+
sequenceNumber,
172+
consistentWithLocalViews,
173+
purpose,
174+
snapshotVersion,
175+
resumeToken);
169176
}
170177
}

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteLruReferenceDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void removeTarget(QueryData queryData) {
172172
queryData.getSnapshotVersion(),
173173
queryData.getResumeToken(),
174174
getCurrentSequenceNumber(),
175-
queryData.isSynced());
175+
queryData.isConsistentWithLocalViews());
176176
persistence.getQueryCache().updateQueryData(updated);
177177
}
178178

firebase-firestore/src/main/java/com/google/firebase/firestore/remote/RemoteStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ private void raiseWatchSnapshot(SnapshotVersion snapshotVersion) {
509509
snapshotVersion,
510510
targetChange.getResumeToken(),
511511
queryData.getSequenceNumber(),
512-
queryData.isSynced()));
512+
queryData.isConsistentWithLocalViews()));
513513
}
514514
}
515515
}
@@ -527,7 +527,7 @@ private void raiseWatchSnapshot(SnapshotVersion snapshotVersion) {
527527
queryData.getSnapshotVersion(),
528528
ByteString.EMPTY,
529529
queryData.getSequenceNumber(),
530-
queryData.isSynced()));
530+
queryData.isConsistentWithLocalViews()));
531531

532532
// Cause a hard reset by unwatching and rewatching immediately, but deliberately don't send
533533
// a resume token so that we get a full update.

firebase-firestore/src/proto/google/firebase/firestore/proto/target.proto

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ message Target {
7979
google.firestore.v1.Target.DocumentsTarget documents = 6;
8080
}
8181

82-
// Whether the locally cached query data and the query's document are in sync
83-
// with the backend. A query is synced if we have received CURRENT, there are
84-
// no Limbo documents and the query does not need to be refilled from cache.
85-
bool synced = 7;
82+
// Whether the set of locally cached query results is consistent with the
83+
// backend's results. A query state is consistent if the corresponding views
84+
// contain no Limbo documents and the query does not need to be refilled from
85+
// cache.
86+
bool consistent = 7;
8687
}
8788

8889
// Global state tracked across all Targets, tracked separately to avoid the

firebase-firestore/src/roboUtil/java/com/google/firebase/firestore/TestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static QuerySnapshot querySnapshot(
129129
documentChanges,
130130
isFromCache,
131131
mutatedKeys,
132-
/* synced= */ true,
132+
/* consistentWithBackend= */ true,
133133
/* didSyncStateChange= */ true,
134134
/* excludesMetadataChanges= */ false);
135135
return new QuerySnapshot(query(path), viewSnapshot, FIRESTORE);

0 commit comments

Comments
 (0)