Search in sources :

Example 6 with KeySliceQuery

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());
            }
        }
    }
}
Also used : BufferPageTest.makeEntry(org.janusgraph.diskstorage.inmemory.BufferPageTest.makeEntry) Entry(org.janusgraph.diskstorage.Entry) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) EntryList(org.janusgraph.diskstorage.EntryList) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test)

Example 7 with KeySliceQuery

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);
}
Also used : KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 8 with KeySliceQuery

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;
}
Also used : KeyRange(org.janusgraph.diskstorage.keycolumnvalue.KeyRange) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) CLUSTER_MAX_PARTITIONS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CLUSTER_MAX_PARTITIONS) IDBlock(org.janusgraph.diskstorage.IDBlock) StoreManager(org.janusgraph.diskstorage.keycolumnvalue.StoreManager) StringUtils(org.janusgraph.util.StringUtils) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) Timer(org.janusgraph.diskstorage.util.time.Timer) NumberUtil(org.janusgraph.util.stats.NumberUtil) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) ArrayList(java.util.ArrayList) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IDAUTHORITY_CAV_TAG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDAUTHORITY_CAV_TAG) IDAUTHORITY_CAV_BITS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDAUTHORITY_CAV_BITS) VariableLong(org.janusgraph.graphdb.database.idhandling.VariableLong) Duration(java.time.Duration) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) IDPoolExhaustedException(org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException) BackendException(org.janusgraph.diskstorage.BackendException) IDAUTHORITY_CONFLICT_AVOIDANCE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDAUTHORITY_CONFLICT_AVOIDANCE) Logger(org.slf4j.Logger) Configuration(org.janusgraph.diskstorage.configuration.Configuration) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Durations(org.janusgraph.diskstorage.util.time.Durations) WriteBufferUtil(org.janusgraph.diskstorage.util.WriteBufferUtil) Instant(java.time.Instant) KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) TIMESTAMP_PROVIDER(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TIMESTAMP_PROVIDER) List(java.util.List) Entry(org.janusgraph.diskstorage.Entry) BufferUtil(org.janusgraph.diskstorage.util.BufferUtil) Preconditions(com.google.common.base.Preconditions) IDAUTHORITY_CAV_RETRIES(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDAUTHORITY_CAV_RETRIES) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Collections(java.util.Collections) TemporaryLockingException(org.janusgraph.diskstorage.locking.TemporaryLockingException) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ArrayList(java.util.ArrayList) List(java.util.List) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 9 with KeySliceQuery

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);
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) ArrayList(java.util.ArrayList) List(java.util.List) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) BackendException(org.janusgraph.diskstorage.BackendException)

Example 10 with KeySliceQuery

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;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) EntryList(org.janusgraph.diskstorage.EntryList) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Aggregations

KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)35 Test (org.junit.jupiter.api.Test)18 Entry (org.janusgraph.diskstorage.Entry)16 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)15 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)14 ArrayList (java.util.ArrayList)13 EntryList (org.janusgraph.diskstorage.EntryList)13 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)12 HashMap (java.util.HashMap)8 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)8 BufferPageTest.makeEntry (org.janusgraph.diskstorage.inmemory.BufferPageTest.makeEntry)8 List (java.util.List)5 Map (java.util.Map)5 JanusGraphBaseStoreFeaturesTest (org.janusgraph.JanusGraphBaseStoreFeaturesTest)5 BackendException (org.janusgraph.diskstorage.BackendException)5 BufferPageTest.makeStaticBuffer (org.janusgraph.diskstorage.inmemory.BufferPageTest.makeStaticBuffer)5 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)5 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)5 Instant (java.time.Instant)4 Random (java.util.Random)4