Search in sources :

Example 96 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class ConsistentKeyLockerTest method testWriteLockRetriesOnTemporaryStorageException.

/**
 * Test the locker retries a lock write after the initial store mutation
 * fails with a {@link org.janusgraph.diskstorage.TemporaryBackendException}. The retry should both
 * attempt to write the and delete the failed mutation column.
 *
 * @throws org.janusgraph.diskstorage.BackendException shouldn't happen
 */
@Test
public void testWriteLockRetriesOnTemporaryStorageException() throws BackendException {
    TemporaryBackendException tse = new TemporaryBackendException("Storage cluster is waking up");
    expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
    recordSuccessfulLocalLock();
    StaticBuffer firstCol = recordExceptionLockWrite(tse);
    LockInfo secondLI = recordSuccessfulLockWrite(1, ChronoUnit.NANOS, firstCol);
    recordSuccessfulLocalLock(secondLI.tsNS);
    lockState.take(eq(defaultTx), eq(defaultLockID), eq(secondLI.stat));
    ctrl.replay();
    // SUT
    locker.writeLock(defaultLockID, defaultTx);
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Test(org.junit.jupiter.api.Test)

Example 97 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class ConsistentKeyLockerTest method testWriteLockDiesOnPermanentStorageException.

/**
 * Test that the first {@link org.janusgraph.diskstorage.PermanentBackendException} thrown by the
 * locker's store causes it to attempt to delete outstanding lock writes and
 * then emit the exception without retrying.
 *
 * @throws org.janusgraph.diskstorage.BackendException shouldn't happen
 */
@Test
public void testWriteLockDiesOnPermanentStorageException() throws BackendException {
    PermanentBackendException errOnFire = new PermanentBackendException("Storage cluster is on fire");
    expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
    recordSuccessfulLocalLock();
    StaticBuffer lockCol = recordExceptionLockWrite(errOnFire);
    recordSuccessfulLockDelete(lockCol);
    recordSuccessfulLocalUnlock();
    ctrl.replay();
    BackendException expected = null;
    try {
        // SUT
        locker.writeLock(defaultLockID, defaultTx);
    } catch (PermanentLockingException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertEquals(errOnFire, expected.getCause());
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Test(org.junit.jupiter.api.Test)

Example 98 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class ExpirationCacheTest method testGracePeriod.

private void testGracePeriod(Duration graceWait) throws Exception {
    final int minCleanupTriggerCalls = 5;
    final int numKeys = 100, numCols = 10;
    loadStore(numKeys, numCols);
    // Replace cache with proper times
    cache = getCache(store, Duration.ofDays(200), graceWait);
    final StaticBuffer key = BufferUtil.getIntBuffer(81);
    final List<StaticBuffer> keys = new ArrayList<>();
    keys.add(key);
    keys.add(BufferUtil.getIntBuffer(37));
    keys.add(BufferUtil.getIntBuffer(2));
    SliceQuery query = getQuery(2, 8);
    verifyResults(key, keys, query, 6);
    // If we modify through cache store...
    CacheTransaction tx = getCacheTx();
    cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(getEntry(4, 4)), tx);
    tx.commit();
    Instant utime = times.getTime();
    store.resetCounter();
    // ...invalidation should happen and the result set is updated immediately
    verifyResults(key, keys, query, 5);
    assertEquals(2, store.getSliceCalls());
    // however, the key is expired and hence repeated calls need to go through to the store
    verifyResults(key, keys, query, 5);
    assertEquals(4, store.getSliceCalls());
    // however, when we sleep past the grace wait time and trigger a cleanup...
    times.sleepPast(utime.plus(graceWait));
    for (int t = 0; t < minCleanupTriggerCalls; t++) {
        assertEquals(5, cache.getSlice(new KeySliceQuery(key, query), tx).size());
        times.sleepFor(Duration.ofMillis(5));
    }
    // ...the cache should cache results again
    store.resetCounter();
    verifyResults(key, keys, query, 5);
    assertEquals(0, store.getSliceCalls());
    verifyResults(key, keys, query, 5);
    assertEquals(0, store.getSliceCalls());
}
Also used : Instant(java.time.Instant) ArrayList(java.util.ArrayList) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) CacheTransaction(org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 99 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class ExpirationCacheTest method verifyResults.

private void verifyResults(StaticBuffer key, List<StaticBuffer> keys, SliceQuery query, int expectedResults) throws Exception {
    CacheTransaction tx = getCacheTx();
    assertEquals(expectedResults, cache.getSlice(new KeySliceQuery(key, query), tx).size());
    Map<StaticBuffer, EntryList> results = cache.getSlice(keys, query, tx);
    assertEquals(keys.size(), results.size());
    assertEquals(expectedResults, results.get(key).size());
    tx.commit();
}
Also used : StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) EntryList(org.janusgraph.diskstorage.EntryList) CacheTransaction(org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 100 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class BufferUtilTest method testNextBigger.

@Test
public void testNextBigger() {
    int trials = 100000;
    for (int t = 0; t < trials; t++) {
        long val = random.nextLong() >>> 1;
        assertTrue(val >= 0);
        StaticBuffer b = BufferUtil.getLongBuffer(val);
        assertEquals(val, b.getLong(0));
        StaticBuffer bn = BufferUtil.nextBiggerBuffer(b);
        assertEquals(8, bn.length());
        assertEquals(val + 1, bn.getLong(0));
    }
    try {
        StaticBuffer b = BufferUtil.getLongBuffer(-1);
        BufferUtil.nextBiggerBuffer(b);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    StaticBuffer b = BufferUtil.getLongBuffer(-1);
    StaticBuffer bn = BufferUtil.nextBiggerBufferAllowOverflow(b);
    assertEquals(8, bn.length());
    assertEquals(BufferUtil.zeroBuffer(8), bn);
}
Also used : StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)101 Entry (org.janusgraph.diskstorage.Entry)36 Test (org.junit.jupiter.api.Test)36 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)20 Map (java.util.Map)19 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)17 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)16 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)16 BackendException (org.janusgraph.diskstorage.BackendException)15 List (java.util.List)14 EntryList (org.janusgraph.diskstorage.EntryList)14 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)14 KCVMutation (org.janusgraph.diskstorage.keycolumnvalue.KCVMutation)13 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)12 Instant (java.time.Instant)11 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)10 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)8 ConsistentKeyLockStatus (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)7 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)7