Skip to content

Commit 8542958

Browse files
Backport LocalStoreTest changes
1 parent 5e06078 commit 8542958

15 files changed

+408
-385
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.firebase.firestore.util.Assert.hardAssert;
2020

2121
import androidx.annotation.Nullable;
22+
import androidx.annotation.VisibleForTesting;
2223
import com.google.firebase.database.collection.ImmutableSortedMap;
2324
import com.google.firebase.firestore.core.Query;
2425
import com.google.firebase.firestore.model.Document;
@@ -55,6 +56,21 @@ class LocalDocumentsView {
5556
this.indexManager = indexManager;
5657
}
5758

59+
@VisibleForTesting
60+
RemoteDocumentCache getRemoteDocumentCache() {
61+
return remoteDocumentCache;
62+
}
63+
64+
@VisibleForTesting
65+
MutationQueue getMutationQueue() {
66+
return mutationQueue;
67+
}
68+
69+
@VisibleForTesting
70+
IndexManager getIndexManager() {
71+
return indexManager;
72+
}
73+
5874
/**
5975
* Returns the the local view of the document identified by {@code key}.
6076
*

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ final class MemoryMutationQueue implements MutationQueue {
6969
private ByteString lastStreamToken;
7070

7171
private final MemoryPersistence persistence;
72-
private final StatsCollector statsCollector;
7372

74-
MemoryMutationQueue(MemoryPersistence persistence, StatsCollector statsCollector) {
73+
MemoryMutationQueue(MemoryPersistence persistence) {
7574
this.persistence = persistence;
76-
this.statsCollector = statsCollector;
7775
queue = new ArrayList<>();
7876

7977
batchesByDocumentKey = new ImmutableSortedSet<>(emptyList(), DocumentReference.BY_KEY);
@@ -156,16 +154,12 @@ public MutationBatch addMutationBatch(
156154
.addToCollectionParentIndex(mutation.getKey().getPath().popLast());
157155
}
158156

159-
statsCollector.recordRowsWritten(STATS_TAG, 1);
160-
161157
return batch;
162158
}
163159

164160
@Nullable
165161
@Override
166162
public MutationBatch lookupMutationBatch(int batchId) {
167-
statsCollector.recordRowsRead(STATS_TAG, 1);
168-
169163
int index = indexOfBatchId(batchId);
170164
if (index < 0 || index >= queue.size()) {
171165
return null;
@@ -214,8 +208,6 @@ public List<MutationBatch> getAllMutationBatchesAffectingDocumentKey(DocumentKey
214208
result.add(batch);
215209
}
216210

217-
statsCollector.recordRowsRead(STATS_TAG, result.size());
218-
219211
return result;
220212
}
221213

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,30 @@ public final class MemoryPersistence extends Persistence {
3535
private final MemoryIndexManager indexManager;
3636
private final MemoryQueryCache queryCache;
3737
private final MemoryRemoteDocumentCache remoteDocumentCache;
38-
private final StatsCollector statsCollector;
3938
private ReferenceDelegate referenceDelegate;
4039

4140
private boolean started;
4241

4342
public static MemoryPersistence createEagerGcMemoryPersistence() {
44-
return createEagerGcMemoryPersistence(StatsCollector.NO_OP_STATS_COLLECTOR);
45-
}
46-
47-
public static MemoryPersistence createEagerGcMemoryPersistence(StatsCollector statsCollector) {
48-
MemoryPersistence persistence = new MemoryPersistence(statsCollector);
43+
MemoryPersistence persistence = new MemoryPersistence();
4944
persistence.setReferenceDelegate(new MemoryEagerReferenceDelegate(persistence));
5045
return persistence;
5146
}
5247

5348
public static MemoryPersistence createLruGcMemoryPersistence(
54-
LruGarbageCollector.Params params,
55-
StatsCollector statsCollector,
56-
LocalSerializer serializer) {
57-
MemoryPersistence persistence = new MemoryPersistence(statsCollector);
49+
LruGarbageCollector.Params params, LocalSerializer serializer) {
50+
MemoryPersistence persistence = new MemoryPersistence();
5851
persistence.setReferenceDelegate(
5952
new MemoryLruReferenceDelegate(persistence, params, serializer));
6053
return persistence;
6154
}
6255

6356
/** Use static helpers to instantiate */
64-
private MemoryPersistence(StatsCollector statsCollector) {
65-
this.statsCollector = statsCollector;
57+
private MemoryPersistence() {
6658
mutationQueues = new HashMap<>();
6759
indexManager = new MemoryIndexManager();
6860
queryCache = new MemoryQueryCache(this);
69-
remoteDocumentCache = new MemoryRemoteDocumentCache(this, statsCollector);
61+
remoteDocumentCache = new MemoryRemoteDocumentCache(this);
7062
}
7163

7264
@Override
@@ -101,7 +93,7 @@ private void setReferenceDelegate(ReferenceDelegate delegate) {
10193
MutationQueue getMutationQueue(User user) {
10294
MemoryMutationQueue queue = mutationQueues.get(user);
10395
if (queue == null) {
104-
queue = new MemoryMutationQueue(this, statsCollector);
96+
queue = new MemoryMutationQueue(this);
10597
mutationQueues.put(user, queue);
10698
}
10799
return queue;

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ final class MemoryRemoteDocumentCache implements RemoteDocumentCache {
3838
private ImmutableSortedMap<DocumentKey, Pair<MaybeDocument, SnapshotVersion>> docs;
3939

4040
private final MemoryPersistence persistence;
41-
private StatsCollector statsCollector;
4241

43-
MemoryRemoteDocumentCache(MemoryPersistence persistence, StatsCollector statsCollector) {
42+
MemoryRemoteDocumentCache(MemoryPersistence persistence) {
4443
docs = ImmutableSortedMap.Builder.emptyMap(DocumentKey.comparator());
45-
this.statsCollector = statsCollector;
4644
this.persistence = persistence;
4745
}
4846

@@ -60,14 +58,12 @@ public void add(MaybeDocument document, SnapshotVersion readTime) {
6058

6159
@Override
6260
public void remove(DocumentKey key) {
63-
statsCollector.recordRowsDeleted(STATS_TAG, 1);
6461
docs = docs.remove(key);
6562
}
6663

6764
@Nullable
6865
@Override
6966
public MaybeDocument get(DocumentKey key) {
70-
statsCollector.recordRowsRead(STATS_TAG, 1);
7167
Pair<MaybeDocument, SnapshotVersion> entry = docs.get(key);
7268
return entry != null ? entry.first : null;
7369
}
@@ -82,7 +78,6 @@ public Map<DocumentKey, MaybeDocument> getAll(Iterable<DocumentKey> keys) {
8278
result.put(key, get(key));
8379
}
8480

85-
statsCollector.recordRowsRead(STATS_TAG, result.size());
8681
return result;
8782
}
8883

@@ -101,13 +96,9 @@ public ImmutableSortedMap<DocumentKey, Document> getAllDocumentsMatchingQuery(
10196
Iterator<Map.Entry<DocumentKey, Pair<MaybeDocument, SnapshotVersion>>> iterator =
10297
docs.iteratorFrom(prefix);
10398

104-
int rowsRead = 0;
105-
10699
while (iterator.hasNext()) {
107100
Map.Entry<DocumentKey, Pair<MaybeDocument, SnapshotVersion>> entry = iterator.next();
108101

109-
++rowsRead;
110-
111102
DocumentKey key = entry.getKey();
112103
if (!queryPath.isPrefixOf(key.getPath())) {
113104
break;
@@ -129,8 +120,6 @@ public ImmutableSortedMap<DocumentKey, Document> getAllDocumentsMatchingQuery(
129120
}
130121
}
131122

132-
statsCollector.recordRowsRead(STATS_TAG, rowsRead);
133-
134123
return result;
135124
}
136125

0 commit comments

Comments
 (0)