Package org.xtreemfs.babudb.api.database

Examples of org.xtreemfs.babudb.api.database.Database


            0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL), new StaticInitialization() {
           
            @Override
            public void initialize(DatabaseManager dbMan, SnapshotManager sMan) {
                try {
                    Database db = dbMan.createDatabase("test", 3);
                    DatabaseInsertGroup ig = db.createInsertGroup();
                    ig.addInsert(0, "Yagga".getBytes(), "Brabbel".getBytes());
                    ig.addInsert(1, "Brabbel".getBytes(), "Blupp".getBytes());
                    ig.addInsert(2, "Blupp".getBytes(), "Blahh".getBytes());
                    db.insert(ig, null).get();
                } catch (Exception e) {
                    e.printStackTrace();
                    fail("No error should occur.");
                }
            }
        });
       
        Database db = database.getDatabaseManager().getDatabase("test");
        byte[] result = db.lookup(0, "Yagga".getBytes(), null).get();
        assertNotNull(result);
        String value = new String(result);
        assertEquals(value, "Brabbel");
       
        result = db.lookup(1, "Brabbel".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Blupp");
       
        result = db.lookup(2, "Blupp".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Blahh");
       
        database.shutdown();
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 0, 0, 0, SyncMode.ASYNC, 0,
            0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL), new StaticInitialization() {
           
            @Override
            public void initialize(DatabaseManager dbMan, SnapshotManager sMan) {
                fail("May not be executed if database is not empty.");
            }
        });
       
        db = database.getDatabaseManager().getDatabase("test");
        result = db.lookup(0, "Yagga".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Brabbel");
       
        result = db.lookup(1, "Brabbel".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Blupp");
       
        result = db.lookup(2, "Blupp".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Blahh");
       
        database.shutdown();
View Full Code Here


        txn.insertRecord("test", 0, "hello".getBytes(), "world".getBytes());
        txn.insertRecord("test", 1, "key".getBytes(), "value".getBytes());
        dbMan.executeTransaction(txn);
       
        // check if the database is there
        Database db = dbMan.getDatabase("test");
        assertNotNull(db);
        assertEquals("test", db.getName());
        assertEquals(3, db.getComparators().length);
       
        // check if the records are there
        byte[] value = db.lookup(0, "hello".getBytes(), null).get();
        assertEquals("world", new String(value));
       
        value = db.lookup(1, "key".getBytes(), null).get();
        assertEquals("value", new String(value));
       
        // create and execute a second transaction
        txn = dbMan.createTransaction();
        txn.createDatabase("test2", 1);
        txn.deleteRecord("test", 0, "hello".getBytes());
        dbMan.executeTransaction(txn);
       
        // check if the both databases are there
        db = dbMan.getDatabase("test");
        assertNotNull(db);
        assertEquals("test", db.getName());
        assertEquals(3, db.getComparators().length);
       
        db = dbMan.getDatabase("test2");
        assertNotNull(db);
        assertEquals("test2", db.getName());
        assertEquals(1, db.getComparators().length);
       
        // check if the key got deleted
        value = db.lookup(0, "hello".getBytes(), null).get();
        assertNull(value);
       
        // create and execute a third transaction
        txn = dbMan.createTransaction();
        txn.deleteDatabase("test");
View Full Code Here

   
    public void testSimpleSnapshot() throws Exception {
       
        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", 3);
       
        // add some key-value pairs
        DatabaseInsertGroup ir = db.createInsertGroup();
        ir.addInsert(0, "Key1".getBytes(), "Value1".getBytes());
        ir.addInsert(0, "Key2".getBytes(), "Value2".getBytes());
        ir.addInsert(0, "Key3".getBytes(), "Value3".getBytes());
        db.insert(ir, null).get();
       
        // create a snapshot (in memory)
        database.getSnapshotManager().createPersistentSnapshot("test",
            new DefaultSnapshotConfig("snap1", new int[] { 0, 1 }, null, null));
        DatabaseRO snap1 = database.getSnapshotManager().getSnapshotDB("test", "snap1");
       
        // overwrite original values
        ir = db.createInsertGroup();
        ir.addInsert(0, "Key1".getBytes(), "x".getBytes());
        ir.addInsert(0, "Key2".getBytes(), "x".getBytes());
        ir.addInsert(0, "Key3".getBytes(), "x".getBytes());
        ir.addInsert(1, "bla".getBytes(), "blub".getBytes());
        db.insert(ir, null).get();
       
        // check if the snapshot still contains the old values
        for (int i = 1; i < 4; i++)
            assertEquals("Value" + i, new String(snap1.lookup(0, ("Key" + i).getBytes(), null).get()));
       
View Full Code Here

   
    public void testPartialSnapshot() throws Exception {
       
        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, "testabc".getBytes(), "v3".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 }, new byte[][][] { { "test".getBytes() },
                { "ba".getBytes(), "blub".getBytes(), "f".getBytes() } }, new byte[][][] {
                { "testabc".getBytes() }, null }));
        DatabaseRO snap1 = database.getSnapshotManager().getSnapshotDB("test", "snap1");
       
        // overwrite original values
        ir = db.createInsertGroup();
        ir.addInsert(0, "testxyz".getBytes(), null);
        ir.addInsert(0, "test".getBytes(), "x".getBytes());
        ir.addInsert(0, "test2".getBytes(), "x".getBytes());
        ir.addInsert(0, "yagga".getBytes(), "x".getBytes());
        ir.addInsert(3, "foo".getBytes(), "x".getBytes());
        ir.addInsert(3, "bar".getBytes(), "x".getBytes());
        db.insert(ir, null).get();
       
        // check whether the snapshot contains exactly the specified key-value
        // pairs
        assertEquals("v1", new String(snap1.lookup(0, "testxyz".getBytes(), null).get()));
        assertEquals("v2", new String(snap1.lookup(0, "test".getBytes(), null).get()));
View Full Code Here

       
        // retrieve the dbMan of the restarted BabuDB
        dbMan = database.getDatabaseManager();
       
        // check if the database is there
        Database db = dbMan.getDatabase("test");
        assertNotNull(db);
        assertEquals("test", db.getName());
        assertEquals(2, db.getComparators().length);
       
        // check if the records are there
        byte[] value = db.lookup(0, "hello".getBytes(), null).get();
        assertEquals("world", new String(value));
       
        value = db.lookup(1, "key".getBytes(), null).get();
        assertEquals("value", new String(value));
       
        // enforce a checkpoint
        database.getCheckpointer().checkpoint();
       
        // shutdown and restart the database
        database.shutdown();
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 0, 0, 0, SyncMode.ASYNC, 0,
            0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
       
        // retrieve the dbMan of the restarted BabuDB
        dbMan = database.getDatabaseManager();
       
        // check if the database is there
        db = dbMan.getDatabase("test");
        assertNotNull(db);
        assertEquals("test", db.getName());
        assertEquals(2, db.getComparators().length);
       
        // check if the records are there
        value = db.lookup(0, "hello".getBytes(), null).get();
        assertEquals("world", new String(value));
       
        value = db.lookup(1, "key".getBytes(), null).get();
        assertEquals("value", new String(value));
       
    }
View Full Code Here

    }
   
    public void testShutdownRestart() throws Exception {
        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());
       
        // checkpoint and restart the database
