Search in sources :

Example 6 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class BerkeleyJEKeyValueStore method getSlice.

@Override
public RecordIterator<KeyValueEntry> getSlice(StaticBuffer keyStart, StaticBuffer keyEnd, KeySelector selector, StoreTransaction txh) throws StorageException {
    log.trace("Get slice query");
    Transaction tx = getTransaction(txh);
    Cursor cursor = null;
    final List<KeyValueEntry> result = new ArrayList<KeyValueEntry>();
    try {
        DatabaseEntry foundKey = keyStart.as(ENTRY_FACTORY);
        DatabaseEntry foundData = new DatabaseEntry();
        cursor = db.openCursor(tx, null);
        OperationStatus status = cursor.getSearchKeyRange(foundKey, foundData, LockMode.DEFAULT);
        // Iterate until given condition is satisfied or end of records
        while (status == OperationStatus.SUCCESS) {
            StaticBuffer key = getBuffer(foundKey);
            if (key.compareTo(keyEnd) >= 0)
                break;
            if (selector.include(key)) {
                result.add(new KeyValueEntry(key, getBuffer(foundData)));
            }
            if (selector.reachedLimit())
                break;
            status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT);
        }
        log.trace("Retrieved: {}", result.size());
        return new RecordIterator<KeyValueEntry>() {

            private final Iterator<KeyValueEntry> entries = result.iterator();

            @Override
            public boolean hasNext() {
                return entries.hasNext();
            }

            @Override
            public KeyValueEntry next() {
                return entries.next();
            }

            @Override
            public void close() {
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    } catch (Exception e) {
        throw new PermanentStorageException(e);
    } finally {
        try {
            if (cursor != null)
                cursor.close();
        } catch (Exception e) {
            throw new PermanentStorageException(e);
        }
    }
}
Also used : RecordIterator(com.thinkaurelius.titan.diskstorage.util.RecordIterator) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) ArrayList(java.util.ArrayList) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) NoSuchElementException(java.util.NoSuchElementException) StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) RecordIterator(com.thinkaurelius.titan.diskstorage.util.RecordIterator) Iterator(java.util.Iterator) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KeyValueEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)

Example 7 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class BerkeleyJEKeyValueStore method get.

@Override
public StaticBuffer get(StaticBuffer key, StoreTransaction txh) throws StorageException {
    Transaction tx = getTransaction(txh);
    try {
        DatabaseEntry dbkey = key.as(ENTRY_FACTORY);
        DatabaseEntry data = new DatabaseEntry();
        OperationStatus status = db.get(tx, dbkey, data, LockMode.DEFAULT);
        if (status == OperationStatus.SUCCESS) {
            return getBuffer(data);
        } else {
            return null;
        }
    } catch (DatabaseException e) {
        throw new PermanentStorageException(e);
    }
}
Also used : StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException)

Example 8 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class BerkeleyJEKeyValueStore method delete.

@Override
public void delete(StaticBuffer key, StoreTransaction txh) throws StorageException {
    log.trace("Deletion");
    Transaction tx = getTransaction(txh);
    try {
        OperationStatus status = db.delete(tx, key.as(ENTRY_FACTORY));
        if (status != OperationStatus.SUCCESS) {
            throw new PermanentStorageException("Could not remove: " + status);
        }
    } catch (DatabaseException e) {
        throw new PermanentStorageException(e);
    }
}
Also used : StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException)

Example 9 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class BerkeleyJEStoreManager method initialize.

private void initialize(int cachePercent) throws StorageException {
    try {
        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setTransactional(transactional);
        envConfig.setCachePercent(cachePercent);
        if (batchLoading) {
            envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CHECKPOINTER, "false");
            envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CLEANER, "false");
        }
        // Open the environment
        environment = new Environment(directory, envConfig);
    } catch (DatabaseException e) {
        throw new PermanentStorageException("Error during BerkeleyJE initialization: ", e);
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException)

Example 10 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class BerkeleyJEStoreManager method openDatabase.

@Override
public BerkeleyJEKeyValueStore openDatabase(String name) throws StorageException {
    Preconditions.checkNotNull(name);
    if (stores.containsKey(name)) {
        BerkeleyJEKeyValueStore store = stores.get(name);
        return store;
    }
    try {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setReadOnly(isReadOnly);
        dbConfig.setAllowCreate(true);
        dbConfig.setTransactional(transactional);
        dbConfig.setKeyPrefixing(true);
        if (batchLoading) {
            dbConfig.setDeferredWrite(true);
        }
        Database db = environment.openDatabase(null, name, dbConfig);
        BerkeleyJEKeyValueStore store = new BerkeleyJEKeyValueStore(name, db, this);
        stores.put(name, store);
        return store;
    } catch (DatabaseException e) {
        throw new PermanentStorageException("Could not open BerkeleyJE data store", e);
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException)

Aggregations

PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)43 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)14 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)12 PersistitException (com.persistit.exception.PersistitException)9 IOException (java.io.IOException)8 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)6 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)5 ByteBuffer (java.nio.ByteBuffer)5 StaticByteBuffer (com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer)4 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)4 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)3 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)3 ColumnFamilyDefinition (com.netflix.astyanax.ddl.ColumnFamilyDefinition)2 Exchange (com.persistit.Exchange)2 DatabaseException (com.sleepycat.je.DatabaseException)2 TitanException (com.thinkaurelius.titan.core.TitanException)2 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)2 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)2 KeyValueEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)2 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)2