use of org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable in project janusgraph by JanusGraph.
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.of()), eq(ImmutableList.of(expiredLockCol.getColumn())), anyObject(StoreTransaction.class));
ctrl.replay();
del.run();
}
use of org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable in project janusgraph by JanusGraph.
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 timeIncremement = 1L;
final Instant timeStart = Instant.EPOCH;
final Instant timeCutoff = timeStart.plusMillis(expiredCount * timeIncremement);
ImmutableList.Builder<Entry> locksBuilder = ImmutableList.builder();
ImmutableList.Builder<Entry> deletionBuilder = ImmutableList.builder();
for (int i = 0; i < lockCount; i++) {
final Instant ts = timeStart.plusMillis(timeIncremement * i);
Entry lock = StaticArrayEntry.of(codec.toLockCol(ts, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
if (ts.isBefore(timeCutoff)) {
deletionBuilder.add(lock);
}
locksBuilder.add(lock);
}
EntryList locks = StaticArrayEntryList.of(locksBuilder.build());
EntryList deletions = StaticArrayEntryList.of(deletionBuilder.build());
assertTrue(expiredCount == deletions.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.of()), eq(columnsOf(deletions)), anyObject(StoreTransaction.class));
ctrl.replay();
del.run();
}
use of org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable in project janusgraph by JanusGraph.
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();
}
use of org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable in project janusgraph by JanusGraph.
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);
}
}
use of org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable in project janusgraph by JanusGraph.
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);
}
}
Aggregations