Search in sources :

Example 1 with StandardLockCleanerRunnable

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

the class LockCleanerRunnableTest method testDeletionWithExpiredAndValidLocks.

/**
     * Test the cleaner against a set of locks where some locks have timestamps
     * before the cutoff and others have timestamps after the cutoff. One lock
     * has a timestamp equal to the cutoff.
     */
@Test
public void testDeletionWithExpiredAndValidLocks() throws BackendException {
    final int lockCount = 10;
    final int expiredCount = 3;
    assertTrue(expiredCount + 2 <= lockCount);
    final long timeIncr = 1L;
    final Instant timeStart = Instant.EPOCH;
    final Instant timeCutoff = timeStart.plusMillis(expiredCount * timeIncr);
    ImmutableList.Builder<Entry> locksBuilder = ImmutableList.builder();
    ImmutableList.Builder<Entry> delsBuilder = ImmutableList.builder();
    for (int i = 0; i < lockCount; i++) {
        final Instant ts = timeStart.plusMillis(timeIncr * i);
        Entry lock = StaticArrayEntry.of(codec.toLockCol(ts, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
        if (ts.isBefore(timeCutoff)) {
            delsBuilder.add(lock);
        }
        locksBuilder.add(lock);
    }
    EntryList locks = StaticArrayEntryList.of(locksBuilder.build());
    EntryList dels = StaticArrayEntryList.of(delsBuilder.build());
    assertTrue(expiredCount == dels.size());
    del = new StandardLockCleanerRunnable(store, kc, tx, codec, timeCutoff, TimestampProviders.MILLI);
    expect(store.getSlice(eq(ksq), eq(tx))).andReturn(locks);
    store.mutate(eq(key), eq(ImmutableList.<Entry>of()), eq(columnsOf(dels)), anyObject(StoreTransaction.class));
    ctrl.replay();
    del.run();
}
Also used : StandardLockCleanerRunnable(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(com.thinkaurelius.titan.diskstorage.Entry) ImmutableList(com.google.common.collect.ImmutableList) StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) Test(org.junit.Test)

Example 2 with StandardLockCleanerRunnable

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

the class LockCleanerRunnableTest method testDeleteSingleLock.

/**
     * Simplest case test of the lock cleaner.
     */
@Test
public void testDeleteSingleLock() throws BackendException {
    Instant now = Instant.ofEpochMilli(1L);
    Entry expiredLockCol = StaticArrayEntry.of(codec.toLockCol(now, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    EntryList expiredSingleton = StaticArrayEntryList.of(expiredLockCol);
    now = now.plusMillis(1);
    del = new StandardLockCleanerRunnable(store, kc, tx, codec, now, TimestampProviders.MILLI);
    expect(store.getSlice(eq(ksq), eq(tx))).andReturn(expiredSingleton);
    store.mutate(eq(key), eq(ImmutableList.<Entry>of()), eq(ImmutableList.<StaticBuffer>of(expiredLockCol.getColumn())), anyObject(StoreTransaction.class));
    ctrl.replay();
    del.run();
}
Also used : StandardLockCleanerRunnable(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(com.thinkaurelius.titan.diskstorage.Entry) StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) Test(org.junit.Test)

Example 3 with StandardLockCleanerRunnable

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

the class LockCleanerServiceTest method testCleanCooldownElapses.

@Test
public void testCleanCooldownElapses() throws InterruptedException {
    final Instant cutoff = Instant.ofEpochMilli(1L);
    Duration wait = Duration.ofMillis(500L);
    svc = new StandardLockCleanerService(store, codec, exec, wait, TimestampProviders.MILLI);
    expect(exec.submit(eq(new StandardLockCleanerRunnable(store, kc, tx, codec, cutoff, TimestampProviders.MILLI)))).andReturn(null);
    expect(exec.submit(eq(new StandardLockCleanerRunnable(store, kc, tx, codec, cutoff.plusMillis(1), TimestampProviders.MILLI)))).andReturn(null);
    ctrl.replay();
    for (int i = 0; i < 2; i++) {
        svc.clean(kc, cutoff, tx);
    }
    TimestampProviders.MILLI.sleepFor(wait.plusMillis(1));
    for (int i = 0; i < 2; i++) {
        svc.clean(kc, cutoff.plusMillis(1), tx);
    }
}
Also used : StandardLockCleanerService(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerService) StandardLockCleanerRunnable(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Instant(java.time.Instant) Duration(java.time.Duration) Test(org.junit.Test)

Example 4 with StandardLockCleanerRunnable

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

the class LockCleanerRunnableTest method testPreservesLocksAtOrAfterCutoff.

/**
     * Locks with timestamps equal to or numerically greater than the cleaner
     * cutoff timestamp must be preserved. Test that the cleaner reads locks by
     * slicing the store and then does <b>not</b> attempt to write.
     */
@Test
public void testPreservesLocksAtOrAfterCutoff() throws BackendException {
    final Instant cutoff = Instant.ofEpochMilli(10L);
    Entry currentLock = StaticArrayEntry.of(codec.toLockCol(cutoff, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    Entry futureLock = StaticArrayEntry.of(codec.toLockCol(cutoff.plusMillis(1), defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    EntryList locks = StaticArrayEntryList.of(currentLock, futureLock);
    // Don't increment cutoff: lockCol is exactly at the cutoff timestamp
    del = new StandardLockCleanerRunnable(store, kc, tx, codec, cutoff, TimestampProviders.MILLI);
    expect(store.getSlice(eq(ksq), eq(tx))).andReturn(locks);
    ctrl.replay();
    del.run();
}
Also used : StandardLockCleanerRunnable(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(com.thinkaurelius.titan.diskstorage.Entry) Instant(java.time.Instant) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) Test(org.junit.Test)

Example 5 with StandardLockCleanerRunnable

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

the class LockCleanerServiceTest method testCleanCooldownBlocksRapidRequests.

@Test
public void testCleanCooldownBlocksRapidRequests() {
    final Instant cutoff = Instant.ofEpochMilli(1L);
    svc = new StandardLockCleanerService(store, codec, exec, Duration.ofSeconds(60L), TimestampProviders.MILLI);
    expect(exec.submit(eq(new StandardLockCleanerRunnable(store, kc, tx, codec, cutoff, TimestampProviders.MILLI)))).andReturn(null);
    ctrl.replay();
    for (int i = 0; i < 500; i++) {
        svc.clean(kc, cutoff, tx);
    }
}
Also used : StandardLockCleanerService(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerService) StandardLockCleanerRunnable(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Instant(java.time.Instant) Test(org.junit.Test)

Aggregations

StandardLockCleanerRunnable (com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable)5 Instant (java.time.Instant)5 Test (org.junit.Test)5 Entry (com.thinkaurelius.titan.diskstorage.Entry)3 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)3 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)2 StandardLockCleanerService (com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerService)2 ImmutableList (com.google.common.collect.ImmutableList)1 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)1 Duration (java.time.Duration)1