aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore
diff options
context:
space:
mode:
authorGravatar Gil <mcg@google.com>2018-06-13 08:12:09 -0700
committerGravatar GitHub <noreply@github.com>2018-06-13 08:12:09 -0700
commitafd897619fba10b881c4567d76793c6fdc60e93a (patch)
tree916cfceabe732ca375b82c7fe4e2cecfb265d251 /Firestore
parent51fb4d0ca4fae5ad30b53c9470f9e59c4678b034 (diff)
Minor LevelDB cleanups (#1401)
* Add leveldb_transaction* to the CMake build * Use std::unique_ptr for leveldb::DB pointers
Diffstat (limited to 'Firestore')
-rw-r--r--Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm8
-rw-r--r--Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm2
-rw-r--r--Firestore/Source/Local/FSTLevelDB.h2
-rw-r--r--Firestore/Source/Local/FSTLevelDB.mm6
-rw-r--r--Firestore/Source/Local/FSTLevelDBMutationQueue.h2
-rw-r--r--Firestore/Source/Local/FSTLevelDBMutationQueue.mm2
-rw-r--r--Firestore/Source/Local/FSTLevelDBQueryCache.h2
-rw-r--r--Firestore/Source/Local/FSTLevelDBQueryCache.mm2
-rw-r--r--Firestore/core/src/firebase/firestore/local/CMakeLists.txt2
9 files changed, 18 insertions, 10 deletions
diff --git a/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm
index 3da8083..e6ab720 100644
--- a/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm
+++ b/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm
@@ -42,7 +42,7 @@ using leveldb::Status;
@end
@implementation FSTLevelDBMigrationsTests {
- std::shared_ptr<DB> _db;
+ std::unique_ptr<DB> _db;
}
- (void)setUp {
@@ -62,12 +62,12 @@ using leveldb::Status;
}
- (void)testAddsTargetGlobal {
- FSTPBTargetGlobal *metadata = [FSTLevelDBQueryCache readTargetMetadataFromDB:_db];
+ FSTPBTargetGlobal *metadata = [FSTLevelDBQueryCache readTargetMetadataFromDB:_db.get()];
XCTAssertNil(metadata, @"Not expecting metadata yet, we should have an empty db");
LevelDbTransaction transaction(_db.get(), "testAddsTargetGlobal");
[FSTLevelDBMigrations runMigrationsWithTransaction:&transaction];
transaction.Commit();
- metadata = [FSTLevelDBQueryCache readTargetMetadataFromDB:_db];
+ metadata = [FSTLevelDBQueryCache readTargetMetadataFromDB:_db.get()];
XCTAssertNotNil(metadata, @"Migrations should have added the metadata");
}
@@ -107,7 +107,7 @@ using leveldb::Status;
LevelDbTransaction transaction(_db.get(), "testCountsQueries");
[FSTLevelDBMigrations runMigrationsWithTransaction:&transaction];
transaction.Commit();
- FSTPBTargetGlobal *metadata = [FSTLevelDBQueryCache readTargetMetadataFromDB:_db];
+ FSTPBTargetGlobal *metadata = [FSTLevelDBQueryCache readTargetMetadataFromDB:_db.get()];
XCTAssertEqual(expected, metadata.targetCount, @"Failed to count all of the targets we added");
}
}
diff --git a/Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm
index 29f5d6c..5c2718b 100644
--- a/Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm
+++ b/Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm
@@ -46,7 +46,7 @@ using firebase::firestore::local::LevelDbTransaction;
@end
@implementation FSTLevelDBTransactionTests {
- std::shared_ptr<DB> _db;
+ std::unique_ptr<DB> _db;
}
- (void)setUp {
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<leveldb::DB> 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 <memory>
+#include <utility>
#import "FIRFirestoreErrors.h"
#import "Firestore/Source/Local/FSTLevelDBMigrations.h"
@@ -60,6 +61,7 @@ using leveldb::WriteOptions;
@implementation FSTLevelDB {
std::unique_ptr<LevelDbTransaction> _transaction;
+ std::unique_ptr<leveldb::DB> _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<leveldb::DB>)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>)db {
++ (FSTBatchID)loadNextBatchIDFromDB:(DB *)db {
// TODO(gsoltis): implement Prev() and SeekToLast() on LevelDbTransaction::Iterator, then port
// this to a transaction.
std::unique_ptr<Iterator> 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<leveldb::DB>)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>)db {
++ (nullable FSTPBTargetGlobal *)readTargetMetadataFromDB:(DB *)db {
std::string key = [FSTLevelDBTargetGlobalKey key];
std::string value;
Status status = db->Get([FSTLevelDB standardReadOptions], key, &value);
diff --git a/Firestore/core/src/firebase/firestore/local/CMakeLists.txt b/Firestore/core/src/firebase/firestore/local/CMakeLists.txt
index 089d03c..4d39c3d 100644
--- a/Firestore/core/src/firebase/firestore/local/CMakeLists.txt
+++ b/Firestore/core/src/firebase/firestore/local/CMakeLists.txt
@@ -17,6 +17,8 @@ cc_library(
SOURCES
leveldb_key.h
leveldb_key.cc
+ leveldb_transaction.h
+ leveldb_transaction.cc
DEPENDS
LevelDB::LevelDB
absl_strings