Search in sources :

Example 1 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testCheckLocksFailsWithSeniorClaimsByOthers.

/**
 * If the checker reads its own lock column preceeded by a lock column from
 * another rid with an earlier timestamp and the timestamps on both columns
 * are unexpired, then the checker must throw a TemporaryLockingException.
 *
 * @throws InterruptedException shouldn't happen
 * @throws StorageException     shouldn't happen (we expect a TemporaryLockingException but
 *                              we catch and swallow it)
 */
@Test
public void testCheckLocksFailsWithSeniorClaimsByOthers() throws InterruptedException, StorageException {
    // Make a pre-existing valid lock by some other tx (written by another process)
    StaticBuffer otherSeniorLockCol = codec.toLockCol(currentTimeNS, otherLockRid);
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    // Expect checker to fetch locks for defaultTx; return just our own lock (not the other guy's)
    StaticBuffer ownJuniorLockCol = codec.toLockCol(currentTimeNS, defaultLockRid);
    ConsistentKeyLockStatus ownJuniorLS = makeStatusNow();
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, ownJuniorLS));
    currentTimeNS += TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
    // Return defaultTx's lock in a map when requested
    expect(times.sleepUntil(ownJuniorLS.getWriteTimestamp(TimeUnit.NANOSECONDS) + defaultWaitNS)).andReturn(currentTimeNS);
    // When the checker slices the store, return the senior lock col by a
    // foreign tx and the junior lock col by defaultTx (in that order)
    recordLockGetSlice(ImmutableList.<Entry>of(new StaticBufferEntry(otherSeniorLockCol, defaultLockVal), new StaticBufferEntry(ownJuniorLockCol, defaultLockVal)));
    ctrl.replay();
    TemporaryLockingException tle = null;
    try {
        locker.checkLocks(defaultTx);
    } catch (TemporaryLockingException e) {
        tle = e;
    }
    assertNotNull(tle);
}
Also used : 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 2 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testDeleteLocksInSimplestCase.

/**
 * Delete a single lock without any timeouts, errors, etc.
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testDeleteLocksInSimplestCase() throws StorageException {
    // Setup a LockStatus for defaultLockID
    final ConsistentKeyLockStatus lockStatus = makeStatusNow();
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    @SuppressWarnings("serial") Map<KeyColumn, ConsistentKeyLockStatus> expectedMap = new HashMap<KeyColumn, ConsistentKeyLockStatus>() {

        {
            put(defaultLockID, lockStatus);
        }
    };
    expect(lockState.getLocksForTx(defaultTx)).andReturn(expectedMap);
    StaticBuffer del = codec.toLockCol(lockStatus.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid);
    expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
    store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(Arrays.asList(del)), eq(defaultTx));
    expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) HashMap(java.util.HashMap) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) Test(org.junit.Test)

Example 3 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testDeleteLocksSkipsToNextLockOnPermanentStorageException.

/**
 * Same as
 * {@link #testDeleteLocksSkipsToNextLockAfterMaxTemporaryStorageExceptions()}
 * , except instead of exceeding the temporary exception retry count on a
 * lock, that lock throws a single permanent exception.
 *
 * @throws StorageException shoudn't happen
 */
@Test
public void testDeleteLocksSkipsToNextLockOnPermanentStorageException() 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 PermanentStorageException("Storage cluster has been destroyed by a tornado"));
    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) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Example 4 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testCheckLocksSucceedsWithSeniorAndJuniorClaimsBySelf.

/**
 * If the checker retrieves a timestamp-ordered list of columns, where the
 * list starts with an unbroken series of columns with the checker's rid but
 * differing timestamps, then consider the lock successfully checked if the
 * checker's expected timestamp occurs anywhere in that series of columns.
 * <p/>
 * This relaxation of the normal checking rules only triggers when either
 * writeLock(...) issued mutate calls that appeared to fail client-side but
 * which actually succeeded (e.g. hinted handoff or timeout)
 *
 * @throws InterruptedException shouldn't happen
 * @throws StorageException     shouldn't happen
 */
@Test
public void testCheckLocksSucceedsWithSeniorAndJuniorClaimsBySelf() throws InterruptedException, StorageException {
    // Setup three lock columns differing only in timestamp
    StaticBuffer myFirstLockCol = codec.toLockCol(currentTimeNS, defaultLockRid);
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    StaticBuffer mySecondLockCol = codec.toLockCol(currentTimeNS, defaultLockRid);
    ConsistentKeyLockStatus mySecondLS = makeStatusNow();
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    StaticBuffer myThirdLockCol = codec.toLockCol(currentTimeNS, defaultLockRid);
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, mySecondLS));
    // Return defaultTx's second lock in a map when requested
    currentTimeNS += TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
    expect(times.sleepUntil(mySecondLS.getWriteTimestamp(TimeUnit.NANOSECONDS) + defaultWaitNS)).andReturn(currentTimeNS);
    // When the checker slices the store, return the senior lock col by a
    // foreign tx and the junior lock col by defaultTx (in that order)
    recordLockGetSlice(ImmutableList.<Entry>of(new StaticBufferEntry(myFirstLockCol, defaultLockVal), new StaticBufferEntry(mySecondLockCol, defaultLockVal), new StaticBufferEntry(myThirdLockCol, defaultLockVal)));
    ctrl.replay();
    locker.checkLocks(defaultTx);
}
Also used : 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 5 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testCheckLocksSucceedsWithJuniorClaimsByOthers.

/**
 * When the checker retrieves its own lock column followed by a lock column
 * with a later timestamp (both with unexpired timestamps), it should
 * consider the lock successfully checked.
 *
 * @throws InterruptedException shouldn't happen
 * @throws StorageException     shouldn't happen
 */
@Test
public void testCheckLocksSucceedsWithJuniorClaimsByOthers() throws InterruptedException, StorageException {
    // Expect checker to fetch locks for defaultTx; return just our own lock (not the other guy's)
    StaticBuffer ownSeniorLockCol = codec.toLockCol(currentTimeNS, defaultLockRid);
    ConsistentKeyLockStatus ownSeniorLS = makeStatusNow();
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    // Make junior lock
    StaticBuffer otherJuniorLockCol = codec.toLockCol(currentTimeNS, otherLockRid);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, ownSeniorLS));
    currentTimeNS += TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
    // Return defaultTx's lock in a map when requested
    expect(times.sleepUntil(ownSeniorLS.getWriteTimestamp(TimeUnit.NANOSECONDS) + defaultWaitNS)).andReturn(currentTimeNS);
    // When the checker slices the store, return the senior lock col by a
    // foreign tx and the junior lock col by defaultTx (in that order)
    recordLockGetSlice(ImmutableList.<Entry>of(new StaticBufferEntry(ownSeniorLockCol, defaultLockVal), new StaticBufferEntry(otherJuniorLockCol, defaultLockVal)));
    ctrl.replay();
    locker.checkLocks(defaultTx);
}
Also used : 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)

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