Search in sources :

Example 1 with StoreTransaction

use of org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction in project janusgraph by JanusGraph.

the class ExpirationCacheTest method testExpiration.

private void testExpiration(Duration expirationTime) throws Exception {
    final int numKeys = 100, numCols = 10;
    loadStore(numKeys, numCols);
    // Replace cache with proper times
    cache = getCache(store, expirationTime, Duration.ZERO);
    final StaticBuffer key = BufferUtil.getIntBuffer(81);
    final List<StaticBuffer> keys = new ArrayList<>();
    keys.add(key);
    keys.add(BufferUtil.getIntBuffer(37));
    keys.add(BufferUtil.getIntBuffer(2));
    SliceQuery query = getQuery(2, 8);
    verifyResults(key, keys, query, 6);
    // Modify store directly
    StoreTransaction txs = getStoreTx();
    store.mutate(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(BufferUtil.getIntBuffer(5)), txs);
    txs.commit();
    Instant utime = times.getTime();
    // Should still see cached results
    verifyResults(key, keys, query, 6);
    // Sleep half way through expiration time
    times.sleepPast(utime.plus(expirationTime.dividedBy(2)));
    verifyResults(key, keys, query, 6);
    // Sleep past expiration time...
    times.sleepPast(utime.plus(expirationTime));
    // ...and just a little bit longer
    times.sleepFor(Duration.ofMillis(5));
    // Now the results should be different
    verifyResults(key, keys, query, 5);
    // If we modify through cache store...
    CacheTransaction tx = getCacheTx();
    cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(getEntry(4, 4)), tx);
    tx.commit();
    store.resetCounter();
    // ...invalidation should happen and the result set is updated immediately
    verifyResults(key, keys, query, 4);
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) ArrayList(java.util.ArrayList) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) CacheTransaction(org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 2 with StoreTransaction

use of org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction in project janusgraph by JanusGraph.

the class KCVSConfigTest method getConfig.

@Override
public WriteConfiguration getConfig() {
    final KeyColumnValueStoreManager manager = new InMemoryStoreManager(Configuration.EMPTY);
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.TIMESTAMP_PROVIDER, TimestampProviders.MICRO);
    try {
        return new KCVSConfiguration(new BackendOperation.TransactionalProvider() {

            @Override
            public StoreTransaction openTx() throws BackendException {
                return manager.beginTransaction(StandardBaseTransactionConfig.of(TimestampProviders.MICRO, manager.getFeatures().getKeyConsistentTxConfig()));
            }

            @Override
            public void close() throws BackendException {
                manager.close();
            }
        }, config, manager.openDatabase("janusgraph"), "general");
    } catch (BackendException e) {
        throw new RuntimeException(e);
    }
}
Also used : KCVSConfiguration(org.janusgraph.diskstorage.configuration.backend.KCVSConfiguration) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) KeyColumnValueStoreManager(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager) InMemoryStoreManager(org.janusgraph.diskstorage.keycolumnvalue.inmemory.InMemoryStoreManager) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException)

Example 3 with StoreTransaction

use of org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction in project janusgraph by JanusGraph.

the class CassandraScanJobIT method testSimpleScan.

