use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class IndexSerializer method getIndexKey.
private StaticBuffer getIndexKey(CompositeIndexType index, Object[] values) {
final DataOutput out = serializer.getDataOutput(8 * DEFAULT_OBJECT_BYTELEN + 8);
VariableLong.writePositive(out, index.getID());
final IndexField[] fields = index.getFieldKeys();
Preconditions.checkArgument(fields.length > 0 && fields.length == values.length);
for (int i = 0; i < fields.length; i++) {
final IndexField f = fields[i];
final Object value = values[i];
Preconditions.checkNotNull(value);
if (InternalAttributeUtil.hasGenericDataType(f.getFieldKey())) {
out.writeClassAndObject(value);
} else {
assert value.getClass().equals(f.getFieldKey().dataType()) : value.getClass() + " - " + f.getFieldKey().dataType();
out.writeObjectNotNull(value);
}
}
StaticBuffer key = out.getStaticBuffer();
if (hashKeys)
key = HashingUtil.hashPrefixKey(hashLength, key);
return key;
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class OrderedKeyValueStoreAdapter method getSlice.
@Override
public Map<StaticBuffer, EntryList> getSlice(List<StaticBuffer> keys, SliceQuery query, StoreTransaction txh) throws BackendException {
final List<KVQuery> queries = new ArrayList<>(keys.size());
for (StaticBuffer key : keys) {
queries.add(convertQuery(new KeySliceQuery(key, query)));
}
final Map<KVQuery, RecordIterator<KeyValueEntry>> results = store.getSlices(queries, txh);
final Map<StaticBuffer, EntryList> convertedResults = new HashMap<>(keys.size());
assert queries.size() == keys.size();
for (int i = 0; i < queries.size(); i++) {
convertedResults.put(keys.get(i), convert(results.get(queries.get(i))));
}
return convertedResults;
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class OrderedKeyValueStoreManagerAdapter method mutateMany.
@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException {
final Map<String, KVMutation> converted = new HashMap<>(mutations.size());
for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> storeEntry : mutations.entrySet()) {
OrderedKeyValueStoreAdapter store = openDatabase(storeEntry.getKey());
Preconditions.checkNotNull(store);
KVMutation mut = new KVMutation();
for (Map.Entry<StaticBuffer, KCVMutation> entry : storeEntry.getValue().entrySet()) {
StaticBuffer key = entry.getKey();
KCVMutation mutation = entry.getValue();
if (mutation.hasAdditions()) {
for (Entry addition : mutation.getAdditions()) {
KeyValueEntry concatenate = store.concatenate(key, addition);
concatenate.setTTL((Integer) addition.getMetaData().get(EntryMetaData.TTL));
mut.addition(concatenate);
}
}
if (mutation.hasDeletions()) {
for (StaticBuffer del : mutation.getDeletions()) {
mut.deletion(store.concatenate(key, del));
}
}
}
converted.put(storeEntry.getKey(), mut);
}
manager.mutateMany(converted, txh);
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class MultiThreadsRowsCollector method run.
void run() throws InterruptedException, TemporaryBackendException {
int numQueries = queries.size();
SliceResult[] currentResults = new SliceResult[numQueries];
while (!interrupted) {
collectDataFromPullers(currentResults, numQueries);
SliceResult conditionQuery = currentResults[0];
// Termination condition - primary query has no more data
if (conditionQuery == null)
break;
final StaticBuffer key = conditionQuery.key;
Row e = buildRow(numQueries, currentResults, key);
rowQueue.put(e);
}
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
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<>(1);
deletions = KeyColumnValueStore.NO_DELETIONS;
StaticBuffer val = object2StaticBuffer(value);
additions.add(StaticArrayEntry.of(column, val));
} else {
// Deletion
additions = KeyColumnValueStore.NO_ADDITIONS;
deletions = new ArrayList<>(1);
deletions.add(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);
}
Aggregations