Search in sources :

Example 6 with ConsistentKeyLockStatus

use of com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method testDeleteLocksRetriesOnTemporaryStorageException.

/**
 * Lock deletion should retry if the first store mutation throws a temporary
 * exception.
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testDeleteLocksRetriesOnTemporaryStorageException() throws StorageException {
    ConsistentKeyLockStatus defaultLS = makeStatusNow();
    currentTimeNS++;
    expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, defaultLS)));
    List<StaticBuffer> dels = ImmutableList.of(codec.toLockCol(defaultLS.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid));
    expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
    store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
    expectLastCall().andThrow(new TemporaryStorageException("Storage cluster is backlogged"));
    expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
    store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
    expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
    // lockState.release(defaultTx, defaultLockID);
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Example 7 with ConsistentKeyLockStatus

use of com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method recordSuccessfulLockWrite.

private LockInfo recordSuccessfulLockWrite(StoreTransaction tx, long duration, TimeUnit tu, StaticBuffer del) throws StorageException {
    expect(times.getApproxNSSinceEpoch()).andReturn(++currentTimeNS);
    final long lockNS = currentTimeNS;
    StaticBuffer lockCol = codec.toLockCol(lockNS, defaultLockRid);
    Entry add = new StaticBufferEntry(lockCol, defaultLockVal);
    StaticBuffer k = eq(defaultLockKey);
    // assert null != add;
    final List<Entry> adds = eq(Arrays.<Entry>asList(add));
    // assert null != adds;
    final List<StaticBuffer> dels;
    if (null != del) {
        dels = eq(Arrays.<StaticBuffer>asList(del));
    } else {
        dels = eq(ImmutableList.<StaticBuffer>of());
    }
    store.mutate(k, adds, dels, eq(tx));
    currentTimeNS += TimeUnit.NANOSECONDS.convert(duration, tu);
    expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
    ConsistentKeyLockStatus status = new ConsistentKeyLockStatus(lockNS, TimeUnit.NANOSECONDS, lockNS + defaultExpireNS, TimeUnit.NANOSECONDS);
    return new LockInfo(lockNS, status, lockCol);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)

Example 8 with ConsistentKeyLockStatus

use of com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method testCheckLocksDiesOnPermanentStorageException.

/**
 * A single PermanentStorageException on getSlice() for a single lock is
 * sufficient to make the method return immediately (regardless of whether
 * other locks are waiting to be checked).
 *
 * @throws InterruptedException shouldn't happen
 * @throws StorageException     shouldn't happen
 */
@Test
public void testCheckLocksDiesOnPermanentStorageException() throws InterruptedException, StorageException {
    // Setup a LockStatus for defaultLockID
    ConsistentKeyLockStatus lockStatus = makeStatusNow();
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, lockStatus));
    expect(times.sleepUntil(lockStatus.getWriteTimestamp(TimeUnit.NANOSECONDS) + defaultWaitNS)).andReturn(currentTimeNS);
    // First and only getSlice call throws a PSE
    recordExceptionalLockGetSlice(new PermanentStorageException("Connection to storage cluster failed: peer is an IPv6 toaster"));
    ctrl.replay();
    PermanentStorageException pse = null;
    try {
        locker.checkLocks(defaultTx);
    } catch (PermanentStorageException e) {
        pse = e;
    }
    assertNotNull(pse);
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Example 9 with ConsistentKeyLockStatus

use of com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method testCheckLocksThrowsExceptionAfterMaxTemporaryStorageExceptions.

/**
 * The checker will throw a TemporaryStorageException if getSlice() throws
 * fails with a TemporaryStorageException as many times as there are
 * configured lock retries.
 *
 * @throws InterruptedException shouldn't happen
 * @throws StorageException     shouldn't happen
 */
@Test
public void testCheckLocksThrowsExceptionAfterMaxTemporaryStorageExceptions() throws InterruptedException, StorageException {
    // Setup a LockStatus for defaultLockID
    ConsistentKeyLockStatus lockStatus = makeStatusNow();
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, lockStatus));
    expect(times.sleepUntil(lockStatus.getWriteTimestamp(TimeUnit.NANOSECONDS) + defaultWaitNS)).andReturn(currentTimeNS);
    // Three successive getSlice calls, each throwing a distinct TSE
    recordExceptionalLockGetSlice(new TemporaryStorageException("Storage cluster is having me-time"));
    recordExceptionalLockGetSlice(new TemporaryStorageException("Storage cluster is in a dissociative fugue state"));
    recordExceptionalLockGetSlice(new TemporaryStorageException("Storage cluster has gone to Prague to find itself"));
    ctrl.replay();
    TemporaryStorageException tse = null;
    try {
        locker.checkLocks(defaultTx);
    } catch (TemporaryStorageException e) {
        tse = e;
    }
    assertNotNull(tse);
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Example 10 with ConsistentKeyLockStatus

use of com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method testCheckLocksInSimplestCase.

/**
 * Test a single checking a single lock under optimal conditions (no
 * timeouts, no errors)
 *
 * @throws StorageException     shouldn't happen
 * @throws InterruptedException shouldn't happen
 */
@Test
public void testCheckLocksInSimplestCase() throws StorageException, InterruptedException {
    // Fake a pre-existing lock
    final ConsistentKeyLockStatus ls = makeStatusNow();
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, ls));
    currentTimeNS += TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
    // Checker should compare the fake lock's timestamp to the current time
    expect(times.sleepUntil(ls.getWriteTimestamp(TimeUnit.NANOSECONDS) + defaultWaitNS)).andReturn(currentTimeNS);
    // Expect a store getSlice() and return the fake lock's column and value
    recordLockGetSliceAndReturnSingleEntry(new StaticBufferEntry(codec.toLockCol(ls.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid), defaultLockVal));
    ctrl.replay();
    locker.checkLocks(defaultTx);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Aggregations

ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)17 Test (org.junit.Test)16 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)15 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)13 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)8 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)4 KeyColumn (com.thinkaurelius.titan.diskstorage.util.KeyColumn)3 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)2 HashMap (java.util.HashMap)1