Search in sources :

Example 41 with OperationStatus

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

the class BDBConfigurationStore method storeConfiguredObjectEntry.

private void storeConfiguredObjectEntry(final Transaction txn, ConfiguredObjectRecord configuredObject) throws StoreException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Storing configured object record: " + configuredObject);
    }
    DatabaseEntry key = new DatabaseEntry();
    UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
    uuidBinding.objectToEntry(configuredObject.getId(), key);
    DatabaseEntry value = new DatabaseEntry();
    ConfiguredObjectBinding queueBinding = ConfiguredObjectBinding.getInstance();
    queueBinding.objectToEntry(configuredObject, value);
    try {
        OperationStatus status = getConfiguredObjectsDb().put(txn, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error writing configured object " + configuredObject + " to database: " + status);
        }
        writeHierarchyRecords(txn, configuredObject);
    } catch (RuntimeException e) {
        throw _environmentFacade.handleDatabaseException("Error writing configured object " + configuredObject + " to database: " + e.getMessage(), e);
    }
}
Also used : ConfiguredObjectBinding(org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding) OperationStatus(com.sleepycat.je.OperationStatus) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 42 with OperationStatus

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

the class AbstractBDBPreferenceStore method updateOrCreateInternal.

private void updateOrCreateInternal(final Transaction txn, final Collection<PreferenceRecord> preferenceRecords) {
    Database preferencesDb = getPreferencesDb();
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
    MapBinding valueBinding = MapBinding.getInstance();
    for (PreferenceRecord record : preferenceRecords) {
        keyBinding.objectToEntry(record.getId(), key);
        valueBinding.objectToEntry(record.getAttributes(), value);
        OperationStatus status = preferencesDb.put(txn, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException(String.format("Error writing preference with id '%s' (status %s)", record.getId(), status.name()));
        }
    }
}
Also used : MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 43 with OperationStatus

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

the class AbstractBDBPreferenceStore method removeAndAdd.

