Package org.xtreemfs.babudb.api.exception

Examples of org.xtreemfs.babudb.api.exception.BabuDBException


                    int dbId = oin.readInt();
                    SnapshotConfig snap = (SnapshotConfig) oin.readObject();
                   
                    return new Object[] { dbId, snap };
                } catch (Exception e) {
                    throw new BabuDBException(ErrorCode.IO_ERROR,
                            "Could not deserialize operation of type " + Operation.TYPE_CREATE_SNAP +
                                ", because: "+e.getMessage(), e);
                } finally {
                    try {
                        serialized.flip();
                        if (oin != null) oin.close();
                    } catch (IOException ioe) {
                        /* who cares? */
                    }
                }
            }
           
            @Override
            public OperationInternal convertToOperation(Object[] args) {
                return new BabuDBTransaction.BabuDBOperation(Operation.TYPE_CREATE_SNAP, (String) null,
                        new Object[] { args[0], args[1] });
            }
           
            @Override
            public Object process(OperationInternal operation) throws BabuDBException {
               
                Object[] args = operation.getParams();
               
                // parse args
                int dbId = (Integer) args[0];
                SnapshotConfig snap = (SnapshotConfig) args[1];
               
                // complete arguments
                if (dbId == InsertRecordGroup.DB_ID_UNKNOWN &&
                    operation.getDatabaseName() != null) {
                    dbId = dbs.getDatabaseManager().getDatabase(
                            operation.getDatabaseName()).getLSMDB().getDatabaseId();
                    operation.updateParams(new Object[] { dbId, snap });                 
                } else if (operation.getDatabaseName() == null) {
                    operation.updateDatabaseName(
                            dbs.getDatabaseManager().getDatabase(dbId).getName());
                }
               
                Map<String, Snapshot> snapMap = snapshotDBs.get(operation.getDatabaseName());
                if (snapMap == null) {
                    snapMap = new HashMap<String, Snapshot>();
                    snapshotDBs.put(operation.getDatabaseName(), snapMap);
                }
               
                // if the snapshot already exists ...
                if (snapMap.containsKey(snap.getName())) {
                   
                    throw new BabuDBException(ErrorCode.SNAP_EXISTS, "snapshot '" + snap.getName()
                        + "' already exists");
                }
               
                snapMap.put(snap.getName(), new Snapshot(null, dbs));
               
                // first, create new in-memory snapshots of all indices
                int[] snapIds = null;
                try {
                    dbs.getTransactionManager().lockService();
                   
                    // create the snapshot
                    snapIds = dbs.getDatabaseManager().getDatabase(dbId).getLSMDB().createSnapshot(
                            snap.getIndices());
                } catch (InterruptedException e) {
                    throw new BabuDBException(ErrorCode.INTERRUPTED, e.getMessage());
                } finally {
                    dbs.getTransactionManager().unlockService();
                }
               
                // then, enqueue a snapshot materialization request in the
                // checkpointer's queue
                dbs.getCheckpointer().addSnapshotMaterializationRequest(operation.getDatabaseName(),
                        snapIds, snap);
               
                // as long as the snapshot has not been persisted yet, add a view on
                // the current snapshot in the original database to the snapshot DB map
                synchronized (snapshotDBs) {
                   
                    Snapshot s = snapMap.get(snap.getName());
                    if (s.getView() == null) {
                        s.setView(new InMemoryView(dbs, operation.getDatabaseName(), snap,
                                snapIds));
                    }
                }
               
                return null;
            }
        });

        dbs.getTransactionManager().registerInMemoryProcessing(Operation.TYPE_DELETE_SNAP,
                new InMemoryProcessing() {
                       
            @Override
            public Object[] deserializeRequest(ReusableBuffer serialized) throws BabuDBException {
               
                byte[] payload = serialized.array();
                int offs = payload[0];
                String dbName = new String(payload, 1, offs);
                String snapName = new String(payload, offs + 1, payload.length - offs - 1);
                serialized.flip();
               
                return new Object[] { dbName, snapName };
            }
           
            @Override
            public OperationInternal convertToOperation(Object[] args) {
                return new BabuDBTransaction.BabuDBOperation(Operation.TYPE_DELETE_SNAP, (String) args[0],
                        new Object[] { args[1] });
            }

            @Override
            public Object process(OperationInternal operation) throws BabuDBException {

                // parse args
                String snapshotName = (String) operation.getParams()[0];
               
                final Map<String, Snapshot> snapMap = snapshotDBs.get(operation.getDatabaseName());
                if(snapMap == null) {
                    throw new BabuDBException(ErrorCode.NO_SUCH_SNAPSHOT,
                            "snapshot '" + snapshotName +
                            "' does not exist");
                }
               
                final Snapshot snap = snapMap.get(snapshotName);
               
                // if the snapshot does not exist ...
                if (snap == null) {
                    throw new BabuDBException(ErrorCode.NO_SUCH_SNAPSHOT,
                            "snapshot '" + snapshotName +
                            "' does not exist");
                }
               
                // shut down and remove the view
View Full Code Here


    public DatabaseInternal getDatabase(String dbName) throws BabuDBException {
       
        DatabaseInternal db = dbsByName.get(dbName);
       
        if (db == null) {
            throw new BabuDBException(ErrorCode.NO_SUCH_DB, "database with name " + dbName +
                    " does not exist");
        }
        return db;
    }
View Full Code Here

    @Override
    public DatabaseInternal getDatabase(int dbId) throws BabuDBException {
        DatabaseInternal db = dbsById.get(dbId);
       
        if (db == null) {
            throw new BabuDBException(ErrorCode.NO_SUCH_DB, "database (" + dbId +
                    ") does not exist");
        }
        return db;
    }
View Full Code Here

               
                DatabaseImpl db = null;
                synchronized (getDBModificationLock()) {
                    synchronized (dbs.getCheckpointer()) {
                        if (dbsByName.containsKey(operation.getDatabaseName())) {
                            throw new BabuDBException(ErrorCode.DB_EXISTS, "database '" +
                                    operation.getDatabaseName() + "' already exists");
                        }
                        final int dbId = nextDbId++;
                        db = new DatabaseImpl(dbs, new LSMDatabase(operation.getDatabaseName(),
                                dbId, dbs.getConfig().getBaseDir() + operation.getDatabaseName() +
                                File.separatorChar, numIndices, false, com, dbs.getConfig()
                                .getCompression(), dbs.getConfig().getMaxNumRecordsPerBlock(), dbs
                                .getConfig().getMaxBlockFileSize(),
                                dbs.getConfig().getDisableMMap(), dbs.getConfig().getMMapLimit()));
                        dbsById.put(dbId, db);
                        dbsByName.put(operation.getDatabaseName(), db);
                        dbs.getDBConfigFile().save();
                    }
                }
               
                return db;
            }
        });
       
        dbs.getTransactionManager().registerInMemoryProcessing(Operation.TYPE_DELETE_DB,
                new InMemoryProcessing() {
                       
            @Override
            public Object[] deserializeRequest(ReusableBuffer serialized) throws BabuDBException {
               
                serialized.getInt(); // do not use, deprecated
               
                String dbName = serialized.getString();
                serialized.flip();
               
                return new Object[] { dbName };
            }
           
            @Override
            public OperationInternal convertToOperation(Object[] args) {
                return new BabuDBTransaction.BabuDBOperation(Operation.TYPE_DELETE_DB, (String) args[0],
                        null);
            }

            @Override
            public Object process(OperationInternal operation) throws BabuDBException {
               
                int dbId = InsertRecordGroup.DB_ID_UNKNOWN;
                synchronized (getDBModificationLock()) {
                    synchronized (dbs.getCheckpointer()) {
                        if (!dbsByName.containsKey(operation.getDatabaseName())) {
                            throw new BabuDBException(ErrorCode.NO_SUCH_DB, "database '" +
                                    operation.getDatabaseName() + "' does not exists");
                        }
                        final LSMDatabase db = getDatabase(operation.getDatabaseName()).getLSMDB();
                        dbId = db.getDatabaseId();
                        dbsByName.remove(operation.getDatabaseName());
                        dbsById.remove(dbId);
                       
                        dbs.getSnapshotManager().deleteAllSnapshots(operation.getDatabaseName());
                       
                        dbs.getDBConfigFile().save();
                        File dbDir = new File(dbs.getConfig().getBaseDir(),
                                operation.getDatabaseName());
                       
                        if (dbDir.exists()) {
                            FSUtils.delTree(dbDir);
                        }
                    }
                }
               
                return null;
            }
        });
       
        dbs.getTransactionManager().registerInMemoryProcessing(Operation.TYPE_COPY_DB,
                new InMemoryProcessing() {
                       
            @Override
            public Object[] deserializeRequest(ReusableBuffer serialized) throws BabuDBException {
               
                serialized.getInt(); // do not use, deprecated
                serialized.getInt(); // do not use, deprecated
               
                String sourceDB = serialized.getString();
                String destDB = serialized.getString();
               
                serialized.flip();
               
                return new Object[] { sourceDB, destDB };
            }
           
            @Override
            public OperationInternal convertToOperation(Object[] args) {
                return new BabuDBTransaction.BabuDBOperation(Operation.TYPE_COPY_DB, (String) args[0],
                        new Object[] { args[1] });
            }

            @Override
            public Object process(OperationInternal operation) throws BabuDBException {
               
                // parse args
                String destDB = (String) operation.getParams()[0];
               
                DatabaseInternal sDB = getDatabase(operation.getDatabaseName());
               
                int dbId;
                synchronized (getDBModificationLock()) {
                    synchronized (dbs.getCheckpointer()) {
                        if (dbsByName.containsKey(destDB)) {
                            throw new BabuDBException(ErrorCode.DB_EXISTS, "database '" + destDB
                                + "' already exists");
                        }
                        dbId = nextDbId++;
                        // just "reserve" the name
                        dbsByName.put(destDB, null);
                        dbs.getDBConfigFile().save();
                    }
                }
                // materializing the snapshot takes some time, we should not
                // hold the
                // lock meanwhile!
                try {
                    sDB.proceedSnapshot(destDB);
                } catch (InterruptedException i) {
                    throw new BabuDBException(ErrorCode.INTERNAL_ERROR,
                            "Snapshot creation was interrupted.", i);
                }
               
                // create new DB and load from snapshot
                DatabaseInternal newDB = new DatabaseImpl(dbs, new LSMDatabase(destDB, dbId,
                        dbs.getConfig().getBaseDir() + destDB + File.separatorChar,
                        sDB.getLSMDB().getIndexCount(), true, sDB.getComparators(),
                        dbs.getConfig().getCompression(),
                        dbs.getConfig().getMaxNumRecordsPerBlock(),
                        dbs.getConfig().getMaxBlockFileSize(), dbs.getConfig().getDisableMMap(),
                        dbs.getConfig().getMMapLimit()));
               
                // insert real database
                synchronized (dbModificationLock) {
                    dbsById.put(dbId, newDB);
                    dbsByName.put(destDB, newDB);
                    dbs.getDBConfigFile().save();
                }
               
                return null;
            }
        });
       
        dbs.getTransactionManager().registerInMemoryProcessing(Operation.TYPE_GROUP_INSERT,
                new InMemoryProcessing() {
                       
            @Override
            public Object[] deserializeRequest(ReusableBuffer serialized) throws BabuDBException {
               
                InsertRecordGroup irg = InsertRecordGroup.deserialize(serialized);
                serialized.flip();
               
                return new Object[] { irg, null };
            }
           
            @Override
            public OperationInternal convertToOperation(Object[] args) {
                return new BabuDBTransaction.BabuDBOperation(Operation.TYPE_GROUP_INSERT, (String) null,
                        new Object[] { args[0] });
            }
           
            @Override
            public Object process(OperationInternal operation) throws BabuDBException {
               
                Object[] args = operation.getParams();
               
                // parse args
                InsertRecordGroup irg = (InsertRecordGroup) args[0];
                LSMDatabase lsmDB = null;
                if (args.length > 1 && args[1] instanceof LSMDatabase) {
                    lsmDB = (LSMDatabase) args[1];
                }
                   
                // complete the arguments
                if (lsmDB == null) {
                   
                    // set the DB ID, if unknown
                    if (irg.getDatabaseId() == InsertRecordGroup.DB_ID_UNKNOWN) {
                        irg.setDatabaseId(getDatabase(
                                operation.getDatabaseName()).getLSMDB().getDatabaseId());
                    }
                    lsmDB = getDatabase(irg.getDatabaseId()).getLSMDB();
                    operation.updateParams(new Object[] { irg, lsmDB });
                }
                if (operation.getDatabaseName() == null) {
                    operation.updateDatabaseName(lsmDB.getDatabaseName());
                }
               
                int numIndices = lsmDB.getIndexCount();
               
                // check for user errors
                for (InsertRecord ir : irg.getInserts()) {
                    if ((ir.getIndexId() >= numIndices) || (ir.getIndexId() < 0)) {
                       
                        throw new BabuDBException(ErrorCode.NO_SUCH_INDEX, "index " +
                                ir.getIndexId() + " does not exist");
                    }
                }
               
                // insert into the in-memory-tree
View Full Code Here

                } catch (BabuDBException be) {
                    assert (be.getErrorCode() == ErrorCode.NO_SUCH_DB);
                   
                    /* affected database does not exist yet; exception will be ignored */
                } catch (InterruptedException ie) {
                    throw new BabuDBException(ErrorCode.INTERRUPTED, ie.getMessage(), ie);
                }
            }
           
            txn.updateWorkerLocks(databaseLockFutureMap);
        }
