Search in sources :

Example 11 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class AstyanaxKeyColumnValueStore method getNamesSlice.

public Map<StaticBuffer, EntryList> getNamesSlice(List<StaticBuffer> keys, SliceQuery query, StoreTransaction txh) throws BackendException {
    /*
         * RowQuery<K,C> should be parametrized as
         * RowQuery<ByteBuffer,ByteBuffer>. However, this causes the following
         * compilation error when attempting to call withColumnRange on a
         * RowQuery<ByteBuffer,ByteBuffer> instance:
         *
         * java.lang.Error: Unresolved compilation problem: The method
         * withColumnRange(ByteBuffer, ByteBuffer, boolean, int) is ambiguous
         * for the type RowQuery<ByteBuffer,ByteBuffer>
         *
         * The compiler substitutes ByteBuffer=C for both startColumn and
         * endColumn, compares it to its identical twin with that type
         * hard-coded, and dies.
         *
         */
    // Add one for last column potentially removed in CassandraHelper.makeEntryList
    final int queryLimit = query.getLimit() + (query.hasLimit() ? 1 : 0);
    final int pageLimit = Math.min(this.readPageSize, queryLimit);
    ByteBuffer sliceStart = query.getSliceStart().asByteBuffer();
    final ByteBuffer sliceEnd = query.getSliceEnd().asByteBuffer();
    final RowSliceQuery rq = keyspace.prepareQuery(columnFamily).setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanax()).withRetryPolicy(retryPolicy.duplicate()).getKeySlice(CassandraHelper.convert(keys));
    // Don't directly chain due to ambiguity resolution; see top comment
    rq.withColumnRange(sliceStart, sliceEnd, false, pageLimit);
    final OperationResult<Rows<ByteBuffer, ByteBuffer>> r;
    try {
        r = (OperationResult<Rows<ByteBuffer, ByteBuffer>>) rq.execute();
    } catch (ConnectionException e) {
        throw new TemporaryBackendException(e);
    }
    final Rows<ByteBuffer, ByteBuffer> rows = r.getResult();
    final Map<StaticBuffer, EntryList> result = new HashMap<>(rows.size());
    for (Row<ByteBuffer, ByteBuffer> row : rows) {
        assert !result.containsKey(row.getKey());
        final ByteBuffer key = row.getKey();
        ColumnList<ByteBuffer> pageColumns = row.getColumns();
        final List<Column<ByteBuffer>> queryColumns = new ArrayList();
        Iterables.addAll(queryColumns, pageColumns);
        while (pageColumns.size() == pageLimit && queryColumns.size() < queryLimit) {
            final Column<ByteBuffer> lastColumn = queryColumns.get(queryColumns.size() - 1);
            sliceStart = lastColumn.getName();
            // No possibility of two values at the same column name, so start the
            // next slice one bit after the last column found by the previous query.
            // byte[] is little-endian
            Integer position = null;
            for (int i = sliceStart.array().length - 1; i >= 0; i--) {
                if (sliceStart.array()[i] < Byte.MAX_VALUE) {
                    position = i;
                    sliceStart.array()[i]++;
                    break;
                }
            }
            if (null == position) {
                throw new PermanentBackendException("Column was not incrementable");
            }
            final RowQuery pageQuery = keyspace.prepareQuery(columnFamily).setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanax()).withRetryPolicy(retryPolicy.duplicate()).getKey(row.getKey());
            // Don't directly chain due to ambiguity resolution; see top comment
            pageQuery.withColumnRange(sliceStart, sliceEnd, false, pageLimit);
            final OperationResult<ColumnList<ByteBuffer>> pageResult;
            try {
                pageResult = (OperationResult<ColumnList<ByteBuffer>>) pageQuery.execute();
            } catch (ConnectionException e) {
                throw new TemporaryBackendException(e);
            }
            if (Thread.interrupted()) {
                throw new TraversalInterruptedException();
            }
            // Reset the incremented position to avoid leaking mutations up the
            // stack to callers - sliceStart.array() in fact refers to a column name
            // that will be later read to deserialize an edge (since we assigned it
            // via de-referencing a column from the previous query).
            sliceStart.array()[position]--;
            pageColumns = pageResult.getResult();
            Iterables.addAll(queryColumns, pageColumns);
        }
        result.put(StaticArrayBuffer.of(key), CassandraHelper.makeEntryList(queryColumns, entryGetter, query.getSliceEnd(), query.getLimit()));
    }
    return result;
}
Also used : TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) EntryList(org.janusgraph.diskstorage.EntryList) ByteBuffer(java.nio.ByteBuffer) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) Column(com.netflix.astyanax.model.Column) RowSliceQuery(com.netflix.astyanax.query.RowSliceQuery) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) ColumnList(com.netflix.astyanax.model.ColumnList) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) RowQuery(com.netflix.astyanax.query.RowQuery) Rows(com.netflix.astyanax.model.Rows)

