Search in sources :

Example 16 with PermanentStorageException

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

the class PersistitKeyValueStore method getSlice.

/**
 * Runs all getSlice queries
 *
 * The keyStart & keyEnd are not guaranteed to exist
 * if keyStart is after keyEnd, an empty list is returned
 *
 * @param keyStart
 * @param keyEnd
 * @param selector
 * @param limit
 * @param txh
 * @return
 * @throws StorageException
 */
private RecordIterator<KeyValueEntry> getSlice(final StaticBuffer keyStart, final StaticBuffer keyEnd, final KeySelector selector, final Integer limit, StoreTransaction txh) throws StorageException {
    PersistitTransaction tx = (PersistitTransaction) txh;
    final List<KeyValueEntry> results = new ArrayList<KeyValueEntry>();
    synchronized (tx) {
        tx.assign();
        Exchange exchange = tx.getExchange(name);
        try {
            byte[] start = getArray(keyStart);
            byte[] end = getArray(keyEnd);
            // bail out if the start key comes after the end
            if (compare(start, end) > 0) {
                return KVUtil.EMPTY_ITERATOR;
            }
            KeyFilter.Term[] terms = { KeyFilter.rangeTerm(start, end, true, false, null) };
            KeyFilter keyFilter = new KeyFilter(terms);
            int i = 0;
            while (exchange.next(keyFilter)) {
                StaticBuffer k = getKey(exchange);
                // check the key against the selector, and that is has a corresponding value
                if (exchange.getValue().isDefined() && (selector == null || selector.include(k))) {
                    StaticBuffer v = getValue(exchange);
                    KeyValueEntry kv = new KeyValueEntry(k, v);
                    results.add(kv);
                    i++;
                    if (limit != null && limit >= 0 && i >= limit)
                        break;
                    if (selector != null && selector.reachedLimit())
                        break;
                }
            }
        } catch (PersistitException ex) {
            throw new PermanentStorageException(ex);
        } finally {
            tx.releaseExchange(exchange);
        }
    }
    // on heap for at least 2 collections.
    return new RecordIterator<KeyValueEntry>() {

        private final Iterator<KeyValueEntry> entries = results.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();
        }
    };
}
Also used : RecordIterator(com.thinkaurelius.titan.diskstorage.util.RecordIterator) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) RecordIterator(com.thinkaurelius.titan.diskstorage.util.RecordIterator) PersistitException(com.persistit.exception.PersistitException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KeyValueEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)

Example 17 with PermanentStorageException

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

the class ElasticSearchIndex method clearStorage.

@Override
public void clearStorage() throws StorageException {
    try {
        try {
            client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet();
            // We wait for one second to let ES delete the river
            Thread.sleep(1000);
        } catch (IndexMissingException e) {
        // Index does not exist... Fine
        }
    } catch (Exception e) {
        throw new PermanentStorageException("Could not delete index " + indexName, e);
    } finally {
        close();
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) IndexMissingException(org.elasticsearch.indices.IndexMissingException) ElasticSearchInterruptedException(org.elasticsearch.ElasticSearchInterruptedException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TitanException(com.thinkaurelius.titan.core.TitanException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) IndexMissingException(org.elasticsearch.indices.IndexMissingException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) IOException(java.io.IOException)

Example 18 with PermanentStorageException

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

the class PersistitKeyValueStore method delete.

@Override
public void delete(final StaticBuffer key, StoreTransaction txh) throws StorageException {
    final PersistitTransaction tx = (PersistitTransaction) txh;
    synchronized (tx) {
        tx.assign();
        final Exchange exchange = tx.getExchange(name);
        try {
            toKey(exchange, key);
            exchange.remove();
        } catch (PersistitException ex) {
            throw new PermanentStorageException(ex);
        } finally {
            tx.releaseExchange(exchange);
        }
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) PersistitException(com.persistit.exception.PersistitException)

Example 19 with PermanentStorageException

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

the class PersistitTransaction method getExchange.

public Exchange getExchange(String treeName, Boolean create) throws StorageException {
    synchronized (this) {
        Exchange exchange;
        try {
            assign();
            exchange = db.getExchange(VOLUME_NAME, treeName, create);
            return exchange;
        } catch (PersistitException ex) {
            throw new PermanentStorageException(ex);
        }
    }
}
Also used : Exchange(com.persistit.Exchange) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) PersistitException(com.persistit.exception.PersistitException)

Example 20 with PermanentStorageException

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

the class CassandraThriftStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String ksName, String cfName, String comparator) throws StorageException {
    CTConnection conn = null;
    try {
        KsDef keyspaceDef = ensureKeyspaceExists(ksName);
        conn = pool.borrowObject(ksName);
        Cassandra.Client client = conn.getClient();
        log.debug("Looking up metadata on keyspace {}...", ksName);
        boolean foundColumnFamily = false;
        for (CfDef cfDef : keyspaceDef.getCf_defs()) {
            String curCfName = cfDef.getName();
            if (curCfName.equals(cfName))
                foundColumnFamily = true;
        }
        if (!foundColumnFamily) {
            createColumnFamily(client, ksName, cfName, comparator);
        } else {
            log.debug("Keyspace {} and ColumnFamily {} were found.", ksName, cfName);
        }
    } catch (SchemaDisagreementException e) {
        throw new TemporaryStorageException(e);
    } catch (Exception e) {
        throw new PermanentStorageException(e);
    } finally {
        pool.returnObjectUnsafe(ksName, conn);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) Cassandra(org.apache.cassandra.thrift.Cassandra) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) KsDef(org.apache.cassandra.thrift.KsDef) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException) CfDef(org.apache.cassandra.thrift.CfDef) NotFoundException(org.apache.cassandra.thrift.NotFoundException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException)

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