Search in sources :

Example 61 with OperationStatus

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

the class BerkeleyJEKeyValueStore method delete.

@Override
public void delete(StaticBuffer key, StoreTransaction txh) throws BackendException {
    log.trace("Deletion");
    Transaction tx = getTransaction(txh);
    try {
        log.trace("db={}, op=delete, tx={}", name, txh);
        OperationStatus status = db.delete(tx, key.as(ENTRY_FACTORY));
        if (status != OperationStatus.SUCCESS && status != OperationStatus.NOTFOUND) {
            throw new PermanentBackendException("Could not remove: " + status);
        }
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Transaction(com.sleepycat.je.Transaction) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseException(com.sleepycat.je.DatabaseException)

Example 62 with OperationStatus

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

the class BerkeleyJEKeyValueStore method insert.

public void insert(StaticBuffer key, StaticBuffer value, StoreTransaction txh, boolean allowOverwrite, Integer ttl) throws BackendException {
    Transaction tx = getTransaction(txh);
    OperationStatus status;
    log.trace("db={}, op=insert, tx={}", name, txh);
    WriteOptions writeOptions = getWriteOptions(txh);
    if (ttl != null && ttl > 0) {
        int convertedTtl = ttlConverter.apply(ttl);
        writeOptions.setTTL(convertedTtl, TimeUnit.HOURS);
    }
    if (allowOverwrite) {
        OperationResult result = db.put(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY), Put.OVERWRITE, writeOptions);
        EnvironmentFailureException.assertState(result != null);
        status = OperationStatus.SUCCESS;
    } else {
        OperationResult result = db.put(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY), Put.NO_OVERWRITE, writeOptions);
        status = result == null ? OperationStatus.KEYEXIST : OperationStatus.SUCCESS;
    }
    if (status != OperationStatus.SUCCESS) {
        throw new PermanentBackendException("Key already exists on no-overwrite.");
    }
}
Also used : WriteOptions(com.sleepycat.je.WriteOptions) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Transaction(com.sleepycat.je.Transaction) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) OperationStatus(com.sleepycat.je.OperationStatus) OperationResult(com.sleepycat.je.OperationResult)

Example 63 with OperationStatus

use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.

the class UpgradeFrom6To7 method performUpgrade.

@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
    reportStarting(environment, 6);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    Database versionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);
    if (versionDb.count() == 0L) {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        IntegerBinding.intToEntry(DEFAULT_CONFIG_VERSION, value);
        ByteBinding.byteToEntry((byte) 0, key);
        OperationStatus status = versionDb.put(null, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error initialising config version: " + status);
        }
    }
    versionDb.close();
    reportFinished(environment, 7);
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig) StoreException(org.apache.qpid.server.store.StoreException)

Example 64 with OperationStatus

use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.

the class BDBLinkStore method save.

private void save(Database database, Transaction txn, final LinkDefinition<Source, Target> link) {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    LinkKey linkKey = new LinkKey(link);
    LinkKeyEntryBinding.getInstance().objectToEntry(linkKey, key);
    LinkValueEntryBinding.getInstance().objectToEntry(new LinkValue(link), value);
    // TODO: create transaction
    OperationStatus status = database.put(txn, key, value);
    if (status != OperationStatus.SUCCESS) {
        throw new StoreException(String.format("Cannot save link %s", linkKey));
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 65 with OperationStatus

use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.

the class AbstractBDBMessageStore method removeMessage.

void removeMessage(long messageId) throws StoreException {
    boolean complete = false;
    Transaction tx = null;
    int attempts = 0;
    try {
        do {
            tx = null;
            try {
                tx = getEnvironmentFacade().beginTransaction(null);
                // remove the message meta data from the store
                DatabaseEntry key = new DatabaseEntry();
                LongBinding.longToEntry(messageId, key);
                getLogger().debug("Removing message id {}", messageId);
                OperationStatus status = getMessageMetaDataDb().delete(tx, key);
                if (status == OperationStatus.NOTFOUND) {
                    getLogger().debug("Message id {} not found (attempt to remove failed - probably application initiated rollback)", messageId);
                }
                getLogger().debug("Deleted metadata for message {}", messageId);
                // now remove the content data from the store if there is any.
                DatabaseEntry contentKeyEntry = new DatabaseEntry();
                LongBinding.longToEntry(messageId, contentKeyEntry);
                getMessageContentDb().delete(tx, contentKeyEntry);
                getLogger().debug("Deleted content for message {}", messageId);
                getEnvironmentFacade().commitNoSync(tx);
                complete = true;
                tx = null;
            } catch (LockConflictException e) {
                try {
                    if (tx != null) {
                        tx.abort();
                    }
                } catch (RuntimeException e2) {
                    getLogger().warn("Unable to abort transaction after LockConflictException on removal of message with id {}", messageId, e2);
                    // been logged.
                    throw getEnvironmentFacade().handleDatabaseException("Cannot remove message with id " + messageId, e);
                }
                sleepOrThrowOnLockConflict(attempts++, "Cannot remove messages", e);
            }
        } while (!complete);
    } catch (RuntimeException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Unexpected BDB exception", e);
        }
        try {
            abortTransactionSafely(tx, getEnvironmentFacade());
        } finally {
            tx = null;
        }
        throw getEnvironmentFacade().handleDatabaseException("Error removing message with id " + messageId + " from database: " + e.getMessage(), e);
    } finally {
        try {
            abortTransactionSafely(tx, getEnvironmentFacade());
        } finally {
            tx = null;
        }
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) PreparedTransaction(org.apache.qpid.server.store.berkeleydb.entry.PreparedTransaction) Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Aggregations

OperationStatus (com.sleepycat.je.OperationStatus)76 DatabaseEntry (com.sleepycat.je.DatabaseEntry)70 Transaction (com.sleepycat.je.Transaction)23 DatabaseException (com.sleepycat.je.DatabaseException)21 Cursor (com.sleepycat.je.Cursor)15 StoreException (org.apache.qpid.server.store.StoreException)13 Versioned (voldemort.versioning.Versioned)9 Database (com.sleepycat.je.Database)8 ArrayList (java.util.ArrayList)7 LockConflictException (com.sleepycat.je.LockConflictException)6 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)6 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)6 UUID (java.util.UUID)4 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)4 SirixIOException (org.sirix.exception.SirixIOException)4 AsyncOperationStatus (voldemort.server.protocol.admin.AsyncOperationStatus)4 PersistenceFailureException (voldemort.store.PersistenceFailureException)4 DatabaseConfig (com.sleepycat.je.DatabaseConfig)3 LockMode (com.sleepycat.je.LockMode)3 VSystemException (io.vertigo.lang.VSystemException)3