private void removeAndAdd(final Collection<UUID> preferenceRecordsToRemove, final Collection<PreferenceRecord> preferenceRecordsToAdd, final Action<Transaction> preCommitAction) {
    _useOrCloseRWLock.readLock().lock();
    try {
        final StoreState storeState = getStoreState();
        if (!storeState.equals(StoreState.OPENED)) {
            throw new IllegalStateException(String.format("PreferenceStore is not opened. Actual state : %s", storeState));
        }
        if (preferenceRecordsToRemove.isEmpty() && preferenceRecordsToAdd.isEmpty()) {
            return;
        }
        EnvironmentFacade environmentFacade = getEnvironmentFacade();
        Transaction txn = null;
        try {
            txn = environmentFacade.beginTransaction(null);
            Database preferencesDb = getPreferencesDb();
            DatabaseEntry key = new DatabaseEntry();
            UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
            for (UUID id : preferenceRecordsToRemove) {
                getLogger().debug("Removing preference {}", id);
                keyBinding.objectToEntry(id, key);
                OperationStatus status = preferencesDb.delete(txn, key);
                if (status == OperationStatus.NOTFOUND) {
                    getLogger().debug("Preference {} not found", id);
                }
            }
            updateOrCreateInternal(txn, preferenceRecordsToAdd);
            if (preCommitAction != null) {
                preCommitAction.performAction(txn);
            }
            txn.commit();
            txn = null;
        } catch (RuntimeException e) {
            throw environmentFacade.handleDatabaseException("Error on replacing of preferences: " + e.getMessage(), e);
        } finally {
            if (txn != null) {
                abortTransactionSafely(txn, environmentFacade);
            }
        }
    } finally {
        _useOrCloseRWLock.readLock().unlock();
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID)

Example 44 with OperationStatus

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

the class OrphanConfigurationRecordPurger method purgeOrphans.

private void purgeOrphans(Environment env, final Transaction tx) throws Exception {
    try (Database configDb = env.openDatabase(tx, CONFIGURED_OBJECTS_DB_NAME, READ_WRITE_DB_CONFIG)) {
        final Set<UUID> records = new HashSet<>();
        try (Cursor configCursor = configDb.openCursor(tx, null)) {
            final DatabaseEntry key = new DatabaseEntry();
            final DatabaseEntry value = new DatabaseEntry();
            while (configCursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
                final UUID recId = entryToUuid(new TupleInput(key.getData()));
                records.add(recId);
            }
        }
        int configRecordDeleted = 0;
        int configHierarchyRecordsDeleted = 0;
        try (Database hierarchyDb = env.openDatabase(null, CONFIGURED_OBJECT_HIERARCHY_DB_NAME, READ_WRITE_DB_CONFIG)) {
            boolean loopAgain;
            do {
                loopAgain = false;
                try (Cursor hierarchyCursor = hierarchyDb.openCursor(tx, null)) {
                    DatabaseEntry key = new DatabaseEntry();
                    DatabaseEntry value = new DatabaseEntry();
                    boolean parentReferencingRecordFound = false;
                    while (hierarchyCursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
                        final TupleInput keyInput = new TupleInput(key.getData());
                        final UUID childId = entryToUuid(keyInput);
                        final String parentType = keyInput.readString();
                        final UUID parentId = entryToUuid(new TupleInput(value.getData()));
                        if (_parentRootCategory.equals(parentType)) {
                            parentReferencingRecordFound = true;
                        } else if (!records.contains(parentId)) {
                            System.out.format("Orphan UUID : %s (has unknown parent with UUID %s of type %s)\n", childId, parentId, parentType);
                            hierarchyCursor.delete();
                            configHierarchyRecordsDeleted++;
                            loopAgain = true;
                            DatabaseEntry uuidKey = new DatabaseEntry();
                            final TupleOutput tupleOutput = uuidToKey(childId);
                            TupleBase.outputToEntry(tupleOutput, uuidKey);
                            final OperationStatus delete = configDb.delete(tx, uuidKey);
                            if (delete == OperationStatus.SUCCESS) {
                                records.remove(childId);
                                configRecordDeleted++;
                            }
                        }
                    }
                    if (!parentReferencingRecordFound) {
                        throw new IllegalStateException(String.format("No hierarchy record found with root category type (%s)." + " Cannot modify store.", _parentRootCategory));
                    }
                }
            } while (loopAgain);
            System.out.format("Identified %d orphaned configured object record(s) " + "and %d hierarchy records for purging\n", configRecordDeleted, configHierarchyRecordsDeleted);
        }
    }
}
Also used : DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) TupleInput(com.sleepycat.bind.tuple.TupleInput) OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) UUID(java.util.UUID) HashSet(java.util.HashSet) TupleOutput(com.sleepycat.bind.tuple.TupleOutput)

Example 45 with OperationStatus

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

the class UpgradeFrom8To9 method performUpgrade.

@Override
public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, final ConfiguredObject<?> parent) {
    reportStarting(environment, 8);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    final Transaction transaction = environment.beginTransaction(null, null);
    try {
        Database userPreferencesDb = environment.openDatabase(transaction, "USER_PREFERENCES", dbConfig);
        userPreferencesDb.close();
        try (Database userPreferencesVersionDb = environment.openDatabase(transaction, "USER_PREFERENCES_VERSION", dbConfig)) {
            if (userPreferencesVersionDb.count() == 0L) {
                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry value = new DatabaseEntry();
                StringBinding.stringToEntry(DEFAULT_VERSION, key);
                LongBinding.longToEntry(System.currentTimeMillis(), value);
                OperationStatus status = userPreferencesVersionDb.put(transaction, key, value);
                if (status != OperationStatus.SUCCESS) {
                    throw new StoreException("Error initialising user preference version: " + status);
                }
            }
        }
        transaction.commit();
        reportFinished(environment, 9);
    } catch (RuntimeException e) {
        try {
            if (transaction.isValid()) {
                transaction.abort();
            }
        } finally {
            throw e;
        }
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) 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)

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