From afd897619fba10b881c4567d76793c6fdc60e93a Mon Sep 17 00:00:00 2001 From: Gil Date: Wed, 13 Jun 2018 08:12:09 -0700 Subject: Minor LevelDB cleanups (#1401) * Add leveldb_transaction* to the CMake build * Use std::unique_ptr for leveldb::DB pointers --- Firestore/Source/Local/FSTLevelDB.h | 2 +- Firestore/Source/Local/FSTLevelDB.mm | 6 ++++++ Firestore/Source/Local/FSTLevelDBMutationQueue.h | 2 +- Firestore/Source/Local/FSTLevelDBMutationQueue.mm | 2 +- Firestore/Source/Local/FSTLevelDBQueryCache.h | 2 +- Firestore/Source/Local/FSTLevelDBQueryCache.mm | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) (limited to 'Firestore/Source/Local') diff --git a/Firestore/Source/Local/FSTLevelDB.h b/Firestore/Source/Local/FSTLevelDB.h index 95b80a6..a56c133 100644 --- a/Firestore/Source/Local/FSTLevelDB.h +++ b/Firestore/Source/Local/FSTLevelDB.h @@ -95,7 +95,7 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)descriptionOfStatus:(leveldb::Status)status; /** The native db pointer, allocated during start. */ -@property(nonatomic, assign, readonly) std::shared_ptr ptr; +@property(nonatomic, assign, readonly) leveldb::DB *ptr; @property(nonatomic, readonly) firebase::firestore::local::LevelDbTransaction *currentTransaction; diff --git a/Firestore/Source/Local/FSTLevelDB.mm b/Firestore/Source/Local/FSTLevelDB.mm index 9f75a3e..9dc50a2 100644 --- a/Firestore/Source/Local/FSTLevelDB.mm +++ b/Firestore/Source/Local/FSTLevelDB.mm @@ -17,6 +17,7 @@ #import "Firestore/Source/Local/FSTLevelDB.h" #include +#include #import "FIRFirestoreErrors.h" #import "Firestore/Source/Local/FSTLevelDBMigrations.h" @@ -60,6 +61,7 @@ using leveldb::WriteOptions; @implementation FSTLevelDB { std::unique_ptr _transaction; + std::unique_ptr _ptr; FSTTransactionRunner _transactionRunner; } @@ -82,6 +84,10 @@ using leveldb::WriteOptions; return self; } +- (leveldb::DB *)ptr { + return _ptr.get(); +} + - (const FSTTransactionRunner &)run { return _transactionRunner; } diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.h b/Firestore/Source/Local/FSTLevelDBMutationQueue.h index 034738f..911fa37 100644 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.h +++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.h @@ -51,7 +51,7 @@ NS_ASSUME_NONNULL_BEGIN * Returns one larger than the largest batch ID that has been stored. If there are no mutations * returns 0. Note that batch IDs are global. */ -+ (FSTBatchID)loadNextBatchIDFromDB:(std::shared_ptr)db; ++ (FSTBatchID)loadNextBatchIDFromDB:(leveldb::DB *)db; @end diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm index 3b4687c..94ab8a5 100644 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm +++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm @@ -132,7 +132,7 @@ using leveldb::WriteOptions; self.metadata = metadata; } -+ (FSTBatchID)loadNextBatchIDFromDB:(std::shared_ptr)db { ++ (FSTBatchID)loadNextBatchIDFromDB:(DB *)db { // TODO(gsoltis): implement Prev() and SeekToLast() on LevelDbTransaction::Iterator, then port // this to a transaction. std::unique_ptr it(db->NewIterator(LevelDbTransaction::DefaultReadOptions())); diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.h b/Firestore/Source/Local/FSTLevelDBQueryCache.h index 2cd6758..f756d9e 100644 --- a/Firestore/Source/Local/FSTLevelDBQueryCache.h +++ b/Firestore/Source/Local/FSTLevelDBQueryCache.h @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN * Retrieves the global singleton metadata row from the given database, if it exists. * TODO(gsoltis): remove this method once fully ported to transactions. */ -+ (nullable FSTPBTargetGlobal *)readTargetMetadataFromDB:(std::shared_ptr)db; ++ (nullable FSTPBTargetGlobal *)readTargetMetadataFromDB:(leveldb::DB *)db; /** * Retrieves the global singleton metadata row using the given transaction, if it exists. diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.mm b/Firestore/Source/Local/FSTLevelDBQueryCache.mm index f28370a..31c2a2e 100644 --- a/Firestore/Source/Local/FSTLevelDBQueryCache.mm +++ b/Firestore/Source/Local/FSTLevelDBQueryCache.mm @@ -85,7 +85,7 @@ using firebase::firestore::model::DocumentKeySet; return proto; } -+ (nullable FSTPBTargetGlobal *)readTargetMetadataFromDB:(std::shared_ptr)db { ++ (nullable FSTPBTargetGlobal *)readTargetMetadataFromDB:(DB *)db { std::string key = [FSTLevelDBTargetGlobalKey key]; std::string value; Status status = db->Get([FSTLevelDB standardReadOptions], key, &value); -- cgit v1.2.3