Search in sources :

Example 1 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testDeleteLocksInSimplestCase.

/**
 * Delete a single lock without any timeouts, errors, etc.
 *
 * @throws org.janusgraph.diskstorage.BackendException shouldn't happen
 */
@Test
public void testDeleteLocksInSimplestCase() throws BackendException {
    // Setup a LockStatus for defaultLockID
    final ConsistentKeyLockStatus lockStatus = makeStatusNow();
    currentTimeNS = currentTimeNS.plusNanos(1);
    @SuppressWarnings("serial") Map<KeyColumn, ConsistentKeyLockStatus> expectedMap = new HashMap<KeyColumn, ConsistentKeyLockStatus>() {

        {
            put(defaultLockID, lockStatus);
        }
    };
    expect(lockState.getLocksForTx(defaultTx)).andReturn(expectedMap);
    List<StaticBuffer> deletions = ImmutableList.of(codec.toLockCol(lockStatus.getWriteTimestamp(), defaultLockRid, times));
    expect(times.getTime()).andReturn(currentTimeNS);
    store.mutate(eq(defaultLockKey), eq(ImmutableList.of()), eq(deletions), eq(defaultTx));
    expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : HashMap(java.util.HashMap) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) KeyColumn(org.janusgraph.diskstorage.util.KeyColumn) Test(org.junit.jupiter.api.Test)

Example 2 with ConsistentKeyLockStatus

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

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 org.janusgraph.diskstorage.BackendException shouldn't happen
 */
@Test
public void testDeleteLocksIdempotence() throws BackendException {
    // Setup a LockStatus for defaultLockID
    ConsistentKeyLockStatus lockStatus = makeStatusNow();
    currentTimeNS = currentTimeNS.plusNanos(1);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, lockStatus)));
    expectLockDeleteSuccessfully(defaultLockID, defaultLockKey, lockStatus);
    ctrl.replay();
    locker.deleteLocks(defaultTx);
    ctrl.verify();
    ctrl.reset();
    expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of()));
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.jupiter.api.Test)

Example 3 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testCheckOwnExpiredLockThrowsException.

/**
 * A transaction that writes a lock, waits past expiration, and attempts
 * to check locks should receive an {@code ExpiredLockException} during
 * the check stage.
 *
 * @throws org.janusgraph.diskstorage.BackendException     shouldn't happen
 * @throws InterruptedException
 */
@Test
public void testCheckOwnExpiredLockThrowsException() throws BackendException, InterruptedException {
    // Fake a pre-existing lock that's long since expired
    final ConsistentKeyLockStatus expired = makeStatusNow();
    expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, expired));
    // pretend a huge multiple of the expiration time has passed
    currentTimeNS = currentTimeNS.plus(100, ChronoUnit.DAYS);
    // Checker should compare the fake lock's timestamp to the current time
    expectSleepAfterWritingLock(expired);
    // Checker must slice the store; we return the single expired lock column
    recordLockGetSliceAndReturnSingleEntry(StaticArrayEntry.of(codec.toLockCol(expired.getWriteTimestamp(), defaultLockRid, times), defaultLockVal));
    ctrl.replay();
    ExpiredLockException ele = null;
    try {
        locker.checkLocks(defaultTx);
    } catch (ExpiredLockException e) {
        ele = e;
    }
    assertNotNull(ele);
}
Also used : ExpiredLockException(org.janusgraph.diskstorage.locking.consistentkey.ExpiredLockException) ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.jupiter.api.Test)

Example 4 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testDeleteLocksOnTwoLocks.

/**
 * Delete two locks without any timeouts, errors, etc.
 *
 * @throws org.janusgraph.diskstorage.BackendException shouldn't happen
 */
@Test
public void testDeleteLocksOnTwoLocks() throws BackendException {
    ConsistentKeyLockStatus defaultLS = makeStatusNow();
    currentTimeNS = currentTimeNS.plusNanos(1);
    ConsistentKeyLockStatus otherLS = makeStatusNow();
    currentTimeNS = currentTimeNS.plusNanos(1);
    // 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);
    expectLockDeleteSuccessfully(defaultLockID, defaultLockKey, defaultLS);
    expectLockDeleteSuccessfully(otherLockID, otherLockKey, otherLS);
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) KeyColumn(org.janusgraph.diskstorage.util.KeyColumn) Test(org.junit.jupiter.api.Test)

Example 5 with ConsistentKeyLockStatus

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

the class ConsistentKeyLockerTest method testDeleteLocksRetriesOnTemporaryStorageException.

/**
 * Lock deletion should retry if the first store mutation throws a temporary
 * exception.
 *
 * @throws org.janusgraph.diskstorage.BackendException shouldn't happen
 */
@Test
public void testDeleteLocksRetriesOnTemporaryStorageException() throws BackendException {
    ConsistentKeyLockStatus defaultLS = makeStatusNow();
    currentTimeNS = currentTimeNS.plusNanos(1);
    expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, defaultLS)));
    expectDeleteLock(defaultLockID, defaultLockKey, defaultLS, new TemporaryBackendException("Storage cluster is backlogged"));
    ctrl.replay();
    locker.deleteLocks(defaultTx);
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.jupiter.api.Test)

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