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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations