Last active
December 29, 2015 05:08
-
-
Save aozturk/7619361 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rocksdb::Slice key1 = "1"; | |
rocksdb::Slice key2 = "2"; | |
std::string val1 = "one"; | |
std::string val2 = "two"; | |
// populate db first | |
db->Put(rocksdb::WriteOptions(), key1, val1); | |
db->Put(rocksdb::WriteOptions(), key2, val2); | |
rocksdb::ReadOptions readOptions; | |
readOptions.snapshot = db->GetSnapshot(); | |
rocksdb::Iterator* it = db->NewIterator(readOptions); | |
// apply some updates to database | |
rocksdb::Slice key3 = "3"; | |
std::string val3 = "three"; | |
db->Put(rocksdb::WriteOptions(), key3, val3); | |
// read using iter to view the state when the snapshot was created | |
for (it->SeekToFirst(); it->Valid(); it->Next()) { | |
cout << it->key().ToString() << ": " << it->value().ToString() << endl; | |
} | |
delete it; | |
// do not forget to release the snapshot | |
db->ReleaseSnapshot(readOptions.snapshot); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment