Search in sources :

Example 56 with BackendException

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);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 57 with BackendException

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);
        }
    }
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 58 with BackendException

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();
        }
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) JanusGraphException(org.janusgraph.core.JanusGraphException) SchemaViolationException(org.janusgraph.core.SchemaViolationException) NoSuchElementException(java.util.NoSuchElementException) BackendException(org.janusgraph.diskstorage.BackendException) ReadOnlyTransactionException(org.janusgraph.core.ReadOnlyTransactionException) BackendException(org.janusgraph.diskstorage.BackendException)

Example 59 with BackendException

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);
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 60 with BackendException

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);
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Test(org.junit.jupiter.api.Test)

Aggregations

BackendException (org.janusgraph.diskstorage.BackendException)62 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)26 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)18 JanusGraphException (org.janusgraph.core.JanusGraphException)17 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)16 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)16 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Map (java.util.Map)12 Duration (java.time.Duration)11 HashMap (java.util.HashMap)11 Configuration (org.janusgraph.diskstorage.configuration.Configuration)11 Entry (org.janusgraph.diskstorage.Entry)10 Test (org.junit.jupiter.api.Test)10 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)9 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)9 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)9 IOException (java.io.IOException)8 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)8 Preconditions (com.google.common.base.Preconditions)6