Search in sources :

Example 36 with Transaction

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

the class BDBLinkStore method getLinkDefinitions.

private Collection<LinkDefinition<Source, Target>> getLinkDefinitions(final LinkStoreUpdater updater) {
    Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
    Collection<LinkDefinition<Source, Target>> links = new HashSet<>();
    ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
    ModelVersion storedVersion = getStoredVersion();
    if (currentVersion.lessThan(storedVersion)) {
        throw new StoreException(String.format("Cannot downgrade preference store from '%s' to '%s'", storedVersion, currentVersion));
    }
    try (Cursor cursor = linksDatabase.openCursor(null, null)) {
        final DatabaseEntry key = new DatabaseEntry();
        final DatabaseEntry value = new DatabaseEntry();
        LinkKeyEntryBinding keyEntryBinding = LinkKeyEntryBinding.getInstance();
        LinkValueEntryBinding linkValueEntryBinding = LinkValueEntryBinding.getInstance();
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
            LinkKey linkKey = keyEntryBinding.entryToObject(key);
            LinkValue linkValue = linkValueEntryBinding.entryToObject(value);
            LinkDefinition<Source, Target> link = new LinkDefinitionImpl<>(linkKey.getRemoteContainerId(), linkKey.getLinkName(), linkKey.getRole(), linkValue.getSource(), linkValue.getTarget());
            links.add(link);
        }
    }
    if (storedVersion.lessThan(currentVersion)) {
        links = updater.update(storedVersion.toString(), links);
        final Transaction txn = getEnvironmentFacade().beginTransaction(null);
        try {
            linksDatabase = getEnvironmentFacade().clearDatabase(txn, LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
            for (LinkDefinition<Source, Target> link : links) {
                save(linksDatabase, txn, link);
            }
            updateVersion(txn, currentVersion.toString());
            txn.commit();
            linksDatabase.close();
        } catch (Exception e) {
            txn.abort();
            throw e;
        }
    }
    return links;
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) StoreException(org.apache.qpid.server.store.StoreException) DatabaseNotFoundException(com.sleepycat.je.DatabaseNotFoundException) StoreException(org.apache.qpid.server.store.StoreException) LinkDefinition(org.apache.qpid.server.protocol.v1_0.LinkDefinition) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) LinkDefinitionImpl(org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) ModelVersion(org.apache.qpid.server.model.ModelVersion) HashSet(java.util.HashSet)

Example 37 with Transaction

use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.

the class JEObjectDatabase method getRawInternal.

@Override
protected InputStream getRawInternal(final ObjectId id, final boolean failIfNotFound) {
    checkOpen();
    Preconditions.checkNotNull(id, "id");
    DatabaseEntry key = new DatabaseEntry(id.getRawValue());
    DatabaseEntry data = new DatabaseEntry();
    final LockMode lockMode = LockMode.READ_UNCOMMITTED;
    Transaction transaction = null;
    OperationStatus operationStatus = objectDb.get(transaction, key, data, lockMode);
    if (NOTFOUND.equals(operationStatus)) {
        if (failIfNotFound) {
            throw new IllegalArgumentException("Object does not exist: " + id.toString() + " at " + env.getHome().getAbsolutePath());
        }
        return null;
    }
    final byte[] cData = data.getData();
    return new ByteArrayInputStream(cData);
}
Also used : Transaction(com.sleepycat.je.Transaction) ByteArrayInputStream(java.io.ByteArrayInputStream) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) LockMode(com.sleepycat.je.LockMode)

Example 38 with Transaction

use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.

the class JEObjectDatabase method exists.

/**
     * @see org.locationtech.geogig.storage.ObjectDatabase#exists(org.locationtech.geogig.api.ObjectId)
     */
@Override
public boolean exists(final ObjectId id) {
    checkOpen();
    Preconditions.checkNotNull(id, "id");
    DatabaseEntry key = new DatabaseEntry(id.getRawValue());
    DatabaseEntry data = new DatabaseEntry();
    // tell db not to retrieve data
    data.setPartial(0, 0, true);
    final LockMode lockMode = LockMode.READ_UNCOMMITTED;
    Transaction transaction = null;
    OperationStatus status = objectDb.get(transaction, key, data, lockMode);
    return SUCCESS == status;
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) LockMode(com.sleepycat.je.LockMode)

