Search in sources :

Example 96 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry in project BIMserver by opensourceBIM.

the class BerkeleySearchingRecordIterator method last.

@Override
public Record last() throws BimserverLockConflictException {
    if (nextStartSearchingAt != null) {
        return getFirstNext(nextStartSearchingAt);
    }
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    if (onlyKeys) {
        value.setPartial(0, 0, true);
    }
    try {
        OperationStatus next = cursor.getLast(key, value, LockMode.DEFAULT);
        if (next == OperationStatus.SUCCESS) {
            byte[] firstBytes = new byte[mustStartWith.length];
            System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
            if (Arrays.equals(firstBytes, mustStartWith)) {
                return new BerkeleyRecord(key, value);
            }
        }
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 97 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry in project BIMserver by opensourceBIM.

the class BerkeleySearchingRecordIterator method getFirstNext.

private Record getFirstNext(byte[] startSearchingAt) throws BimserverLockConflictException {
    this.nextStartSearchingAt = null;
    DatabaseEntry key = new DatabaseEntry(startSearchingAt);
    DatabaseEntry value = new DatabaseEntry();
    if (onlyKeys) {
        value.setPartial(0, 0, true);
    }
    try {
        OperationStatus next = cursor.getSearchKeyRange(key, value, LockMode.DEFAULT);
        if (next == OperationStatus.SUCCESS) {
            byte[] firstBytes = new byte[mustStartWith.length];
            System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
            if (Arrays.equals(firstBytes, mustStartWith)) {
                return new BerkeleyRecord(key, value);
            }
        }
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 98 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method delete.

public void delete(String tableName, byte[] key, DatabaseSession databaseSession) throws BimserverLockConflictException {
    DatabaseEntry entry = new DatabaseEntry(key);
    try {
        TableWrapper tableWrapper = getTableWrapper(tableName);
        tableWrapper.getDatabase().delete(getTransaction(databaseSession, tableWrapper), entry);
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    } catch (UnsupportedOperationException e) {
        LOGGER.error("", e);
    } catch (IllegalArgumentException e) {
        LOGGER.error("", e);
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 99 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry in project BIMserver by opensourceBIM.

the class BerkeleyRecordIterator method next.

public Record next() {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    try {
        OperationStatus next = cursor.getNext(key, value, LockMode.DEFAULT);
        if (next == OperationStatus.SUCCESS) {
            return new BerkeleyRecord(key, value);
        } else {
            return null;
        }
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException)

Example 100 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry 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

DatabaseEntry (com.sleepycat.je.DatabaseEntry)153 OperationStatus (com.sleepycat.je.OperationStatus)70 Transaction (com.sleepycat.je.Transaction)58 Database (com.sleepycat.je.Database)46 Cursor (com.sleepycat.je.Cursor)31 DatabaseException (com.sleepycat.je.DatabaseException)26 StoreException (org.apache.qpid.server.store.StoreException)20 UUID (java.util.UUID)17 ArrayList (java.util.ArrayList)13 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 DatabaseConfig (com.sleepycat.je.DatabaseConfig)11 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)11 LockConflictException (com.sleepycat.je.LockConflictException)9 HashMap (java.util.HashMap)9 Versioned (voldemort.versioning.Versioned)9 HashSet (java.util.HashSet)8 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)8 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)6 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)6 SirixIOException (org.sirix.exception.SirixIOException)6