Search in sources :

Example 11 with StorageException

use of com.thinkaurelius.titan.diskstorage.StorageException in project titan by thinkaurelius.

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 StorageException shouldn't happen
 */
@Test
public void testWriteLockThrowsExceptionAfterMaxStoreTimeouts() throws StorageException {
    expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
    recordSuccessfulLocalLock();
    StaticBuffer firstCol = recordSuccessfulLockWrite(5, TimeUnit.SECONDS, null).col;
    StaticBuffer secondCol = recordSuccessfulLockWrite(5, TimeUnit.SECONDS, firstCol).col;
    StaticBuffer thirdCol = recordSuccessfulLockWrite(5, TimeUnit.SECONDS, secondCol).col;
    recordSuccessfulLockDelete(1, TimeUnit.NANOSECONDS, thirdCol);
    recordSuccessfulLocalUnlock();
    ctrl.replay();
    StorageException expected = null;
    try {
        // SUT
        locker.writeLock(defaultLockID, defaultTx);
    } catch (TemporaryStorageException e) {
        expected = e;
    }
    assertNotNull(expected);
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) Test(org.junit.Test)

Example 12 with StorageException

use of com.thinkaurelius.titan.diskstorage.StorageException in project titan by thinkaurelius.

the class KCVSConfiguration method getConfigurationProperty.

/**
 * Reads the configuration property for this StoreManager
 *
 * @param key Key identifying the configuration property
 * @return Value stored for the key or null if the configuration property has not (yet) been defined.
 * @throws StorageException
 */
public String getConfigurationProperty(final String key) throws StorageException {
    StaticBuffer column = string2StaticBuffer(key);
    final KeySliceQuery query = new KeySliceQuery(rowKey, column, ByteBufferUtil.nextBiggerBuffer(column), false);
    StaticBuffer result = BackendOperation.execute(new Callable<StaticBuffer>() {

        @Override
        public StaticBuffer call() throws Exception {
            StoreTransaction txh = null;
            try {
                txh = manager.beginTransaction(new StoreTxConfig(ConsistencyLevel.KEY_CONSISTENT));
                List<Entry> entries = store.getSlice(query, txh);
                if (entries.isEmpty())
                    return null;
                return entries.get(0).getValue();
            } finally {
                if (txh != null)
                    txh.commit();
            }
        }

        @Override
        public String toString() {
            return "getConfiguration";
        }
    }, maxOperationWaitTime);
    if (result == null)
        return null;
    return staticBuffer2String(result);
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) StorageException(com.thinkaurelius.titan.diskstorage.StorageException)

Example 13 with StorageException

use of com.thinkaurelius.titan.diskstorage.StorageException in project titan by thinkaurelius.

the class StandardTitanGraph method newTransaction.

public StandardTitanTx newTransaction(TransactionConfiguration configuration) {
    if (!isOpen)
        ExceptionFactory.graphShutdown();
    try {
        IndexSerializer.IndexInfoRetriever retriever = indexSerializer.getIndexInforRetriever();
        StandardTitanTx tx = new StandardTitanTx(this, configuration, backend.beginTransaction(configuration, retriever));
        retriever.setTransaction(tx);
        return tx;
    } catch (StorageException e) {
        throw new TitanException("Could not start new transaction", e);
    }
}
Also used : StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) StorageException(com.thinkaurelius.titan.diskstorage.StorageException)

Example 14 with StorageException

use of com.thinkaurelius.titan.diskstorage.StorageException in project titan by thinkaurelius.

the class StandardIDPool method renewBuffer.

private void renewBuffer() {
    Preconditions.checkArgument(bufferNextID == BUFFER_EMPTY, bufferNextID);
    Preconditions.checkArgument(bufferMaxID == BUFFER_EMPTY, bufferMaxID);
    try {
        long[] idblock = idAuthority.getIDBlock(partitionID);
        bufferNextID = idblock[0];
        bufferMaxID = idblock[1];
        Preconditions.checkArgument(bufferNextID > 0, bufferNextID);
        Preconditions.checkArgument(bufferMaxID > bufferNextID, bufferMaxID);
    } catch (StorageException e) {
        throw new TitanException("Could not acquire new ID block from storage", e);
    } catch (IDPoolExhaustedException e) {
        bufferNextID = BUFFER_POOL_EXHAUSTION;
        bufferMaxID = BUFFER_POOL_EXHAUSTION;
    }
}
Also used : TitanException(com.thinkaurelius.titan.core.TitanException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException)

Example 15 with StorageException

use of com.thinkaurelius.titan.diskstorage.StorageException in project titan by thinkaurelius.

the class BackendOperation method execute.

public static final <V> V execute(Callable<V> exe, int maxRetryAttempts, long retryWaittime) throws TitanException {
    Preconditions.checkArgument(maxRetryAttempts > 0, "Retry attempts must be positive");
    Preconditions.checkArgument(retryWaittime >= 0, "Retry wait time must be non-negative");
    int retryAttempts = 0;
    StorageException lastException = null;
    do {
        try {
            return exe.call();
        } catch (StorageException e) {
            if (e instanceof TemporaryStorageException)
                lastException = e;
            else
                // Its permanent
                throw new TitanException("Permanent exception during backend operation", e);
        } catch (Throwable e) {
            throw new TitanException("Unexpected exception during backend operation", e);
        }
        // Wait and retry
        retryAttempts++;
        Preconditions.checkNotNull(lastException);
        if (retryAttempts < maxRetryAttempts) {
            long waitTime = Math.round(retryWaittime + ((Math.random() * WAITTIME_PERTURBATION_PERCENTAGE - WAITTIME_PERTURBATION_PERCENTAGE_HALF) * retryWaittime));
            Preconditions.checkArgument(waitTime >= 0, "Invalid wait time: %s", waitTime);
            log.info("Temporary storage exception during backend operation [{}]. Attempting incremental retry", exe.toString(), lastException);
            try {
                Thread.sleep(waitTime);
            } catch (InterruptedException r) {
                throw new TitanException("Interrupted while waiting to retry failed backend operation", r);
            }
        }
    } while (retryAttempts < maxRetryAttempts);
    throw new TitanException("Could not successfully complete backend operation due to repeated temporary exceptions after " + maxRetryAttempts + " attempts", lastException);
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TitanException(com.thinkaurelius.titan.core.TitanException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException)

Aggregations

StorageException (com.thinkaurelius.titan.diskstorage.StorageException)29 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)22 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)20 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)9 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)9 TException (org.apache.thrift.TException)9 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)8 ArrayList (java.util.ArrayList)7 Cassandra (org.apache.cassandra.thrift.Cassandra)7 TitanException (com.thinkaurelius.titan.core.TitanException)6 NotFoundException (org.apache.cassandra.thrift.NotFoundException)6 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)6 SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)5 IOException (java.io.IOException)4 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 CfDef (org.apache.cassandra.thrift.CfDef)4 ColumnParent (org.apache.cassandra.thrift.ColumnParent)4 KsDef (org.apache.cassandra.thrift.KsDef)4 SliceRange (org.apache.cassandra.thrift.SliceRange)4