Search in sources :

Example 11 with Entry

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method testDeleteLocksOnTwoLocks.

/**
 * Delete two locks without any timeouts, errors, etc.
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testDeleteLocksOnTwoLocks() throws StorageException {
    ConsistentKeyLockStatus defaultLS = makeStatusNow();
    currentTimeNS++;
    ConsistentKeyLockStatus otherLS = makeStatusNow();
    currentTimeNS++;
    // Expect a call for defaultTx's locks and return two
    Map<KeyColumn, ConsistentKeyLockStatus> expectedMap = Maps.newLinkedHashMap();
    expectedMap.put(defaultLockID, defaultLS);
    expectedMap.put(otherLockID, otherLS);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(expectedMap);
    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));
    expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
    dels = ImmutableList.of(codec.toLockCol(otherLS.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid));
    expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
    store.mutate(eq(otherLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
    expect(mediator.unlock(otherLockID, defaultTx)).andReturn(true);
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) 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 12 with Entry

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method recordExceptionLockWrite.

private StaticBuffer recordExceptionLockWrite(long duration, TimeUnit tu, StaticBuffer del, Throwable t) throws StorageException {
    expect(times.getApproxNSSinceEpoch()).andReturn(++currentTimeNS);
    StaticBuffer lockCol = codec.toLockCol(currentTimeNS, 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(defaultTx));
    expectLastCall().andThrow(t);
    currentTimeNS += TimeUnit.NANOSECONDS.convert(duration, tu);
    expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
    return 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)

Example 13 with Entry

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method testDeleteLocksIdempotence.

/**
 * When delete is called multiple times with no intervening write or check
 * calls, all calls after the first should have no effect.
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testDeleteLocksIdempotence() throws StorageException {
    // Setup a LockStatus for defaultLockID
    ConsistentKeyLockStatus lockStatus = makeStatusNow();
    currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, lockStatus)));
    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);
    // lockState.release(defaultTx, defaultLockID);
    ctrl.replay();
    locker.deleteLocks(defaultTx);
    ctrl.verify();
    ctrl.reset();
    expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.<KeyColumn, ConsistentKeyLockStatus>of()));
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) 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 14 with Entry

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry 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)

Example 15 with Entry

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method testDeleteLocksDeletesUncheckedLocks.

/**
 * Deletion should remove previously written locks regardless of whether
 * they were ever checked; this method fakes and verifies deletion on a
 * single unchecked lock
 *
 * @throws StorageException shouldn't happen
 */
@Test
public void testDeleteLocksDeletesUncheckedLocks() throws StorageException {
    ConsistentKeyLockStatus defaultLS = makeStatusNow();
    assertFalse(defaultLS.isChecked());
    currentTimeNS++;
    // Expect a call for defaultTx's locks and the checked one
    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));
    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) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Aggregations

Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)18 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)14 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)10 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)8 Test (org.junit.Test)7 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)5 HashMap (java.util.HashMap)5 ByteBuffer (java.nio.ByteBuffer)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)3 ByteBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.ByteBufferEntry)3 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)3 KeyColumn (com.thinkaurelius.titan.diskstorage.util.KeyColumn)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)2 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)2 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)2 StaticByteBuffer (com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer)2 List (java.util.List)2