diff options
author | Michael Lehenbauer <mikelehen@gmail.com> | 2018-03-12 11:53:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-12 11:53:26 -0700 |
commit | f122cf7ce802972bd2fea45acac3deae2affcafa (patch) | |
tree | 58e996c86a48528fc5c96c6a535295adcfac723e /Firestore/Source/Local/FSTLevelDBMutationQueue.mm | |
parent | 7522314812b934884f8877d36a66a4686f424a8f (diff) |
Fix MutationQueue issue resulting in re-sending acknowledged writes. (#909)
Port of: https://github.com/firebase/firebase-js-sdk/pull/559
Should address #772 once released.
getNextMutationBatchAfterBatchId() was not respecting
highestAcknowledgedBatchId and therefore we were resending writes after the
network was disabled / re-enabled.
Diffstat (limited to 'Firestore/Source/Local/FSTLevelDBMutationQueue.mm')
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBMutationQueue.mm | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm index 575e98d..d7b5eca 100644 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm +++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm @@ -315,7 +315,12 @@ static ReadOptions StandardReadOptions() { } - (nullable FSTMutationBatch *)nextMutationBatchAfterBatchID:(FSTBatchID)batchID { - std::string key = [self mutationKeyForBatchID:batchID + 1]; + // All batches with batchID <= self.metadata.lastAcknowledgedBatchId have been acknowledged so + // the first unacknowledged batch after batchID will have a batchID larger than both of these + // values. + FSTBatchID nextBatchID = MAX(batchID, self.metadata.lastAcknowledgedBatchId) + 1; + + std::string key = [self mutationKeyForBatchID:nextBatchID]; std::unique_ptr<Iterator> it(_db->NewIterator(StandardReadOptions())); it->Seek(key); @@ -336,7 +341,7 @@ static ReadOptions StandardReadOptions() { return nil; } - FSTAssert(rowKey.batchID > batchID, @"Should have found mutation after %d", batchID); + FSTAssert(rowKey.batchID >= nextBatchID, @"Should have found mutation after %d", nextBatchID); return [self decodedMutationBatch:it->value()]; } |