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();
}
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);
}
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();
}
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));
}
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());
}
Aggregations