Search in sources :

Example 11 with DatabaseException

use of com.sleepycat.je.DatabaseException in project sessdb by ppdai.

the class BdbBenchmark method destroyDb.

@Override
public void destroyDb() {
    if (bdb_ != null) {
        try {
            bdb_.close();
            env_.removeDatabase(null, BdbBenchmark.DATABASE_NAME);
            env_.close();
            FileUtil.deleteDirectory(new File(databaseDir_));
            bdb_ = null;
            env_ = null;
        } catch (DatabaseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : File(java.io.File) DatabaseException(com.sleepycat.je.DatabaseException)

Example 12 with DatabaseException

use of com.sleepycat.je.DatabaseException in project janusgraph by JanusGraph.

the class BerkeleyJETx method rollback.

@Override
public synchronized void rollback() throws BackendException {
    super.rollback();
    if (tx == null)
        return;
    if (log.isTraceEnabled())
        log.trace("{} rolled back", this.toString(), new TransactionClose(this.toString()));
    try {
        closeOpenIterators();
        tx.abort();
        tx = null;
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 13 with DatabaseException

use of com.sleepycat.je.DatabaseException in project voldemort by voldemort.

the class BdbStorageConfiguration method getStats.

public String getStats(String storeName, boolean fast) {
    try {
        if (environments.containsKey(storeName)) {
            StatsConfig config = new StatsConfig();
            config.setFast(fast);
            Environment env = environments.get(storeName);
            return env.getStats(config).toString();
        } else {
            // return empty string if environment not created yet
            return "";
        }
    } catch (DatabaseException e) {
        throw new VoldemortException(e);
    }
}
Also used : StatsConfig(com.sleepycat.je.StatsConfig) Environment(com.sleepycat.je.Environment) DatabaseException(com.sleepycat.je.DatabaseException) VoldemortException(voldemort.VoldemortException)

Example 14 with DatabaseException

use of com.sleepycat.je.DatabaseException in project voldemort by voldemort.

the class BdbStorageEngine method put.

@Override
public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms) throws PersistenceFailureException {
    long startTimeNs = -1;
    if (logger.isTraceEnabled())
        startTimeNs = System.nanoTime();
    StoreUtils.assertValidKey(key);
    DatabaseEntry keyEntry = new DatabaseEntry(key.get());
    DatabaseEntry valueEntry = new DatabaseEntry();
    boolean succeeded = false;
    Transaction transaction = null;
    List<Versioned<byte[]>> vals = null;
    try {
        transaction = environment.beginTransaction(null, null);
        // do a get for the existing values
        OperationStatus status = getBdbDatabase().get(transaction, keyEntry, valueEntry, LockMode.RMW);
        if (OperationStatus.SUCCESS == status) {
            // update
            vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
            // compare vector clocks and throw out old ones, for updates
            Iterator<Versioned<byte[]>> iter = vals.iterator();
            while (iter.hasNext()) {
                Versioned<byte[]> curr = iter.next();
                Occurred occurred = value.getVersion().compare(curr.getVersion());
                if (occurred == Occurred.BEFORE)
                    throw new ObsoleteVersionException("Key " + new String(hexCodec.encode(key.get())) + " " + value.getVersion().toString() + " is obsolete, it is no greater than the current version of " + curr.getVersion().toString() + ".");
                else if (occurred == Occurred.AFTER)
                    iter.remove();
            }
        } else {
            // insert
            vals = new ArrayList<Versioned<byte[]>>(1);
        }
        // update the new value
        vals.add(value);
        valueEntry.setData(StoreBinaryFormat.toByteArray(vals));
        status = getBdbDatabase().put(transaction, keyEntry, valueEntry);
        if (status != OperationStatus.SUCCESS)
            throw new PersistenceFailureException("Put operation failed with status: " + status);
        succeeded = true;
    } catch (DatabaseException e) {
        this.bdbEnvironmentStats.reportException(e);
        logger.error("Error in put for store " + this.getName(), e);
        throw new PersistenceFailureException(e);
    } finally {
        if (succeeded)
            attemptCommit(transaction);
        else
            attemptAbort(transaction);
        if (logger.isTraceEnabled()) {
            logger.trace("Completed PUT (" + getName() + ") to key " + key + " (keyRef: " + System.identityHashCode(key) + " value " + value + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
        }
    }
}
Also used : Versioned(voldemort.versioning.Versioned) DatabaseEntry(com.sleepycat.je.DatabaseEntry) PersistenceFailureException(voldemort.store.PersistenceFailureException) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) AsyncOperationStatus(voldemort.server.protocol.admin.AsyncOperationStatus) DatabaseException(com.sleepycat.je.DatabaseException) Occurred(voldemort.versioning.Occurred)

Example 15 with DatabaseException

use of com.sleepycat.je.DatabaseException in project voldemort by voldemort.

the class BdbStorageEngine method delete.

@Override
public boolean delete(ByteArray key, Version version) throws PersistenceFailureException {
    StoreUtils.assertValidKey(key);
    long startTimeNs = -1;
    if (logger.isTraceEnabled())
        startTimeNs = System.nanoTime();
    Transaction transaction = null;
    try {
        transaction = this.environment.beginTransaction(null, null);
        DatabaseEntry keyEntry = new DatabaseEntry(key.get());
        if (version == null) {
            // unversioned delete. Just blow away the whole thing
            OperationStatus status = getBdbDatabase().delete(transaction, keyEntry);
            if (OperationStatus.SUCCESS == status)
                return true;
            else
                return false;
        } else {
            // versioned deletes; need to determine what to delete
            DatabaseEntry valueEntry = new DatabaseEntry();
            // do a get for the existing values
            OperationStatus status = getBdbDatabase().get(transaction, keyEntry, valueEntry, LockMode.RMW);
            // key does not exist to begin with.
            if (OperationStatus.NOTFOUND == status)
                return false;
            List<Versioned<byte[]>> vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
            Iterator<Versioned<byte[]>> iter = vals.iterator();
            int numVersions = vals.size();
            int numDeletedVersions = 0;
            // supplied version
            while (iter.hasNext()) {
                Versioned<byte[]> curr = iter.next();
                Version currentVersion = curr.getVersion();
                if (currentVersion.compare(version) == Occurred.BEFORE) {
                    iter.remove();
                    numDeletedVersions++;
                }
            }
            if (numDeletedVersions < numVersions) {
                // we still have some valid versions
                valueEntry.setData(StoreBinaryFormat.toByteArray(vals));
                getBdbDatabase().put(transaction, keyEntry, valueEntry);
            } else {
                // we have deleted all the versions; so get rid of the entry
                // in the database
                getBdbDatabase().delete(transaction, keyEntry);
            }
            return numDeletedVersions > 0;
        }
    } catch (DatabaseException e) {
        this.bdbEnvironmentStats.reportException(e);
        logger.error(e);
        throw new PersistenceFailureException(e);
    } finally {
        attemptCommit(transaction);
        if (logger.isTraceEnabled()) {
            logger.trace("Completed DELETE (" + getName() + ") of key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
        }
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) Versioned(voldemort.versioning.Versioned) Version(voldemort.versioning.Version) OperationStatus(com.sleepycat.je.OperationStatus) AsyncOperationStatus(voldemort.server.protocol.admin.AsyncOperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Aggregations

DatabaseException (com.sleepycat.je.DatabaseException)21 DatabaseEntry (com.sleepycat.je.DatabaseEntry)5 Environment (com.sleepycat.je.Environment)5 OperationStatus (com.sleepycat.je.OperationStatus)5 Transaction (com.sleepycat.je.Transaction)5 VoldemortException (voldemort.VoldemortException)5 AsyncOperationStatus (voldemort.server.protocol.admin.AsyncOperationStatus)5 PersistenceFailureException (voldemort.store.PersistenceFailureException)5 Versioned (voldemort.versioning.Versioned)3 StatsConfig (com.sleepycat.je.StatsConfig)2 PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)2 WebURL (edu.uci.ics.crawler4j.url.WebURL)2 Bdb (io.leopard.bdb.Bdb)2 File (java.io.File)2 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)2 CheckpointConfig (com.sleepycat.je.CheckpointConfig)1 Database (com.sleepycat.je.Database)1 DatabaseConfig (com.sleepycat.je.DatabaseConfig)1 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)1 DuplicateEntryException (com.sleepycat.je.tree.DuplicateEntryException)1