Search in sources :

Example 1 with KeyValueEntry

use of org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry in project janusgraph by JanusGraph.

the class BerkeleyJEStoreManager method mutateMany.

@Override
public void mutateMany(Map<String, KVMutation> mutations, StoreTransaction txh) throws BackendException {
    for (Map.Entry<String, KVMutation> mutation : mutations.entrySet()) {
        BerkeleyJEKeyValueStore store = openDatabase(mutation.getKey());
        KVMutation mutationValue = mutation.getValue();
        if (!mutationValue.hasAdditions() && !mutationValue.hasDeletions()) {
            log.debug("Empty mutation set for {}, doing nothing", mutation.getKey());
        } else {
            log.debug("Mutating {}", mutation.getKey());
        }
        if (mutationValue.hasAdditions()) {
            for (KeyValueEntry entry : mutationValue.getAdditions()) {
                store.insert(entry.getKey(), entry.getValue(), txh);
                log.trace("Insertion on {}: {}", mutation.getKey(), entry);
            }
        }
        if (mutationValue.hasDeletions()) {
            for (StaticBuffer del : mutationValue.getDeletions()) {
                store.delete(del, txh);
                log.trace("Deletion on {}: {}", mutation.getKey(), del);
            }
        }
    }
}
Also used : KVMutation(org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KVMutation) HashMap(java.util.HashMap) Map(java.util.Map) KeyValueEntry(org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)

Example 2 with KeyValueEntry

use of org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry 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

KeyValueEntry (org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 BackendException (org.janusgraph.diskstorage.BackendException)1 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)1 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)1 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)1 KVMutation (org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KVMutation)1 KeySelector (org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeySelector)1 RecordIterator (org.janusgraph.diskstorage.util.RecordIterator)1