aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Local/FSTLevelDB.mm
diff options
context:
space:
mode:
authorGravatar Greg Soltis <gsoltis@google.com>2018-03-22 15:45:05 -0700
committerGravatar GitHub <noreply@github.com>2018-03-22 15:45:05 -0700
commit4afaafdc770612185c4e11d3f09226ce168462a5 (patch)
tree21c912e4c719a1b0a0961457017efce1f4b385c0 /Firestore/Source/Local/FSTLevelDB.mm
parent1e769d708459ff64ca3571ab562377cc56a9d637 (diff)
Change write groups to use transactions (#912)
* 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 * Everything passing * Drop unused function * Style * Renaming * Style * Add log line * Style * Add debug log line for commits, drop unused BatchDescription
Diffstat (limited to 'Firestore/Source/Local/FSTLevelDB.mm')
-rw-r--r--Firestore/Source/Local/FSTLevelDB.mm26
1 files changed, 14 insertions, 12 deletions
diff --git a/Firestore/Source/Local/FSTLevelDB.mm b/Firestore/Source/Local/FSTLevelDB.mm
index ac29304..a7ee99d 100644
--- a/Firestore/Source/Local/FSTLevelDB.mm
+++ b/Firestore/Source/Local/FSTLevelDB.mm
@@ -31,6 +31,7 @@
#include "Firestore/core/src/firebase/firestore/auth/user.h"
#include "Firestore/core/src/firebase/firestore/core/database_info.h"
+#include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
@@ -43,6 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
static NSString *const kReservedPathComponent = @"firestore";
+using firebase::firestore::local::LevelDbTransaction;
using leveldb::DB;
using leveldb::Options;
using leveldb::ReadOptions;
@@ -58,7 +60,9 @@ using leveldb::WriteOptions;
@end
-@implementation FSTLevelDB
+@implementation FSTLevelDB {
+ std::unique_ptr<LevelDbTransaction> _transaction;
+}
/**
* For now this is paranoid, but perhaps disable that in production builds.
@@ -137,7 +141,9 @@ using leveldb::WriteOptions;
return NO;
}
_ptr.reset(database);
- [FSTLevelDBMigrations runMigrationsOnDB:_ptr];
+ LevelDbTransaction transaction(_ptr.get());
+ [FSTLevelDBMigrations runMigrationsWithTransaction:&transaction];
+ transaction.Commit();
return YES;
}
@@ -212,20 +218,16 @@ using leveldb::WriteOptions;
}
- (FSTWriteGroup *)startGroupWithAction:(NSString *)action {
- return [self.writeGroupTracker startGroupWithAction:action];
+ FSTAssert(_transaction == nullptr, @"Starting a transaction while one is already outstanding");
+ _transaction = std::make_unique<LevelDbTransaction>(_ptr.get());
+ return [self.writeGroupTracker startGroupWithAction:action transaction:_transaction.get()];
}
- (void)commitGroup:(FSTWriteGroup *)group {
+ FSTAssert(_transaction != nullptr, @"Committing a transaction before one is started");
[self.writeGroupTracker endGroup:group];
-
- NSString *description = [group description];
- FSTLog(@"Committing %@", description);
-
- Status status = [group writeToDB:_ptr];
- if (!status.ok()) {
- FSTFail(@"%@ failed with status: %s, description: %@", group.action, status.ToString().c_str(),
- description);
- }
+ _transaction->Commit();
+ _transaction.reset();
}
- (void)shutdown {