@Test
public void testSimpleScan() throws InterruptedException, ExecutionException, IOException, BackendException {
    int keys = 1000;
    int cols = 40;
    String[][] values = KeyValueStoreUtil.generateData(keys, cols);
    // Make it only half the number of columns for every 2nd key
    for (int i = 0; i < values.length; i++) {
        if (i % 2 == 0)
            values[i] = Arrays.copyOf(values[i], cols / 2);
    }
    log.debug("Loading values: " + keys + "x" + cols);
    KeyColumnValueStoreManager mgr = new CassandraThriftStoreManager(GraphDatabaseConfiguration.buildGraphConfiguration());
    KeyColumnValueStore store = mgr.openDatabase("edgestore");
    StoreTransaction tx = mgr.beginTransaction(StandardBaseTransactionConfig.of(TimestampProviders.MICRO));
    KeyColumnValueStoreUtil.loadValues(store, tx, values);
    // noop on Cassandra, but harmless
    tx.commit();
    SimpleScanJobRunner runner = (ScanJob job, Configuration jobConf, String rootNSName) -> {
        try {
            return new CassandraHadoopScanRunner(job).scanJobConf(jobConf).scanJobConfRoot(rootNSName).partitionerOverride("org.apache.cassandra.dht.Murmur3Partitioner").run();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    };
    SimpleScanJob.runBasicTests(keys, cols, runner);
}
Also used : KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) JanusGraphHadoopConfiguration(org.janusgraph.hadoop.config.JanusGraphHadoopConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) CassandraThriftStoreManager(org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftStoreManager) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) KeyColumnValueStoreManager(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager) CassandraHadoopScanRunner(org.janusgraph.hadoop.scan.CassandraHadoopScanRunner) ScanJob(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJob) Test(org.junit.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 4 with StoreTransaction

use of org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction in project janusgraph by JanusGraph.

the class BerkeleyJEKeyValueStore method insert.

public void insert(StaticBuffer key, StaticBuffer value, StoreTransaction txh, boolean allowOverwrite) throws BackendException {
    Transaction tx = getTransaction(txh);
    try {
        OperationStatus status;
        log.trace("db={}, op=insert, tx={}", name, txh);
        if (allowOverwrite)
            status = db.put(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY));
        else
            status = db.putNoOverwrite(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY));
        if (status != OperationStatus.SUCCESS) {
            if (status == OperationStatus.KEYEXIST) {
                throw new PermanentBackendException("Key already exists on no-overwrite.");
            } else {
                throw new PermanentBackendException("Could not write entity, return status: " + status);
            }
        }
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 5 with StoreTransaction

use of org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction in project janusgraph by JanusGraph.

the class BerkeleyJEKeyValueStore method getSlice.

@Override
public RecordIterator<KeyValueEntry> getSlice(KVQuery query, StoreTransaction txh) throws BackendException {
    log.trace("beginning db={}, op=getSlice, tx={}", name, txh);
    final Transaction tx = getTransaction(txh);
    final StaticBuffer keyStart = query.getStart();
    final StaticBuffer keyEnd = query.getEnd();
    final KeySelector selector = query.getKeySelector();
    final List<KeyValueEntry> result = new ArrayList<>();
    final DatabaseEntry foundKey = keyStart.as(ENTRY_FACTORY);
    final DatabaseEntry foundData = new DatabaseEntry();
    try (final Cursor cursor = db.openCursor(tx, null)) {
        OperationStatus status = cursor.getSearchKeyRange(foundKey, foundData, getLockMode(txh));
        // Iterate until given condition is satisfied or end of records
        while (status == OperationStatus.SUCCESS) {
            StaticBuffer key = getBuffer(foundKey);
            if (key.compareTo(keyEnd) >= 0)
                break;
            if (selector.include(key)) {
                result.add(new KeyValueEntry(key, getBuffer(foundData)));
            }
            if (selector.reachedLimit())
                break;
            status = cursor.getNext(foundKey, foundData, getLockMode(txh));
        }
    } catch (Exception e) {
        throw new PermanentBackendException(e);
    }
    log.trace("db={}, op=getSlice, tx={}, resultcount={}", name, txh, result.size());
    return new RecordIterator<KeyValueEntry>() {

        private final Iterator<KeyValueEntry> entries = result.iterator();

        @Override
        public boolean hasNext() {
            return entries.hasNext();
        }

        @Override
        public KeyValueEntry next() {
            return entries.next();
        }

        @Override
        public void close() {
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : RecordIterator(org.janusgraph.diskstorage.util.RecordIterator) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) ArrayList(java.util.ArrayList) KeySelector(org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeySelector) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Iterator(java.util.Iterator) RecordIterator(org.janusgraph.diskstorage.util.RecordIterator) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) KeyValueEntry(org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)

Aggregations

StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)9 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)5 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BackendException (org.janusgraph.diskstorage.BackendException)2 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)2 Configuration (org.janusgraph.diskstorage.configuration.Configuration)2 KeyColumnValueStoreManager (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager)2 KeyRange (org.janusgraph.diskstorage.keycolumnvalue.KeyRange)2 BatchStatement (com.datastax.driver.core.BatchStatement)1 Type (com.datastax.driver.core.BatchStatement.Type)1 Cluster (com.datastax.driver.core.Cluster)1 Builder (com.datastax.driver.core.Cluster.Builder)1 HostDistance (com.datastax.driver.core.HostDistance)1 JdkSSLOptions (com.datastax.driver.core.JdkSSLOptions)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 PoolingOptions (com.datastax.driver.core.PoolingOptions)1 ProtocolVersion (com.datastax.driver.core.ProtocolVersion)1 ResultSet (com.datastax.driver.core.ResultSet)1