Search in sources :

Example 51 with StaticBuffer

use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.

the class HashingUtil method hashPrefixKey.

public static final StaticBuffer hashPrefixKey(final HashLength hashPrefixLen, final StaticBuffer key) {
    final int prefixLen = hashPrefixLen.length();
    final StaticBuffer.Factory<HashCode> hashFactory;
    switch(hashPrefixLen) {
        case SHORT:
            hashFactory = SHORT_HASH_FACTORY;
            break;
        case LONG:
            hashFactory = LONG_HASH_FACTORY;
            break;
        default:
            throw new IllegalArgumentException("Unknown hash prefix: " + hashPrefixLen);
    }
    HashCode hashcode = key.as(hashFactory);
    WriteByteBuffer newKey = new WriteByteBuffer(prefixLen + key.length());
    assert prefixLen == 4 || prefixLen == 8;
    if (prefixLen == 4)
        newKey.putInt(hashcode.asInt());
    else
        newKey.putLong(hashcode.asLong());
    newKey.putBytes(key);
    return newKey.getStaticBuffer();
}
Also used : HashCode(com.google.common.hash.HashCode) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 52 with StaticBuffer

use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.

the class KCVSConfiguration method set.

public <O> void set(String key, O value, O expectedValue, final boolean checkExpectedValue) {
    final StaticBuffer column = string2StaticBuffer(key);
    final List<Entry> additions;
    final List<StaticBuffer> deletions;
    if (value != null) {
        //Addition
        additions = new ArrayList<Entry>(1);
        deletions = KeyColumnValueStore.NO_DELETIONS;
        StaticBuffer val = object2StaticBuffer(value);
        additions.add(StaticArrayEntry.of(column, val));
    } else {
        //Deletion
        additions = KeyColumnValueStore.NO_ADDITIONS;
        deletions = Lists.newArrayList(column);
    }
    final StaticBuffer expectedValueBuffer;
    if (checkExpectedValue && expectedValue != null) {
        expectedValueBuffer = object2StaticBuffer(expectedValue);
    } else {
        expectedValueBuffer = null;
    }
    BackendOperation.execute(new BackendOperation.Transactional<Boolean>() {

        @Override
        public Boolean call(StoreTransaction txh) throws BackendException {
            if (checkExpectedValue)
                store.acquireLock(rowKey, column, expectedValueBuffer, txh);
            store.mutate(rowKey, additions, deletions, txh);
            return true;
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
}
Also used : Entry(com.thinkaurelius.titan.diskstorage.Entry) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) BackendOperation(com.thinkaurelius.titan.diskstorage.util.BackendOperation) BackendException(com.thinkaurelius.titan.diskstorage.BackendException)

Example 53 with StaticBuffer

use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.

the class TitanGraphIterativeBenchmark method testDataSequential.

//@Test
public void testDataSequential() throws Exception {
    loadData(200000, 2);
    close();
    KeyColumnValueStoreManager manager = openStorageManager();
    KeyColumnValueStore store = manager.openDatabase(Backend.EDGESTORE_NAME);
    SliceQuery query = new SliceQuery(BufferUtil.zeroBuffer(8), BufferUtil.oneBuffer(8));
    query.setLimit(2);
    Stopwatch watch = Stopwatch.createStarted();
    StoreTransaction txh = manager.beginTransaction(StandardBaseTransactionConfig.of(TimestampProviders.MILLI));
    KeyIterator iter = store.getKeys(query, txh);
    int numV = 0;
    while (iter.hasNext()) {
        StaticBuffer key = iter.next();
        RecordIterator<Entry> entries = iter.getEntries();
        assertEquals(2, Iterators.size(entries));
        numV++;
    }
    iter.close();
    txh.commit();
    System.out.println("Time taken: " + watch.elapsed(TimeUnit.MILLISECONDS));
    System.out.println("Num Vertices: " + numV);
    store.close();
    manager.close();
}
Also used : Entry(com.thinkaurelius.titan.diskstorage.Entry) Stopwatch(com.google.common.base.Stopwatch) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 54 with StaticBuffer

use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.

the class BufferUtilTest method testNextBigger.

@Test
public void testNextBigger() {
    int trials = 100000;
    for (int t = 0; t < trials; t++) {
        long val = random.nextLong() >>> 1;
        assert 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 e) {
    }
    StaticBuffer b = BufferUtil.getLongBuffer(-1);
    StaticBuffer bn = BufferUtil.nextBiggerBufferAllowOverflow(b);
    Assert.assertEquals(8, bn.length());
    Assert.assertTrue(BufferUtil.zeroBuffer(8).equals(bn));
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Test(org.junit.Test)

Example 55 with StaticBuffer

use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.

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);
    StaticBuffer key = BufferUtil.getIntBuffer(81);
    List<StaticBuffer> keys = new ArrayList<StaticBuffer>();
    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(com.thinkaurelius.titan.diskstorage.StaticBuffer) CacheTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Aggregations

StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)92 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)16 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)15 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)14 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)13 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)13 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)12 HashMap (java.util.HashMap)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Entry (com.thinkaurelius.titan.diskstorage.Entry)10 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)10 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)9 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)8 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)7 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)6 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)6 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)6 Instant (java.time.Instant)6