Package org.xtreemfs.babudb.api

Examples of org.xtreemfs.babudb.api.DatabaseManager


    public static void main(String[] args) throws InterruptedException {
        try {
            // start the database
            BabuDB databaseSystem = BabuDBFactory.createBabuDB(new BabuDBConfig("myDatabase/", "myDatabase/",
                2, 1024 * 1024 * 16, 5 * 60, SyncMode.SYNC_WRITE, 0, 0, false, 16, 1024 * 1024 * 512));
            DatabaseManager dbm = databaseSystem.getDatabaseManager();
           
            // create a new database called myDB
            dbm.createDatabase("myDB", 2);
            Database db = dbm.getDatabase("myDB");
           
            // create an insert group for atomic inserts
            DatabaseInsertGroup group = db.createInsertGroup();
           
            // insert one key in each index
View Full Code Here


    }
   
    @Test
    public void testTransactionExecution() throws Exception {
       
        DatabaseManager dbMan = database.getDatabaseManager();
       
        // create and execute a transaction
        Transaction txn = dbMan.createTransaction();
        txn.createDatabase("test", 3);
        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");
        txn.deleteDatabase("test2");
        dbMan.executeTransaction(txn);
       
        // check if all databases were deleted
        assertEquals(0, dbMan.getDatabases().size());
       
        // create and execute an empty transaction
        txn = dbMan.createTransaction();
        dbMan.executeTransaction(txn);
       
    }
View Full Code Here

    }
   
    @Test
    public void testTransactionPersistence() throws Exception {
       
        DatabaseManager dbMan = database.getDatabaseManager();
       
        // create and execute a transaction
        Transaction txn = dbMan.createTransaction();
        txn.createDatabase("test", 2);
        txn.insertRecord("test", 0, "hello".getBytes(), "world".getBytes());
        txn.insertRecord("test", 1, "key".getBytes(), "value".getBytes());
        dbMan.executeTransaction(txn);
       
        // shutdown and restart the database
        database.shutdown();
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 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
        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
View Full Code Here

    @Test
    public void testTransactionListeners() throws Exception {
       
        final AtomicInteger count = new AtomicInteger(0);
       
        DatabaseManager dbMan = database.getDatabaseManager();
       
        // add a transaction listener
        TransactionListener l0 = new TransactionListener() {
            public void transactionPerformed(Transaction txn) {
                count.incrementAndGet();
            }
        };
        dbMan.addTransactionListener(l0);
       
        // create and execute a transaction
        Transaction txn = dbMan.createTransaction();
        txn.createDatabase("test", 1);
        txn.insertRecord("test", 0, "hello".getBytes(), "world".getBytes());
        txn.insertRecord("test", 0, "key".getBytes(), "value".getBytes());
        dbMan.executeTransaction(txn);
       
        assertEquals(1, count.get());
       
        // create and execute another transaction (which is empty)
        txn = dbMan.createTransaction();
       
        // add a listener before executing the transaction and wait for the
        // notification
        TransactionListener l1 = new TransactionListener() {
            public void transactionPerformed(Transaction txn) {
                count.incrementAndGet();
            }
        };
        dbMan.addTransactionListener(l1);
        dbMan.executeTransaction(txn);
       
        assertEquals(3, count.get());
       
    }
View Full Code Here

       
        final int numTxns = 10;
        final int numKVPairs = 20;
        final int numIndices = 5;
       
        final DatabaseManager dbMan = database.getDatabaseManager();
        final List<Throwable> errors = new LinkedList<Throwable>();
       
        // add a transaction listener
        TransactionListener l = new TransactionListener() {
            public void transactionPerformed(Transaction txn) {
                try {
                    // check if the database has been properly created and
                    // populated
                    checkDBContent(dbMan, txn.getOperations().get(0).getDatabaseName(), numIndices,
                        numKVPairs);
                } catch (Throwable e) {
                    errors.add(e);
                }
            }
        };
        dbMan.addTransactionListener(l);
       
        // create and execute multiple transactions: each creates a new database
        // and populates multiple indices
        for (int i = 0; i < numTxns; i++) {
           
            String dbName = i + "";
           
            Transaction txn = dbMan.createTransaction();
            txn.createDatabase(dbName, numIndices);
            for (int j = 0; j < numKVPairs; j++) {
                String kv = intToString(j, ("" + numKVPairs).length());
                txn.insertRecord(dbName, j % numIndices, kv.getBytes(), kv.getBytes());
            }
            dbMan.executeTransaction(txn);
        }
       
        if (errors.size() > 0)
            throw errors.get(0);
       
View Full Code Here

        // FSUtils.delTree(new File(dbDir));
       
        // start the database
        final BabuDB databaseSystem = BabuDBFactory.createBabuDB(new BabuDBConfig(dbDir, dbDir, numThreads,
                maxLogFileSize, 10, SyncMode.ASYNC, 1000, 0, false, 16, 1024 * 1024 * 256));
        DatabaseManager dbm = databaseSystem.getDatabaseManager();
       
        // for (int i = 0; i < numDBs; i++)
        // dbm.createDatabase("DB" + i, numIndices);
        dbm.createDatabase("blub", numIndices);
       
        final Database[] dbs = new Database[numDBs];
        for (int i = 0; i < dbs.length; i++)
            dbs[i] = dbm.getDatabase("DB" + i);
       
        Thread writeThread = new Thread() {
           
            public void run() {
               
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.api.DatabaseManager

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.