Search in sources :

Example 76 with StaticBuffer

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

the class ConsistentKeyLockerTest method testWriteLockRetriesOnTemporaryStorageException.

/**
 * Test the locker retries a lock write after the initial store mutation
 * fails with a {@link TemporaryStorageException}. The retry should both
 * attempt to write the and delete the failed mutation column.
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testWriteLockRetriesOnTemporaryStorageException() throws StorageException {
    TemporaryStorageException tse = new TemporaryStorageException("Storage cluster is waking up");
    expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
    recordSuccessfulLocalLock();
    StaticBuffer firstCol = recordExceptionLockWrite(1, TimeUnit.NANOSECONDS, null, tse);
    LockInfo secondLI = recordSuccessfulLockWrite(1, TimeUnit.NANOSECONDS, firstCol);
    recordSuccessfulLocalLock(secondLI.tsNS);
    lockState.take(eq(defaultTx), eq(defaultLockID), eq(secondLI.stat));
    ctrl.replay();
    // SUT
    locker.writeLock(defaultLockID, defaultTx);
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Test(org.junit.Test)

Example 77 with StaticBuffer

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

the class ConsistentKeyLockerTest method testWriteLockRetriesAfterOneStoreTimeout.

/**
 * Test locker when first attempt to write to the store takes too long (but
 * succeeds). Expected behavior is to call mutate on the store, adding a
 * column with a new timestamp and deleting the column with the old
 * (too-slow-to-write) timestamp.
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testWriteLockRetriesAfterOneStoreTimeout() throws StorageException {
    expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
    recordSuccessfulLocalLock();
    // too slow
    StaticBuffer firstCol = recordSuccessfulLockWrite(5, TimeUnit.SECONDS, null).col;
    // plenty fast
    LockInfo secondLI = recordSuccessfulLockWrite(1, TimeUnit.NANOSECONDS, firstCol);
    recordSuccessfulLocalLock(secondLI.tsNS);
    lockState.take(eq(defaultTx), eq(defaultLockID), eq(secondLI.stat));
    ctrl.replay();
    // SUT
    locker.writeLock(defaultLockID, defaultTx);
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Test(org.junit.Test)

Example 78 with StaticBuffer

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

the class ConsistentKeyLockerTest method testCheckLocksRetriesAfterSingleTemporaryStorageException.

/**
 * The checker should retry getSlice() in the face of a
 * TemporaryStorageException so long as the number of exceptional
 * getSlice()s is fewer than the lock retry count. The retry count applies
 * on a per-lock basis.
 *
 * @throws StorageException     shouldn't happen
 * @throws InterruptedException shouldn't happen
 */
@Test
public void testCheckLocksRetriesAfterSingleTemporaryStorageException() throws StorageException, InterruptedException {
    // Setup one lock column
    StaticBuffer lockCol = codec.toLockCol(currentTimeNS, defaultLockRid);
    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 getSlice will fail
    TemporaryStorageException tse = new TemporaryStorageException("Storage cluster will be right back");
    recordExceptionalLockGetSlice(tse);
    // Second getSlice will succeed
    recordLockGetSliceAndReturnSingleEntry(new StaticBufferEntry(lockCol, defaultLockVal));
    ctrl.replay();
    locker.checkLocks(defaultTx);
// TODO run again with two locks instead of one and show that the retry count applies on a per-lock basis
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Example 79 with StaticBuffer

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

the class ConsistentKeyLockerTest method testWriteLockDiesOnPermanentStorageException.

/**
 * Test that the first {@link PermanentStorageException} thrown by the
 * locker's store causes it to attempt to delete outstanding lock writes and
 * then emit the exception without retrying.
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testWriteLockDiesOnPermanentStorageException() throws StorageException {
    PermanentStorageException errOnFire = new PermanentStorageException("Storage cluster is on fire");
    expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
    recordSuccessfulLocalLock();
    StaticBuffer lockCol = recordExceptionLockWrite(1, TimeUnit.NANOSECONDS, null, errOnFire);
    recordSuccessfulLockDelete(1, TimeUnit.NANOSECONDS, lockCol);
    recordSuccessfulLocalUnlock();
    ctrl.replay();
    StorageException expected = null;
    try {
        // SUT
        locker.writeLock(defaultLockID, defaultTx);
    } catch (PermanentLockingException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertEquals(errOnFire, expected.getCause());
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) 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 80 with StaticBuffer

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

the class ConsistentKeyLockerTest method testDeleteLocksSkipsToNextLockAfterMaxTemporaryStorageExceptions.

/**
 * If lock deletion exceeds the temporary exception retry count when trying
 * to delete a lock, it should move onto the next lock rather than returning
 * and potentially leaving the remaining locks undeleted.
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testDeleteLocksSkipsToNextLockAfterMaxTemporaryStorageExceptions() 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 busy"));
    expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
    store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
    expectLastCall().andThrow(new TemporaryStorageException("Storage cluster is busier"));
    expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
    store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
    expectLastCall().andThrow(new TemporaryStorageException("Storage cluster has reached peak business"));
    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)

Aggregations

StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)92 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)16 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)15 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)14 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)13 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)13 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)12 HashMap (java.util.HashMap)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Entry (com.thinkaurelius.titan.diskstorage.Entry)10 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)10 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)9 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)8 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)7 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)6 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)6 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)6 Instant (java.time.Instant)6