aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Local/FSTLocalStore.mm
diff options
context:
space:
mode:
authorGravatar Greg Soltis <gsoltis@google.com>2018-03-26 11:57:34 -0700
committerGravatar GitHub <noreply@github.com>2018-03-26 11:57:34 -0700
commitf77ec68a8862bd03b430deff48022ffb179172b0 (patch)
treed6e39cc2ac36c1fb7433edc1372ec10a8064e593 /Firestore/Source/Local/FSTLocalStore.mm
parentacc5c456d39a1150bdb8658df60d215feff42f02 (diff)
Switch LevelDB MutationQueue and RemoteDocumentCache to use transactions (#968)
* Start work on leveldb transactions * Style * Working API. Not plumbed in yet * Move files into correct place * Wrangling file locations and associations * Tests pass * Add some comments * style * Fix copyright * Rewrite iterator internals to handle deletion-while-iterating. Also add tests for same * Switch to strings instead of slices * Style * More style fixes * Start switching writegroup over * Swap out write group tracking for transaction usage * Style * Response to feedback before updating docs * Style * Add comment * Initialize version_ * Satisfy the linter * Start switching writegroup over * Swap out write group tracking for transaction usage * Style * Checkpoint before implementing BatchDescription * Style * Initial plumbing for leveldb local parts * Add model::BatchId * Port leveldb_key.{h,cc} * Add string StartsWith * Add leveldb_key_test.cc to the project * Revert back to using leveldb::Slice for read/describe These operations universally operate on keys obtained from leveldb so it's actually unhelpful to force all the callers to make absl::string_views from them. * Everything passing * Drop unused function * Style * STart work on reads * Swap reads in queryCache to use transactions * Fix up tests of querycache * Drop commented out code * Cleanup * Style * Fix up for passing tests * style * Renaming * Style * Start work on ToString for transactions * Add ToString() method to LevelDbTransaction * Style * lint * Fix includes, drop runTransaction * current_transaction -> currentTransaction * LevelDbTransaction::NewIterator now returns a unique_ptr * Style * Revert addition of util::StartsWith * Add log line * Style * Add log line * Style * Add debug log line for commits, drop unused BatchDescription * STart work on reads * Swap reads in queryCache to use transactions * Start on remote documents * Transition mutation queue and remote documents to use transactions * Style * Make everything pass * Make everything pass * Make it compile * Style * Style * Revert name change, use DefaultReadOptions() * Style * Handle iterators returning bad statuses
Diffstat (limited to 'Firestore/Source/Local/FSTLocalStore.mm')
-rw-r--r--Firestore/Source/Local/FSTLocalStore.mm41
1 files changed, 28 insertions, 13 deletions
diff --git a/Firestore/Source/Local/FSTLocalStore.mm b/Firestore/Source/Local/FSTLocalStore.mm
index 1bcc6d0..2ea3328 100644
--- a/Firestore/Source/Local/FSTLocalStore.mm
+++ b/Firestore/Source/Local/FSTLocalStore.mm
@@ -172,7 +172,9 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTMaybeDocumentDictionary *)userDidChange:(const User &)user {
// Swap out the mutation queue, grabbing the pending mutation batches before and after.
+ FSTWriteGroup *group = [self.persistence startGroupWithAction:@"OldBatches"];
NSArray<FSTMutationBatch *> *oldBatches = [self.mutationQueue allMutationBatches];
+ [self.persistence commitGroup:group];
[self.mutationQueue shutdown];
[self.garbageCollector removeGarbageSource:self.mutationQueue];
@@ -182,6 +184,7 @@ NS_ASSUME_NONNULL_BEGIN
[self startMutationQueue];
+ group = [self.persistence startGroupWithAction:@"NewBatches"];
NSArray<FSTMutationBatch *> *newBatches = [self.mutationQueue allMutationBatches];
// Recreate our LocalDocumentsView using the new MutationQueue.
@@ -199,7 +202,9 @@ NS_ASSUME_NONNULL_BEGIN
}
// Return the set of all (potentially) changed documents as the result of the user change.
- return [self.localDocuments documentsForKeys:changedKeys];
+ FSTMaybeDocumentDictionary *result = [self.localDocuments documentsForKeys:changedKeys];
+ [self.persistence commitGroup:group];
+ return result;
}
- (FSTLocalWriteResult *)locallyWriteMutations:(NSArray<FSTMutation *> *)mutations {
@@ -208,10 +213,9 @@ NS_ASSUME_NONNULL_BEGIN
FSTMutationBatch *batch = [self.mutationQueue addMutationBatchWithWriteTime:localWriteTime
mutations:mutations
group:group];
- [self.persistence commitGroup:group];
-
FSTDocumentKeySet *keys = [batch keys];
FSTMaybeDocumentDictionary *changedDocuments = [self.localDocuments documentsForKeys:keys];
+ [self.persistence commitGroup:group];
return [FSTLocalWriteResult resultForBatchID:batch.batchID changes:changedDocuments];
}
@@ -237,10 +241,11 @@ NS_ASSUME_NONNULL_BEGIN
[remoteDocuments applyToWriteGroup:group];
}
- [self.persistence commitGroup:group];
[self.mutationQueue performConsistencyCheck];
- return [self.localDocuments documentsForKeys:affected];
+ FSTMaybeDocumentDictionary *result = [self.localDocuments documentsForKeys:affected];
+ [self.persistence commitGroup:group];
+ return result;
}
- (FSTMaybeDocumentDictionary *)rejectBatchID:(FSTBatchID)batchID {
@@ -254,10 +259,11 @@ NS_ASSUME_NONNULL_BEGIN
FSTDocumentKeySet *affected = [self removeMutationBatch:toReject group:group];
- [self.persistence commitGroup:group];
[self.mutationQueue performConsistencyCheck];
- return [self.localDocuments documentsForKeys:affected];
+ FSTMaybeDocumentDictionary *result = [self.localDocuments documentsForKeys:affected];
+ [self.persistence commitGroup:group];
+ return result;
}
- (nullable NSData *)lastStreamToken {
@@ -362,15 +368,15 @@ NS_ASSUME_NONNULL_BEGIN
[remoteDocuments applyToWriteGroup:group];
- [self.persistence commitGroup:group];
-
// Union the two key sets.
__block FSTDocumentKeySet *keysToRecalc = changedDocKeys;
[releasedWriteKeys enumerateObjectsUsingBlock:^(FSTDocumentKey *key, BOOL *stop) {
keysToRecalc = [keysToRecalc setByAddingObject:key];
}];
- return [self.localDocuments documentsForKeys:keysToRecalc];
+ FSTMaybeDocumentDictionary *result = [self.localDocuments documentsForKeys:keysToRecalc];
+ [self.persistence commitGroup:group];
+ return result;
}
- (void)notifyLocalViewChanges:(NSArray<FSTLocalViewChanges *> *)viewChanges {
@@ -387,11 +393,17 @@ NS_ASSUME_NONNULL_BEGIN
}
- (nullable FSTMutationBatch *)nextMutationBatchAfterBatchID:(FSTBatchID)batchID {
- return [self.mutationQueue nextMutationBatchAfterBatchID:batchID];
+ FSTWriteGroup *group = [self.persistence startGroupWithAction:@"nextMutationBatchAfterBatchID"];
+ FSTMutationBatch *result = [self.mutationQueue nextMutationBatchAfterBatchID:batchID];
+ [self.persistence commitGroup:group];
+ return result;
}
- (nullable FSTMaybeDocument *)readDocument:(const DocumentKey &)key {
- return [self.localDocuments documentForKey:key];
+ FSTWriteGroup *group = [self.persistence startGroupWithAction:@"ReadDocument"];
+ FSTMaybeDocument *result = [self.localDocuments documentForKey:key];
+ [self.persistence commitGroup:group];
+ return result;
}
- (FSTQueryData *)allocateQuery:(FSTQuery *)query {
@@ -447,7 +459,10 @@ NS_ASSUME_NONNULL_BEGIN
}
- (FSTDocumentDictionary *)executeQuery:(FSTQuery *)query {
- return [self.localDocuments documentsMatchingQuery:query];
+ FSTWriteGroup *group = [self.persistence startGroupWithAction:@"ExecuteQuery"];
+ FSTDocumentDictionary *result = [self.localDocuments documentsMatchingQuery:query];
+ [self.persistence commitGroup:group];
+ return result;
}
- (FSTDocumentKeySet *)remoteDocumentKeysForTarget:(FSTTargetID)targetID {