database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, DEBUG_LEVEL));
Database db = database.getDatabaseManager().createDatabase("test", 4);
// add some key-value pairs
DatabaseInsertGroup ir = db.createInsertGroup();
ir.addInsert(0, "testxyz".getBytes(), "v1".getBytes());
ir.addInsert(0, "test".getBytes(), "v2".getBytes());
ir.addInsert(0, "yagga".getBytes(), "bla".getBytes());
ir.addInsert(3, "foo".getBytes(), "v1".getBytes());
ir.addInsert(3, "bar".getBytes(), "v2".getBytes());
db.insert(ir, null).get();
// create a snapshot (in memory)
database.getSnapshotManager().createPersistentSnapshot("test",
new DefaultSnapshotConfig("snap1", new int[] { 0, 3 }, null, null));
DatabaseRO snap1 = database.getSnapshotManager().getSnapshotDB("test", "snap1");
// overwrite original values
ir = db.createInsertGroup();
ir.addInsert(0, "testxyz".getBytes(), "x".getBytes());
ir.addInsert(0, "test".getBytes(), "x".getBytes());
ir.addInsert(3, "foo".getBytes(), "x".getBytes());
ir.addInsert(3, "bar".getBytes(), "x".getBytes());
db.insert(ir, null).get();
// restart the database
database.shutdown();
database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, DEBUG_LEVEL));
db = database.getDatabaseManager().getDatabase("test");
snap1 = database.getSnapshotManager().getSnapshotDB("test", "snap1");
// check whether the snapshot exists and contains the correct value
assertEquals("v1", new String(snap1.lookup(0, "testxyz".getBytes(), null).get()));
assertEquals("v2", new String(snap1.lookup(0, "test".getBytes(), null).get()));
assertEquals("v1", new String(snap1.lookup(3, "foo".getBytes(), null).get()));
assertEquals("v2", new String(snap1.lookup(3, "bar".getBytes(), null).get()));
// create a checkpoint and restart the database again
database.getCheckpointer().checkpoint();
database.shutdown();
database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, DEBUG_LEVEL));
db = database.getDatabaseManager().getDatabase("test");
snap1 = database.getSnapshotManager().getSnapshotDB("test", "snap1");
// check whether the snapshot exists and contains the correct value
assertEquals("v1", new String(snap1.lookup(0, "testxyz".getBytes(), null).get()));
assertEquals("v2", new String(snap1.lookup(0, "test".getBytes(), null).get()));
assertEquals("v1", new String(snap1.lookup(3, "foo".getBytes(), null).get()));
assertEquals("v2", new String(snap1.lookup(3, "bar".getBytes(), null).get()));
ir = db.createInsertGroup();
ir.addInsert(0, "te".getBytes(), "x".getBytes());
ir.addInsert(0, "key".getBytes(), "x".getBytes());
db.insert(ir, null).get();
// create a partial user-defined snapshot
database.getSnapshotManager().createPersistentSnapshot("test", new TestSnapshotConfig());