Search in sources :

Example 26 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 27 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 28 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 29 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 30 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)44 Entry (com.thinkaurelius.titan.diskstorage.Entry)13 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)8 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)7 Map (java.util.Map)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 Instant (java.time.Instant)6 HashMap (java.util.HashMap)6 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)5 BiMap (com.google.common.collect.BiMap)4 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)4 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)4 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)4 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)4 Delete (org.apache.hadoop.hbase.client.Delete)4 Put (org.apache.hadoop.hbase.client.Put)4 Pair (org.apache.hadoop.hbase.util.Pair)4 ImmutableList (com.google.common.collect.ImmutableList)3