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);
}
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);
}
}
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();
}
};
}
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);
}
}
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);
}
Aggregations