diff options
author | Greg Soltis <gsoltis@google.com> | 2018-03-22 15:45:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-22 15:45:05 -0700 |
commit | 4afaafdc770612185c4e11d3f09226ce168462a5 (patch) | |
tree | 21c912e4c719a1b0a0961457017efce1f4b385c0 /Firestore/Source/Local/FSTLevelDBQueryCache.mm | |
parent | 1e769d708459ff64ca3571ab562377cc56a9d637 (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/FSTLevelDBQueryCache.mm')
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBQueryCache.mm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.mm b/Firestore/Source/Local/FSTLevelDBQueryCache.mm index fe1bf19..95b032e 100644 --- a/Firestore/Source/Local/FSTLevelDBQueryCache.mm +++ b/Firestore/Source/Local/FSTLevelDBQueryCache.mm @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN +using firebase::firestore::local::LevelDbTransaction; using Firestore::StringView; using leveldb::DB; using leveldb::Iterator; @@ -59,6 +60,30 @@ using leveldb::WriteOptions; FSTSnapshotVersion *_lastRemoteSnapshotVersion; } ++ (nullable FSTPBTargetGlobal *)readTargetMetadataWithTransaction: + (firebase::firestore::local::LevelDbTransaction *)transaction { + std::string key = [FSTLevelDBTargetGlobalKey key]; + std::string value; + Status status = transaction->Get(key, &value); + if (status.IsNotFound()) { + return nil; + } else if (!status.ok()) { + FSTFail(@"metadataForKey: failed loading key %s with status: %s", key.c_str(), + status.ToString().c_str()); + } + + NSData *data = + [[NSData alloc] initWithBytesNoCopy:(void *)value.data() length:value.size() freeWhenDone:NO]; + + NSError *error; + FSTPBTargetGlobal *proto = [FSTPBTargetGlobal parseFromData:data error:&error]; + if (!proto) { + FSTFail(@"FSTPBTargetGlobal failed to parse: %@", error); + } + + return proto; +} + + (nullable FSTPBTargetGlobal *)readTargetMetadataFromDB:(std::shared_ptr<DB>)db { std::string key = [FSTLevelDBTargetGlobalKey key]; std::string value; |