View Full Code Here

                    * Math.max(1, configuration.getNumThreads()));
            logger.setLifeCycleListener(this);
            logger.start();
            logger.waitForStartup();
        } catch (Exception ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR, "cannot start database operations logger", ex);
        }
        this.txnMan.init(new LSN(nextLSN.getViewId(), nextLSN.getSequenceNo() - 1L));
        this.txnMan.setLogger(logger);
       
        if (configuration.getNumThreads() > 0) {
View Full Code Here

    @Override
    public LSN restart() throws BabuDBException {
        synchronized (stopped) {
           
            if (!stopped.get()) {
                throw new BabuDBException(ErrorCode.IO_ERROR, "BabuDB has to" + " be stopped before!");
            }
           
            databaseManager.reset();
           
            // determine the LSN from which to start the log replay
           
            // to be able to recover from crashes during checkpoints, it is
            // necessary to start with the smallest LSN found on disk
            LSN dbLsn = null;
            for (DatabaseInternal db : databaseManager.getDatabaseList()) {
                if (dbLsn == null)
                    dbLsn = db.getLSMDB().getOndiskLSN();
                else {
                    LSN onDiskLSN = db.getLSMDB().getOndiskLSN();
                    if (!(LSMDatabase.NO_DB_LSN.equals(dbLsn) || LSMDatabase.NO_DB_LSN.equals(onDiskLSN))) {
                        dbLsn = dbLsn.compareTo(onDiskLSN) < 0 ? dbLsn : onDiskLSN;
                    }
                }
            }
            if (dbLsn == null) {
                // empty database
                dbLsn = new LSN(0, 0);
            } else {
                // need next LSN which is onDisk + 1
                dbLsn = new LSN(dbLsn.getViewId(), dbLsn.getSequenceNo() + 1);
            }
           
            Logging.logMessage(Logging.LEVEL_INFO, this, "starting log replay");
            LSN nextLSN = replayLogs(dbLsn);
            if (dbLsn.compareTo(nextLSN) > 0)
                nextLSN = dbLsn;
            Logging.logMessage(Logging.LEVEL_INFO, this, "log replay done, " + "using LSN: " + nextLSN);
           
            try {
                logger = new DiskLogger(configuration.getDbLogDir(), nextLSN, configuration.getSyncMode(),
                    configuration.getPseudoSyncWait(), configuration.getMaxQueueLength()
                        * configuration.getNumThreads());
                logger.setLifeCycleListener(this);
                logger.start();
                logger.waitForStartup();
            } catch (Exception ex) {
                throw new BabuDBException(ErrorCode.IO_ERROR,
                    "Cannot start " + "database operations logger!", ex);
            }
            this.txnMan.init(new LSN(nextLSN.getViewId(), nextLSN.getSequenceNo() - 1L));
            this.txnMan.setLogger(logger);
           
View Full Code Here

                w.shutdown(graceful);
            }
        }
       
        // stop the plugin threads
        BabuDBException exc = null;
        for (LifeCycleThread p : plugins) {
            try {
                p.shutdown();
                p.waitForShutdown();
            } catch (Exception e) {
                if (exc == null)
                    exc = new BabuDBException(ErrorCode.BROKEN_PLUGIN, e.getMessage(), e.getCause());
            }
        }
       
        // shut down the logger; this keeps insertions from being completed
        try {
            logger.shutdown(graceful);
        } catch (Exception e) {
            Logging.logError(Logging.LEVEL_DEBUG, this, e);
        }
       
        // complete checkpoint before shutdown
        try {
            dbCheckptr.shutdown();
            dbCheckptr.waitForShutdown();
        } catch (Exception e) {
            Logging.logError(Logging.LEVEL_DEBUG, this, e);
        }
       
        try {
            databaseManager.shutdown();
            snapshotManager.shutdown();
        } catch (Exception e) {
            Logging.logError(Logging.LEVEL_DEBUG, this, e);
        }
       
        if (worker != null) {
            for (LSMDBWorker w : worker) {
                try {
                    w.waitForShutdown();
                } catch (Exception e) {
                    Logging.logError(Logging.LEVEL_DEBUG, this, e);
                }
            }
           
            Logging.logMessage(Logging.LEVEL_DEBUG, this, "%d worker threads shut down " + "successfully",
                worker.length);
        }
       
        try {
            responseManager.shutdown();
        } catch (Exception e) {
            throw new BabuDBException(ErrorCode.INTERRUPTED, e.getMessage(), e);
        }
       
        if (exc != null) {
            throw exc;
        }
View Full Code Here

                return new LSN(1, 1);
            }
           
        } catch (IOException ex) {
           
            throw new BabuDBException(ErrorCode.IO_ERROR, "cannot load database operations log, "
                + "file might be corrupted", ex);
        } catch (Exception ex) {
           
            Logging.logError(Logging.LEVEL_ERROR, this, ex);
            throw new BabuDBException(ErrorCode.IO_ERROR, "corrupted/incomplete log entry in "
                + "database operations log", ex);
        }
    }
