Skip to content

Commit 7b4c377

Browse files
Remove no longer needed MutationBatch methods
1 parent 58969cb commit 7b4c377

File tree

5 files changed

+5
-154
lines changed

5 files changed

+5
-154
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> rejectBatch(int batchId) {
229229
MutationBatch toReject = mutationQueue.lookupMutationBatch(batchId);
230230
hardAssert(toReject != null, "Attempt to reject nonexistent batch!");
231231

232-
int lastAcked = mutationQueue.getHighestAcknowledgedBatchId();
233-
hardAssert(batchId > lastAcked, "Acknowledged batches can't be rejected.");
234-
235232
mutationQueue.removeMutationBatch(toReject);
236233
mutationQueue.performConsistencyCheck();
237234
return localDocuments.getDocuments(toReject.getKeys());

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ public int getNextBatchId() {
111111
return nextBatchId;
112112
}
113113

114-
@Override
115-
public int getHighestAcknowledgedBatchId() {
116-
return highestAcknowledgedBatchId;
117-
}
118-
119114
@Override
120115
public void acknowledgeBatch(MutationBatch batch, ByteString streamToken) {
121116
int batchId = batch.getBatchId();
@@ -216,23 +211,6 @@ public List<MutationBatch> getAllMutationBatches() {
216211
return getAllLiveMutationBatchesBeforeIndex(queue.size());
217212
}
218213

219-
@Override
220-
public List<MutationBatch> getAllMutationBatchesThroughBatchId(int batchId) {
221-
int count = queue.size();
222-
223-
int endIndex = indexOfBatchId(batchId);
224-
if (endIndex < 0) {
225-
endIndex = 0;
226-
} else if (endIndex >= count) {
227-
endIndex = count;
228-
} else {
229-
// The endIndex is in the queue so increment to pull everything in the queue including it.
230-
endIndex += 1;
231-
}
232-
233-
return getAllLiveMutationBatchesBeforeIndex(endIndex);
234-
}
235-
236214
@Override
237215
public List<MutationBatch> getAllMutationBatchesAffectingDocumentKey(DocumentKey documentKey) {
238216
DocumentReference start = new DocumentReference(documentKey, 0);

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ interface MutationQueue {
4747
*/
4848
int getNextBatchId();
4949

50-
/**
51-
* Returns the highest batchId that has been acknowledged. If no batches have been acknowledged or
52-
* if there are no batches in the queue this can return {@link MutationBatch#UNKNOWN}.
53-
*/
54-
int getHighestAcknowledgedBatchId();
55-
5650
/** Acknowledges the given batch. */
5751
void acknowledgeBatch(MutationBatch batch, ByteString streamToken);
5852

@@ -85,17 +79,6 @@ interface MutationQueue {
8579
// cheaply, we should replace this.
8680
List<MutationBatch> getAllMutationBatches();
8781

88-
/**
89-
* Finds all mutations with a batchId less than or equal to the given batchId.
90-
*
91-
* <p>Generally the caller should be asking for the next unacknowledged batchId and the number of
92-
* acknowledged batches should be very small when things are functioning well.
93-
*
94-
* @param batchId The batch to search through.
95-
* @return an List containing all batches with matching batchIds.
96-
*/
97-
List<MutationBatch> getAllMutationBatchesThroughBatchId(int batchId);
98-
9982
/**
10083
* Finds all mutation batches that could @em possibly affect the given document key. Not all
10184
* mutations in a batch will necessarily affect the document key, so when looping through the

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ public int getNextBatchId() {
164164
return nextBatchId;
165165
}
166166

167-
@Override
168-
public int getHighestAcknowledgedBatchId() {
169-
return lastAcknowledgedBatchId;
170-
}
171-
172167
@Override
173168
public void acknowledgeBatch(MutationBatch batch, ByteString streamToken) {
174169
int batchId = batch.getBatchId();
@@ -267,17 +262,6 @@ public List<MutationBatch> getAllMutationBatches() {
267262
return result;
268263
}
269264

270-
@Override
271-
public List<MutationBatch> getAllMutationBatchesThroughBatchId(int batchId) {
272-
List<MutationBatch> result = new ArrayList<>();
273-
db.query(
274-
"SELECT mutations FROM mutations "
275-
+ "WHERE uid = ? AND batch_id <= ? ORDER BY batch_id ASC")
276-
.binding(uid, batchId)
277-
.forEach(row -> result.add(decodeMutationBatch(row.getBlob(0))));
278-
return result;
279-
}
280-
281265
@Override
282266
public List<MutationBatch> getAllMutationBatchesAffectingDocumentKey(DocumentKey documentKey) {
283267
String path = EncodedPath.encode(documentKey.getPath());

firebase-firestore/src/test/java/com/google/firebase/firestore/local/MutationQueueTestCase.java

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import static com.google.firebase.firestore.testutil.TestUtil.streamToken;
2424
import static java.util.Arrays.asList;
2525
import static java.util.Collections.emptyList;
26-
import static org.hamcrest.Matchers.greaterThan;
27-
import static org.hamcrest.Matchers.lessThan;
2826
import static org.junit.Assert.assertEquals;
2927
import static org.junit.Assert.assertFalse;
3028
import static org.junit.Assert.assertNotNull;
@@ -103,38 +101,6 @@ public void testCountBatches() {
103101
assertTrue(mutationQueue.isEmpty());
104102
}
105103

106-
@Test
107-
public void testAcknowledgeBatchId() {
108-
// Initial state of an empty queue
109-
assertEquals(MutationBatch.UNKNOWN, mutationQueue.getHighestAcknowledgedBatchId());
110-
111-
// Adding mutation batches should not change the highest acked batchId.
112-
MutationBatch batch1 = addMutationBatch();
113-
MutationBatch batch2 = addMutationBatch();
114-
MutationBatch batch3 = addMutationBatch();
115-
assertThat(batch1.getBatchId(), greaterThan(MutationBatch.UNKNOWN));
116-
assertThat(batch2.getBatchId(), greaterThan(batch1.getBatchId()));
117-
assertThat(batch3.getBatchId(), greaterThan(batch2.getBatchId()));
118-
119-
assertEquals(MutationBatch.UNKNOWN, mutationQueue.getHighestAcknowledgedBatchId());
120-
121-
acknowledgeBatch(batch1);
122-
assertEquals(batch1.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
123-
124-
acknowledgeBatch(batch2);
125-
assertEquals(batch2.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
126-
127-
removeMutationBatches(batch1);
128-
assertEquals(batch2.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
129-
130-
removeMutationBatches(batch2);
131-
assertEquals(batch2.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
132-
133-
// Batch 3 never acknowledged.
134-
removeMutationBatches(batch3);
135-
assertEquals(batch2.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
136-
}
137-
138104
@Test
139105
public void testAcknowledgeThenRemove() {
140106
MutationBatch batch1 = addMutationBatch();
@@ -147,44 +113,6 @@ public void testAcknowledgeThenRemove() {
147113
});
148114

149115
assertEquals(0, batchCount());
150-
assertEquals(batch1.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
151-
}
152-
153-
@Test
154-
public void testHighestAcknowledgedBatchIdNeverExceedsNextBatchId() {
155-
MutationBatch batch1 = addMutationBatch();
156-
MutationBatch batch2 = addMutationBatch();
157-
acknowledgeBatch(batch1);
158-
acknowledgeBatch(batch2);
159-
assertEquals(batch2.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
160-
161-
removeMutationBatches(batch1, batch2);
162-
assertEquals(batch2.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
163-
164-
// Restart the queue so that nextBatchId will be reset.
165-
mutationQueue = persistence.getMutationQueue(User.UNAUTHENTICATED);
166-
mutationQueue.start();
167-
168-
persistence.runTransaction("Start mutationQueue", () -> mutationQueue.start());
169-
170-
// Verify that on restart with an empty queue, nextBatchId falls to a lower value.
171-
assertThat(mutationQueue.getNextBatchId(), lessThan(batch2.getBatchId()));
172-
173-
// As a result highestAcknowledgedBatchId must also reset lower.
174-
assertEquals(MutationBatch.UNKNOWN, mutationQueue.getHighestAcknowledgedBatchId());
175-
176-
// The mutation queue will reset the next batchId after all mutations are removed so adding
177-
// another mutation will cause a collision.
178-
MutationBatch newBatch = addMutationBatch();
179-
assertEquals(batch1.getBatchId(), newBatch.getBatchId());
180-
181-
// Restart the queue with one unacknowledged batch in it.
182-
persistence.runTransaction("Start mutationQueue", () -> mutationQueue.start());
183-
184-
assertEquals(newBatch.getBatchId() + 1, mutationQueue.getNextBatchId());
185-
186-
// highestAcknowledgedBatchId must still be MutationBatch.UNKNOWN.
187-
assertEquals(MutationBatch.UNKNOWN, mutationQueue.getHighestAcknowledgedBatchId());
188116
}
189117

190118
@Test
@@ -265,24 +193,6 @@ public void testNextMutationBatchAfterBatchIdSkipsAcknowledgedBatches() {
265193
mutationQueue.getNextMutationBatchAfterBatchId(batches.get(1).getBatchId()));
266194
}
267195

268-
@Test
269-
public void testAllMutationBatchesThroughBatchID() {
270-
List<MutationBatch> batches = createBatches(10);
271-
makeHoles(asList(2, 6, 7), batches);
272-
273-
List<MutationBatch> found;
274-
List<MutationBatch> expected;
275-
276-
found = mutationQueue.getAllMutationBatchesThroughBatchId(batches.get(0).getBatchId() - 1);
277-
assertEquals(emptyList(), found);
278-
279-
for (int i = 0; i < batches.size(); i++) {
280-
found = mutationQueue.getAllMutationBatchesThroughBatchId(batches.get(i).getBatchId());
281-
expected = batches.subList(0, i + 1);
282-
assertEquals(expected, found);
283-
}
284-
}
285-
286196
@Test
287197
public void testAllMutationBatchesAffectingDocumentKey() {
288198
List<Mutation> mutations =
@@ -442,7 +352,7 @@ public void testRemoveMutationBatches() {
442352

443353
List<MutationBatch> found;
444354

445-
found = mutationQueue.getAllMutationBatchesThroughBatchId(last.getBatchId());
355+
found = mutationQueue.getAllMutationBatches();
446356
assertEquals(batches, found);
447357
assertEquals(9, found.size());
448358

@@ -452,14 +362,14 @@ public void testRemoveMutationBatches() {
452362
batches.remove(batches.get(0));
453363
assertEquals(6, batchCount());
454364

455-
found = mutationQueue.getAllMutationBatchesThroughBatchId(last.getBatchId());
365+
found = mutationQueue.getAllMutationBatches();
456366
assertEquals(batches, found);
457367
assertEquals(6, found.size());
458368

459369
removeMutationBatches(batches.remove(batches.size() - 1));
460370
assertEquals(5, batchCount());
461371

462-
found = mutationQueue.getAllMutationBatchesThroughBatchId(last.getBatchId());
372+
found = mutationQueue.getAllMutationBatches();
463373
assertEquals(batches, found);
464374
assertEquals(5, found.size());
465375

@@ -469,12 +379,12 @@ public void testRemoveMutationBatches() {
469379
removeMutationBatches(batches.remove(1));
470380
assertEquals(3, batchCount());
471381

472-
found = mutationQueue.getAllMutationBatchesThroughBatchId(last.getBatchId());
382+
found = mutationQueue.getAllMutationBatches();
473383
assertEquals(batches, found);
474384
assertEquals(3, found.size());
475385

476386
removeMutationBatches(batches.toArray(new MutationBatch[0]));
477-
found = mutationQueue.getAllMutationBatchesThroughBatchId(last.getBatchId());
387+
found = mutationQueue.getAllMutationBatches();
478388
assertEquals(emptyList(), found);
479389
assertEquals(0, found.size());
480390
assertTrue(mutationQueue.isEmpty());
@@ -496,7 +406,6 @@ public void testStreamToken() {
496406
persistence.runTransaction(
497407
"acknowledgeBatchId", () -> mutationQueue.acknowledgeBatch(batch1, streamToken2));
498408

499-
assertEquals(batch1.getBatchId(), mutationQueue.getHighestAcknowledgedBatchId());
500409
assertEquals(streamToken2, mutationQueue.getLastStreamToken());
501410
}
502411

0 commit comments

Comments
 (0)