use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class KCVSLog method writeSetting.
private void writeSetting(String identifier, final StaticBuffer column, long value) {
final StaticBuffer key = getSettingKey(identifier);
final Entry add = StaticArrayEntry.of(column, BufferUtil.getLongBuffer(value));
Boolean status = BackendOperation.execute(new BackendOperation.Transactional<Boolean>() {
@Override
public Boolean call(StoreTransaction txh) throws BackendException {
store.mutate(key, Collections.singletonList(add), KeyColumnValueStore.NO_DELETIONS, txh);
return Boolean.TRUE;
}
@Override
public String toString() {
return "writingLogSetting";
}
}, this, times, maxWriteTime);
Preconditions.checkState(status);
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class ConsistentKeyLocker method deleteSingleLock.
@Override
protected void deleteSingleLock(KeyColumn kc, ConsistentKeyLockStatus ls, StoreTransaction tx) {
List<StaticBuffer> deletions = Collections.singletonList(serializer.toLockCol(ls.getWriteTimestamp(), rid, times));
for (int i = 0; i < lockRetryCount; i++) {
StoreTransaction newTx = null;
try {
newTx = overrideTimestamp(tx, times.getTime());
store.mutate(serializer.toLockKey(kc.getKey(), kc.getColumn()), Collections.emptyList(), deletions, newTx);
newTx.commit();
newTx = null;
return;
} catch (TemporaryBackendException e) {
log.warn("Temporary storage exception while deleting lock", e);
// don't return -- iterate and retry
} catch (BackendException e) {
log.error("Storage exception while deleting lock", e);
// give up on this lock
return;
} finally {
rollbackIfNotNull(newTx);
}
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class StandardJanusGraphTx method commit.
/*
* ------------------------------------ Transaction State ------------------------------------
*/
@Override
public synchronized void commit() {
Preconditions.checkArgument(isOpen(), "The transaction has already been closed");
boolean success = false;
if (null != config.getGroupName()) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "commit").inc();
}
try {
if (hasModifications()) {
graph.commit(addedRelations.getAll(), deletedRelations.values(), this);
} else {
txHandle.commit();
}
success = true;
} catch (Exception e) {
try {
txHandle.rollback();
} catch (BackendException e1) {
throw new JanusGraphException("Could not rollback after a failed commit", e);
}
throw new JanusGraphException("Could not commit transaction due to exception during persistence", e);
} finally {
releaseTransaction();
if (null != config.getGroupName() && !success) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "commit.exceptions").inc();
}
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method expectDeleteLock.
private void expectDeleteLock(KeyColumn lockID, StaticBuffer lockKey, ConsistentKeyLockStatus lockStatus, BackendException... backendFailures) throws BackendException {
List<StaticBuffer> deletions = ImmutableList.of(codec.toLockCol(lockStatus.getWriteTimestamp(), defaultLockRid, times));
expect(times.getTime()).andReturn(currentTimeNS);
store.mutate(eq(lockKey), eq(ImmutableList.of()), eq(deletions), eq(defaultTx));
int backendExceptionsThrown = 0;
for (BackendException e : backendFailures) {
expectLastCall().andThrow(e);
if (e instanceof PermanentBackendException) {
break;
}
backendExceptionsThrown++;
int maxTemporaryStorageExceptions = 3;
if (backendExceptionsThrown < maxTemporaryStorageExceptions) {
expect(times.getTime()).andReturn(currentTimeNS);
store.mutate(eq(lockKey), eq(ImmutableList.of()), eq(deletions), eq(defaultTx));
}
}
expect(mediator.unlock(lockID, defaultTx)).andReturn(true);
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testWriteLockThrowsExceptionAfterMaxStoreTimeouts.
/**
* Test locker when all three attempts to write a lock succeed but take
* longer than the wait limit. We expect the locker to delete all three
* columns that it wrote and locally unlock the KeyColumn, then emit an
* exception.
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testWriteLockThrowsExceptionAfterMaxStoreTimeouts() throws BackendException {
expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
recordSuccessfulLocalLock();
StaticBuffer firstCol = recordSuccessfulLockWrite(5, ChronoUnit.SECONDS, null).col;
StaticBuffer secondCol = recordSuccessfulLockWrite(5, ChronoUnit.SECONDS, firstCol).col;
StaticBuffer thirdCol = recordSuccessfulLockWrite(5, ChronoUnit.SECONDS, secondCol).col;
recordSuccessfulLockDelete(thirdCol);
recordSuccessfulLocalUnlock();
ctrl.replay();
BackendException expected = null;
try {
// SUT
locker.writeLock(defaultLockID, defaultTx);
} catch (TemporaryBackendException e) {
expected = e;
}
assertNotNull(expected);
}
Aggregations