Search in sources :

Example 6 with PermanentBackendException

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

the class BackendOperation method executeDirect.

public static <V> V executeDirect(Callable<V> exe, Duration totalWaitTime) throws BackendException {
    Preconditions.checkArgument(!totalWaitTime.isZero(), "Need to specify a positive waitTime: %s", totalWaitTime);
    long maxTime = System.currentTimeMillis() + totalWaitTime.toMillis();
    Duration waitTime = pertubTime(BASE_REATTEMPT_TIME);
    BackendException lastException;
    while (true) {
        try {
            return exe.call();
        } catch (final Throwable e) {
            // Find inner-most StorageException
            Throwable ex = e;
            BackendException storeEx = null;
            do {
                if (ex instanceof BackendException)
                    storeEx = (BackendException) ex;
            } while ((ex = ex.getCause()) != null);
            if (storeEx != null && storeEx instanceof TemporaryBackendException) {
                lastException = storeEx;
            } else if (e instanceof BackendException) {
                throw (BackendException) e;
            } else {
                throw new PermanentBackendException("Permanent exception while executing backend operation " + exe.toString(), e);
            }
        }
        // Wait and retry
        assert lastException != null;
        if (System.currentTimeMillis() + waitTime.toMillis() < maxTime) {
            log.info("Temporary exception during backend operation [" + exe.toString() + "]. Attempting backoff retry.", lastException);
            try {
                Thread.sleep(waitTime.toMillis());
            } catch (InterruptedException r) {
                // added thread interrupt signal to support traversal interruption
                Thread.currentThread().interrupt();
                throw new PermanentBackendException("Interrupted while waiting to retry failed backend operation", r);
            }
        } else {
            break;
        }
        waitTime = pertubTime(waitTime.multipliedBy(2));
    }
    throw new TemporaryBackendException("Could not successfully complete backend operation due to repeated temporary exceptions after " + totalWaitTime, lastException);
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Duration(java.time.Duration) BackendException(org.janusgraph.diskstorage.BackendException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 7 with PermanentBackendException

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

the class BerkeleyJEKeyValueStore method insert.

public void insert(StaticBuffer key, StaticBuffer value, StoreTransaction txh, boolean allowOverwrite) throws BackendException {
    Transaction tx = getTransaction(txh);
    try {
        OperationStatus status;
        log.trace("db={}, op=insert, tx={}", name, txh);
        if (allowOverwrite)
            status = db.put(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY));
        else
            status = db.putNoOverwrite(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY));
        if (status != OperationStatus.SUCCESS) {
            if (status == OperationStatus.KEYEXIST) {
                throw new PermanentBackendException("Key already exists on no-overwrite.");
            } else {
                throw new PermanentBackendException("Could not write entity, return status: " + status);
            }
        }
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 8 with PermanentBackendException

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

the class BerkeleyJEKeyValueStore method getSlice.

@Override
public RecordIterator<KeyValueEntry> getSlice(KVQuery query, StoreTransaction txh) throws BackendException {
    log.trace("beginning db={}, op=getSlice, tx={}", name, txh);
    final Transaction tx = getTransaction(txh);
    final StaticBuffer keyStart = query.getStart();
    final StaticBuffer keyEnd = query.getEnd();
    final KeySelector selector = query.getKeySelector();
    final List<KeyValueEntry> result = new ArrayList<>();
    final DatabaseEntry foundKey = keyStart.as(ENTRY_FACTORY);
    final DatabaseEntry foundData = new DatabaseEntry();
    try (final Cursor cursor = db.openCursor(tx, null)) {
        OperationStatus status = cursor.getSearchKeyRange(foundKey, foundData, getLockMode(txh));
        // 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, getLockMode(txh));
        }
    } catch (Exception e) {
        throw new PermanentBackendException(e);
    }
    log.trace("db={}, op=getSlice, tx={}, resultcount={}", name, txh, 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();
        }
    };
}
Also used : RecordIterator(org.janusgraph.diskstorage.util.RecordIterator) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) ArrayList(java.util.ArrayList) KeySelector(org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeySelector) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Iterator(java.util.Iterator) RecordIterator(org.janusgraph.diskstorage.util.RecordIterator) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) KeyValueEntry(org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)

Example 9 with PermanentBackendException

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

the class BerkeleyJETx method rollback.

@Override
public synchronized void rollback() throws BackendException {
    super.rollback();
    if (tx == null)
        return;
    if (log.isTraceEnabled())
        log.trace("{} rolled back", this.toString(), new TransactionClose(this.toString()));
    try {
        closeOpenIterators();
        tx.abort();
        tx = null;
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 10 with PermanentBackendException

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

the class AstyanaxKeyColumnValueStore method getKeys.

@Override
public KeyIterator getKeys(@Nullable SliceQuery sliceQuery, StoreTransaction txh) throws BackendException {
    if (storeManager.getPartitioner() != Partitioner.RANDOM)
        throw new PermanentBackendException("This operation is only allowed when random partitioner (md5 or murmur3) is used.");
    AllRowsQuery allRowsQuery = keyspace.prepareQuery(columnFamily).getAllRows();
    if (sliceQuery != null) {
        allRowsQuery.withColumnRange(sliceQuery.getSliceStart().asByteBuffer(), sliceQuery.getSliceEnd().asByteBuffer(), false, sliceQuery.getLimit());
    }
    Rows<ByteBuffer, ByteBuffer> result;
    try {
        /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
        OperationResult op = // pre-fetch that many rows at a time
        allRowsQuery.setRowLimit(storeManager.getPageSize()).setConcurrencyLevel(// one execution thread for fetching portion of rows
        1).setExceptionCallback(new ExceptionCallback() {

            private int retries = 0;

            @Override
            public boolean onException(ConnectionException e) {
                try {
                    // make 3 re-tries
                    return retries > 2;
                } finally {
                    retries++;
                }
            }
        }).execute();
        result = ((OperationResult<Rows<ByteBuffer, ByteBuffer>>) op).getResult();
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
    return new RowIterator(result.iterator(), sliceQuery);
}
Also used : AllRowsQuery(com.netflix.astyanax.query.AllRowsQuery) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) OperationResult(com.netflix.astyanax.connectionpool.OperationResult) ExceptionCallback(com.netflix.astyanax.ExceptionCallback) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) Rows(com.netflix.astyanax.model.Rows)

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