View Full Code Here

    }
   
    public void testDelete() throws Exception {
        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(1, "foo".getBytes(), "v1".getBytes());
        ir.addInsert(1, "bar".getBytes(), "v2".getBytes());
        db.insert(ir, null).get();
       
        // create a snapshot
        database.getSnapshotManager().createPersistentSnapshot("test",
            new DefaultSnapshotConfig("snap1", new int[] { 0, 3 }, null, null));
       
        // delete the snapshot
        database.getSnapshotManager().deletePersistentSnapshot("test", "snap1");
        try {
            database.getSnapshotManager().getSnapshotDB("test", "snap1");
            fail();
        } catch (Exception exc) {
            // ok
        }
       
        ir = db.createInsertGroup();
        ir.addInsert(0, "testxyz".getBytes(), "ggg".getBytes());
        ir.addInsert(0, "test".getBytes(), "ggg".getBytes());
        db.insert(ir, null).get();
       
        // restart the database w/o checkpointing
        database.shutdown();
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, DEBUG_LEVEL));
View Full Code Here

    }
   
    @Test
    public void testTransactionWorkerInteraction() throws Exception {
       
        Database db0 = database.getDatabaseManager().createDatabase("workerTest0", 1);
        Database db1 = database.getDatabaseManager().createDatabase("workerTest1", 2);
        Database db2 = database.getDatabaseManager().createDatabase("workerTest2", 3);
       
        // make some inserts to fill up the worker queue
        for (int i = 0; i < 100; i++) {
            DatabaseInsertGroup ir = db0.createInsertGroup();
            ir.addInsert(0, (i + "").getBytes(), "bla".getBytes());
            db0.insert(ir, null);
           
            ir = db1.createInsertGroup();
            ir.addInsert(0, (i + "").getBytes(), "bla".getBytes());
            ir.addInsert(1, (i + "").getBytes(), "blubb".getBytes());
            db1.insert(ir, null);
           
            ir = db2.createInsertGroup();
            ir.addInsert(0, (i + "").getBytes(), "bla".getBytes());
            ir.addInsert(1, (i + "").getBytes(), "blubb".getBytes());
            ir.addInsert(2, (i + "").getBytes(), "yagga".getBytes());
            db2.insert(ir, null);
        }
       
        // make a transaction to delete the last 3 keys of two of the databases
        // an update anomaly will be visible, if something went wrong
        Transaction txn = database.getDatabaseManager().createTransaction();
        txn.deleteRecord(db0.getName(), 0, "99".getBytes());
        txn.deleteRecord(db0.getName(), 0, "98".getBytes());
        txn.deleteRecord(db0.getName(), 0, "97".getBytes());
        txn.deleteRecord(db2.getName(), 2, "99".getBytes());
        txn.deleteRecord(db2.getName(), 2, "98".getBytes());
        txn.deleteRecord(db2.getName(), 2, "97".getBytes());
        database.getDatabaseManager().executeTransaction(txn);
        assertNull(db0.lookup(0, "99".getBytes(), null).get());
        assertNull(db0.lookup(0, "98".getBytes(), null).get());
        assertNull(db0.lookup(0, "97".getBytes(), null).get());
        assertNull(db2.lookup(2, "99".getBytes(), null).get());
        assertNull(db2.lookup(2, "98".getBytes(), null).get());
        assertNull(db2.lookup(2, "97".getBytes(), null).get());
    }
