use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class InMemoryColumnValueStoreTest method testVolumeSlidingWindows.
@Test
public void testVolumeSlidingWindows() throws TemporaryLockingException {
int pageSize = InMemoryColumnValueStore.DEF_PAGE_SIZE;
int maxNumEntries = 7 * pageSize + pageSize / 2;
StoreTransaction txh = mock(StoreTransaction.class);
BaseTransactionConfig mockConfig = mock(BaseTransactionConfig.class);
when(txh.getConfiguration()).thenReturn(mockConfig);
when(mockConfig.getCustomOption(eq(STORAGE_TRANSACTIONAL))).thenReturn(true);
InMemoryColumnValueStore cvs = new InMemoryColumnValueStore();
for (int numEntries = 1; numEntries < maxNumEntries; numEntries += pageSize + pageSize / 3) {
List<Entry> additions = generateEntries(0, numEntries, "orig");
cvs.mutate(additions, Collections.emptyList(), txh);
EntryList result = cvs.getSlice(new KeySliceQuery(makeStaticBuffer("someRow"), makeStaticBuffer(VERY_START), // if we pass COL_END, it doesn't get included
makeStaticBuffer(VERY_END)), txh);
assertEquals(additions.size(), result.size());
int stepSize = numEntries < 100 ? 1 : 21;
for (int windowSize = 0; windowSize < numEntries; windowSize += stepSize) {
for (int windowStart = 0; windowStart < numEntries; windowStart += stepSize) {
int windowEnd = Math.min(windowStart + windowSize, numEntries - 1);
result = cvs.getSlice(new KeySliceQuery(makeStaticBuffer("someRow"), additions.get(windowStart).getColumn(), additions.get(windowEnd).getColumn()), txh);
assertEquals(windowEnd - windowStart, result.size());
}
}
}
}
use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method recordExceptionalLockGetSlice.
private void recordExceptionalLockGetSlice(Throwable t) throws BackendException {
final KeySliceQuery ksq = new KeySliceQuery(defaultLockKey, LOCK_COL_START, LOCK_COL_END);
expect(store.getSlice(eq(ksq), eq(defaultTx))).andThrow(t);
}
use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class ConsistentKeyIDAuthority method getCurrentID.
private long getCurrentID(final StaticBuffer partitionKey) throws BackendException {
final List<Entry> blocks = BackendOperation.execute((BackendOperation.Transactional<List<Entry>>) txh -> idStore.getSlice(new KeySliceQuery(partitionKey, LOWER_SLICE, UPPER_SLICE).setLimit(5), txh), this, times);
if (blocks == null)
throw new TemporaryBackendException("Could not read from storage");
long latest = BASE_ID;
for (Entry e : blocks) {
long counterVal = getBlockValue(e);
if (latest < counterVal) {
latest = counterVal;
}
}
return latest;
}
use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class KCVSConfiguration method get.
/**
* Reads the configuration property for this StoreManager
*
* @param key Key identifying the configuration property
* @return Value stored for the key or null if the configuration property has not (yet) been defined.
*/
@Override
public <O> O get(final String key, final Class<O> dataType) {
StaticBuffer column = string2StaticBuffer(key);
final KeySliceQuery query = new KeySliceQuery(rowKey, column, BufferUtil.nextBiggerBuffer(column));
StaticBuffer result = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() {
@Override
public StaticBuffer call(StoreTransaction txh) throws BackendException {
List<Entry> entries = store.getSlice(query, txh);
if (entries.isEmpty())
return null;
return entries.get(0).getValueAs(StaticBuffer.STATIC_FACTORY);
}
@Override
public String toString() {
return "getConfiguration";
}
}, txProvider, times, maxOperationWaitTime);
if (result == null)
return null;
return staticBuffer2Object(result, dataType);
}
use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class ExpirationKCVSCache method getSlice.
@Override
public Map<StaticBuffer, EntryList> getSlice(final List<StaticBuffer> keys, final SliceQuery query, final StoreTransaction txh) throws BackendException {
final Map<StaticBuffer, EntryList> results = new HashMap<>(keys.size());
final List<StaticBuffer> remainingKeys = new ArrayList<>(keys.size());
KeySliceQuery[] ksqs = new KeySliceQuery[keys.size()];
incActionBy(keys.size(), CacheMetricsAction.RETRIEVAL, txh);
// Find all cached queries
for (int i = 0; i < keys.size(); i++) {
final StaticBuffer key = keys.get(i);
ksqs[i] = new KeySliceQuery(key, query);
EntryList result = null;
if (!isExpired(ksqs[i]))
result = cache.getIfPresent(ksqs[i]);
else
ksqs[i] = null;
if (result != null)
results.put(key, result);
else
remainingKeys.add(key);
}
// Request remaining ones from backend
if (!remainingKeys.isEmpty()) {
incActionBy(remainingKeys.size(), CacheMetricsAction.MISS, txh);
Map<StaticBuffer, EntryList> subresults = store.getSlice(remainingKeys, query, unwrapTx(txh));
for (int i = 0; i < keys.size(); i++) {
StaticBuffer key = keys.get(i);
EntryList subresult = subresults.get(key);
if (subresult != null) {
results.put(key, subresult);
if (ksqs[i] != null)
cache.put(ksqs[i], subresult);
}
}
}
return results;
}
Aggregations