public void Snapshot() { // modify db var writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key1", "value1"); Native.leveldb_writeoptions_destroy(writeOptions); // create snapshot var snapshot = Native.leveldb_create_snapshot(Database); // modify db again writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key2", "value2"); Native.leveldb_writeoptions_destroy(writeOptions); // read from snapshot var readOptions = Native.leveldb_readoptions_create(); Native.leveldb_readoptions_set_snapshot(readOptions, snapshot); var val1 = Native.leveldb_get(Database, readOptions, "key1"); Assert.AreEqual("value1", val1); var val2 = Native.leveldb_get(Database, readOptions, "key2"); Assert.IsNull(val2); Native.leveldb_readoptions_destroy(readOptions); // release snapshot Native.leveldb_release_snapshot(Database, snapshot); snapshot = IntPtr.Zero; }
public Snapshot(DB db) { if (db == null) { throw new ArgumentNullException("db"); } DB = db; Handle = Native.leveldb_create_snapshot(db.Handle); }