Search in sources :

Example 16 with ConsistentKeyLockStatus

use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.

the class ConsistentKeyLockerTest method testCheckLocksInSimplestCase.

/**
 * Test a single checking a single lock under optimal conditions (no
 * timeouts, no errors)
 *
 * @throws org.janusgraph.diskstorage.BackendException     shouldn't happen
 * @throws InterruptedException shouldn't happen
 */
@Test
public void testCheckLocksInSimplestCase() throws BackendException, InterruptedException {
    // Fake a pre-existing lock
    final ConsistentKeyLockStatus ls = makeStatusNow();
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, ls));
    currentTimeNS = currentTimeNS.plusSeconds(10);
    // Checker should compare the fake lock's timestamp to the current time
    expectSleepAfterWritingLock(ls);
    // Expect a store getSlice() and return the fake lock's column and value
    recordLockGetSliceAndReturnSingleEntry(StaticArrayEntry.of(codec.toLockCol(ls.getWriteTimestamp(), defaultLockRid, times), defaultLockVal));
    ctrl.replay();
    locker.checkLocks(defaultTx);
}
Also used : ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.jupiter.api.Test)

Example 17 with ConsistentKeyLockStatus

use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.

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 org.janusgraph.diskstorage.BackendException shouldn't happen
 */
@Test
public void testDeleteLocksDeletesUncheckedLocks() throws BackendException {
    ConsistentKeyLockStatus defaultLS = makeStatusNow();
    assertFalse(defaultLS.isChecked());
    currentTimeNS = currentTimeNS.plusNanos(1);
    // Expect a call for defaultTx's locks and the checked one
    expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, defaultLS)));
    expectLockDeleteSuccessfully(defaultLockID, defaultLockKey, defaultLS);
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.jupiter.api.Test)

Example 18 with ConsistentKeyLockStatus

use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.

the class ConsistentKeyLockerTest method testCheckLocksThrowsExceptionAfterMaxTemporaryStorageExceptions.

/**
 * The checker will throw a TemporaryStorageException if getSlice() throws
 * fails with a TemporaryStorageException as many times as there are
 * configured lock retries.
 *
 * @throws InterruptedException shouldn't happen
 * @throws org.janusgraph.diskstorage.BackendException     shouldn't happen
 */
@Test
public void testCheckLocksThrowsExceptionAfterMaxTemporaryStorageExceptions() throws InterruptedException, BackendException {
    // Setup a LockStatus for defaultLockID
    ConsistentKeyLockStatus lockStatus = makeStatusNow();
    currentTimeNS = currentTimeNS.plusNanos(1);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, lockStatus));
    expectSleepAfterWritingLock(lockStatus);
    // Three successive getSlice calls, each throwing a distinct TSE
    recordExceptionalLockGetSlice(new TemporaryBackendException("Storage cluster is having me-time"));
    recordExceptionalLockGetSlice(new TemporaryBackendException("Storage cluster is in a dissociative fugue state"));
    recordExceptionalLockGetSlice(new TemporaryBackendException("Storage cluster has gone to Prague to find itself"));
    ctrl.replay();
    TemporaryBackendException tse = null;
    try {
        locker.checkLocks(defaultTx);
    } catch (TemporaryBackendException e) {
        tse = e;
    }
    assertNotNull(tse);
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.jupiter.api.Test)

Example 19 with ConsistentKeyLockStatus

use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.

the class ConsistentKeyLockerTest method recordSuccessfulLockWrite.

private LockInfo recordSuccessfulLockWrite(StoreTransaction tx, long duration, TemporalUnit tu, StaticBuffer del) throws BackendException {
    currentTimeNS = currentTimeNS.plusNanos(1);
    expect(times.getTime()).andReturn(currentTimeNS);
    final Instant lockNS = currentTimeNS;
    StaticBuffer lockCol = codec.toLockCol(lockNS, defaultLockRid, times);
    Entry add = StaticArrayEntry.of(lockCol, defaultLockVal);
    StaticBuffer k = eq(defaultLockKey);
    final List<Entry> adds = eq(Collections.singletonList(add));
    final List<StaticBuffer> deletions;
    if (null != del) {
        deletions = eq(Collections.singletonList(del));
    } else {
        deletions = eq(ImmutableList.of());
    }
    store.mutate(k, adds, deletions, eq(tx));
    expectLastCall().once();
    currentTimeNS = currentTimeNS.plus(duration, tu);
    expect(times.getTime()).andReturn(currentTimeNS);
    ConsistentKeyLockStatus status = new ConsistentKeyLockStatus(lockNS, lockNS.plus(defaultExpireNS));
    return new LockInfo(lockNS, status, lockCol);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Instant(java.time.Instant) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)

Aggregations

ConsistentKeyLockStatus (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)19 Test (org.junit.jupiter.api.Test)18 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)7 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)4 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)2 KeyColumn (org.janusgraph.diskstorage.util.KeyColumn)2 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 Entry (org.janusgraph.diskstorage.Entry)1 ConsistentKeyLocker (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker)1 ExpiredLockException (org.janusgraph.diskstorage.locking.consistentkey.ExpiredLockException)1 LockCleanerService (org.janusgraph.diskstorage.locking.consistentkey.LockCleanerService)1 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)1