View Full Code Here

            public void synced(LSN lsn) {
       
                try {
                   
                    if (!isAsync) {
                        BabuDBException irregs = txn.getIrregularities();
                       
                        if (irregs == null) {
                            listener.finished(results, lsn);
                        } else {
                            throw new BabuDBException(irregs.getErrorCode(), "Transaction "
                              + "failed at the execution of the " + (txn.size() + 1)
                                + "th operation, because: " + irregs.getMessage(), irregs);
                        }
                    }
                } catch (BabuDBException error) {
                   
                    if (!isAsync) {
                        listener.failed(error);
                    } else {
                        Logging.logError(Logging.LEVEL_WARN, this, error);
                    }
                } finally {
                   
                    Logging.logMessage(Logging.LEVEL_DEBUG, this, "... transaction %s finished.",
                            txn.toString());
                   
                    // notify listeners (sync)
                    if (!isAsync) {
                        for (TransactionListener l : listeners) {
                            l.transactionPerformed(txn);
                        }
                    }
                }
            }
           
            @Override
            public void failed(Exception ex) {
                if (!isAsync) {
                    listener.failed((ex != null && ex instanceof BabuDBException) ?
                            (BabuDBException) ex : new BabuDBException(
                                    ErrorCode.INTERNAL_ERROR, ex.getMessage()));
                }
            }
        }, LogEntry.PAYLOAD_TYPE_TRANSACTION);
       
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.api.exception.BabuDBException

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.