Skip to content

Instantly share code, notes, and snippets.

@aozturk
Last active December 29, 2015 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aozturk/7619361 to your computer and use it in GitHub Desktop.
Save aozturk/7619361 to your computer and use it in GitHub Desktop.
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