Example 12 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method getRetryBackoffStrategy.

private static RetryBackoffStrategy getRetryBackoffStrategy(String desc) throws PermanentBackendException {
    if (null == desc)
        return null;
    String[] tokens = desc.split(",");
    String policyClassName = tokens[0];
    int argCount = tokens.length - 1;
    Integer[] args = new Integer[argCount];
    for (int i = 1; i < tokens.length; i++) {
        args[i - 1] = Integer.valueOf(tokens[i]);
    }
    try {
        RetryBackoffStrategy rbs = instantiate(policyClassName, args, desc);
        log.debug("Instantiated RetryBackoffStrategy object {} from config string \"{}\"", rbs, desc);
        return rbs;
    } catch (Exception e) {
        throw new PermanentBackendException("Failed to instantiate Astyanax RetryBackoffStrategy implementation", e);
    }
}
Also used : ExponentialRetryBackoffStrategy(com.netflix.astyanax.connectionpool.impl.ExponentialRetryBackoffStrategy) RetryBackoffStrategy(com.netflix.astyanax.connectionpool.RetryBackoffStrategy) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 13 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method getRetryPolicy.

private static RetryPolicy getRetryPolicy(String serializedRetryPolicy) throws BackendException {
    String[] tokens = serializedRetryPolicy.split(",");
    String policyClassName = tokens[0];
    int argCount = tokens.length - 1;
    Integer[] args = new Integer[argCount];
    for (int i = 1; i < tokens.length; i++) {
        args[i - 1] = Integer.valueOf(tokens[i]);
    }
    try {
        RetryPolicy rp = instantiate(policyClassName, args, serializedRetryPolicy);
        log.debug("Instantiated RetryPolicy object {} from config string \"{}\"", rp, serializedRetryPolicy);
        return rp;
    } catch (Exception e) {
        throw new PermanentBackendException("Failed to instantiate Astyanax Retry Policy class", e);
    }
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) RetryPolicy(com.netflix.astyanax.retry.RetryPolicy) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 14 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method clearStorage.

@Override
public void clearStorage() throws BackendException {
    try {
        Cluster cluster = clusterContext.getClient();
        Keyspace ks = cluster.getKeyspace(keySpaceName);
        // everything up, so first invocation would always fail as Keyspace doesn't yet exist.
        if (ks == null)
            return;
        if (this.storageConfig.get(GraphDatabaseConfiguration.DROP_ON_CLEAR)) {
            ks.dropKeyspace();
        } else {
            final KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(keySpaceName);
            if (keyspaceDefinition == null) {
                return;
            }
            for (final ColumnFamilyDefinition cf : keyspaceDefinition.getColumnFamilyList()) {
                ks.truncateColumnFamily(new ColumnFamily<>(cf.getName(), null, null));
            }
        }
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Keyspace(com.netflix.astyanax.Keyspace) Cluster(com.netflix.astyanax.Cluster) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 15 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException 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) {
            throw new PermanentBackendException("Could not remove: " + status);
        }
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Aggregations

PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)29 IOException (java.io.IOException)12 BackendException (org.janusgraph.diskstorage.BackendException)9 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)9 UncheckedIOException (java.io.UncheckedIOException)8 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)7 Map (java.util.Map)5 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)5 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 KeeperException (org.apache.zookeeper.KeeperException)4 Rows (com.netflix.astyanax.model.Rows)3 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)3 BiMap (com.google.common.collect.BiMap)2 Keyspace (com.netflix.astyanax.Keyspace)2 ColumnFamilyDefinition (com.netflix.astyanax.ddl.ColumnFamilyDefinition)2 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)2 RowSliceQuery (com.netflix.astyanax.query.RowSliceQuery)2 ByteBuffer (java.nio.ByteBuffer)2 Duration (java.time.Duration)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2