Search in sources :

Example 1 with StandardLockCleanerRunnable

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();
}
Also used : StandardLockCleanerRunnable(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(org.janusgraph.diskstorage.Entry) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) EntryList(org.janusgraph.diskstorage.EntryList) Test(org.junit.Test)

Example 2 with StandardLockCleanerRunnable

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();
}
Also used : StandardLockCleanerRunnable(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(org.janusgraph.diskstorage.Entry) ImmutableList(com.google.common.collect.ImmutableList) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) EntryList(org.janusgraph.diskstorage.EntryList) Test(org.junit.Test)

Example 3 with StandardLockCleanerRunnable

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();
}
Also used : StandardLockCleanerRunnable(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(org.janusgraph.diskstorage.Entry) Instant(java.time.Instant) EntryList(org.janusgraph.diskstorage.EntryList) Test(org.junit.Test)

Example 4 with StandardLockCleanerRunnable

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);
    }
}
Also used : StandardLockCleanerService(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerService) StandardLockCleanerRunnable(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Instant(java.time.Instant) Test(org.junit.Test)

Example 5 with StandardLockCleanerRunnable

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);
    }
}
Also used : StandardLockCleanerService(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerService) StandardLockCleanerRunnable(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Instant(java.time.Instant) Duration(java.time.Duration) Test(org.junit.Test)

Aggregations

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