Skip to content

Instantly share code, notes, and snippets.

@aozturk
Last active December 29, 2015 05:08
Show Gist options
  • Select an option

  • Save aozturk/7619361 to your computer and use it in GitHub Desktop.

Select an option

Save aozturk/7619361 to your computer and use it in GitHub Desktop.

Revisions

  1. aozturk revised this gist Nov 23, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion RocksSnapshot.cpp
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,7 @@ db->Put(rocksdb::WriteOptions(), key3, val3);
    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);
  2. aozturk created this gist Nov 23, 2013.
    25 changes: 25 additions & 0 deletions RocksSnapshot.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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;
    db->ReleaseSnapshot(readOptions.snapshot);