Example 39 with Transaction

use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.

the class JEObjectDatabase method deleteAll.

@Override
public long deleteAll(Iterator<ObjectId> ids, final BulkOpListener listener) {
    checkWritable();
    long count = 0;
    UnmodifiableIterator<List<ObjectId>> partition = partition(ids, getBulkPartitionSize());
    final DatabaseEntry data = new DatabaseEntry();
    // do not retrieve data
    data.setPartial(0, 0, true);
    while (partition.hasNext()) {
        List<ObjectId> nextIds = Lists.newArrayList(partition.next());
        Collections.sort(nextIds);
        final Transaction transaction = newTransaction();
        CursorConfig cconfig = new CursorConfig();
        final Cursor cursor = objectDb.openCursor(transaction, cconfig);
        try {
            DatabaseEntry key = new DatabaseEntry(new byte[ObjectId.NUM_BYTES]);
            for (ObjectId id : nextIds) {
                // copy id to key object without allocating new byte[]
                id.getRawValue(key.getData());
                OperationStatus status = cursor.getSearchKey(key, data, LockMode.DEFAULT);
                if (OperationStatus.SUCCESS.equals(status)) {
                    OperationStatus delete = cursor.delete();
                    if (OperationStatus.SUCCESS.equals(delete)) {
                        listener.deleted(id);
                        count++;
                    } else {
                        listener.notFound(id);
                    }
                } else {
                    listener.notFound(id);
                }
            }
            cursor.close();
        } catch (Exception e) {
            cursor.close();
            abort(transaction);
            Throwables.propagate(e);
        }
        commit(transaction);
    }
    return count;
}
Also used : Transaction(com.sleepycat.je.Transaction) ObjectId(org.locationtech.geogig.api.ObjectId) OperationStatus(com.sleepycat.je.OperationStatus) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseEntry(com.sleepycat.je.DatabaseEntry) CursorConfig(com.sleepycat.je.CursorConfig) Cursor(com.sleepycat.je.Cursor) ExecutionException(java.util.concurrent.ExecutionException) EnvironmentLockedException(com.sleepycat.je.EnvironmentLockedException)

Example 40 with Transaction

use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.

the class JEObjectDatabase method newTransaction.

@Nullable
private Transaction newTransaction() {
    final boolean transactional = objectDb.getConfig().getTransactional();
    if (transactional) {
        TransactionConfig txConfig = new TransactionConfig();
        txConfig.setReadUncommitted(true);
        Optional<String> durability = configDB.get(OBJECT_DURABILITY_CONFIG_KEY);
        if (!durability.isPresent()) {
            durability = configDB.getGlobal(OBJECT_DURABILITY_CONFIG_KEY);
        }
        if ("safe".equals(durability.orNull())) {
            txConfig.setDurability(Durability.COMMIT_SYNC);
        } else {
            txConfig.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
        }
        Transaction transaction = env.beginTransaction(null, txConfig);
        return transaction;
    }
    return null;
}
Also used : Transaction(com.sleepycat.je.Transaction) TransactionConfig(com.sleepycat.je.TransactionConfig) Nullable(javax.annotation.Nullable)

Aggregations

Transaction (com.sleepycat.je.Transaction)74 DatabaseEntry (com.sleepycat.je.DatabaseEntry)55 Database (com.sleepycat.je.Database)35 OperationStatus (com.sleepycat.je.OperationStatus)20 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 UUID (java.util.UUID)11 Cursor (com.sleepycat.je.Cursor)10 DatabaseConfig (com.sleepycat.je.DatabaseConfig)7 DatabaseException (com.sleepycat.je.DatabaseException)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Environment (com.sleepycat.je.Environment)5 HashMap (java.util.HashMap)5 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)5 NewPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction)5 OldPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)5 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)4 StoreException (org.apache.qpid.server.store.StoreException)4 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)3 LockMode (com.sleepycat.je.LockMode)3