View Full Code Here

    }
   
    private void checkDBContent(DatabaseManager dbMan, String dbName, int numIndices, int numKVPairs)
        throws Throwable {
       
        Database db = dbMan.getDatabase(dbName);
       
        for (int j = 0; j < numIndices; j++) {
           
            ResultSet<byte[], byte[]> resultSet = db.prefixLookup(j, new byte[0], null).get();
            for (int i = j; i < numKVPairs; i += numIndices) {
               
                assertTrue(resultSet.hasNext());
                String kv = intToString(i, ("" + numKVPairs).length());
               
View Full Code Here

//        }
    }
   
    public void startTest(int numHours) throws Exception {
       
        final Database db = database.getDatabaseManager().getDatabase(dbname);
       
        tStart = System.currentTimeMillis();
        tEnd = tStart + numHours * 60 * 60 * 1000;
        while (System.currentTimeMillis() < tEnd) {
           
            // what shall we do?
            final int oper = (int) Math.round(Math.random() * 3);
           
            switch (oper) {
            case 0: {
                // single insert
                final int index = getRandomIndex();
                final String key = getRandomDictEntry();
                final String value = getRandomDictEntry();
               
//                controlIndices[index].put(key, value);
                db.singleInsert(index, key.getBytes(), value.getBytes(), null).get();
               
                numIns++;
                System.out.print("+");
            }
                ;
                break;
            case 1: {
                // groupInsert
                final int numInGroup = (int) Math.round(Math.random() * (9)) + 1;
                final DatabaseInsertGroup ig = db.createInsertGroup();
                for (int i = 0; i < numInGroup; i++) {
                    final int index = getRandomIndex();
                    final String key = getRandomDictEntry();
                    final String value = getRandomDictEntry();
//                    controlIndices[index].put(key, value);
                    ig.addInsert(index, key.getBytes(), value.getBytes());
                }
               
                db.insert(ig, null).get();
               
                numInsGroup++;
                System.out.print("x");
            }
                ;
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.api.database.Database

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.