use of org.janusgraph.diskstorage.Entry 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);
}
use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class SliceQuery method getSubset.
// TODO: make this more efficient by using reuseIterator() on otherResult
public EntryList getSubset(final SliceQuery otherQuery, final EntryList otherResult) {
assert otherQuery.subsumes(this);
int pos = Collections.binarySearch(otherResult, sliceStart);
if (pos < 0)
pos = -pos - 1;
final List<Entry> result = new ArrayList<>();
for (; pos < otherResult.size() && result.size() < getLimit(); pos++) {
Entry e = otherResult.get(pos);
if (e.getColumnAs(StaticBuffer.STATIC_FACTORY).compareTo(sliceEnd) < 0)
result.add(e);
else
break;
}
return EntryArrayList.of(result);
}
use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class CacheTransaction method convert.
private KCVMutation convert(KCVEntryMutation mutation) {
assert !mutation.isEmpty();
if (mutation.hasDeletions()) {
return new KCVMutation(() -> new ArrayList<>(mutation.getAdditions()), () -> {
List<Entry> deletions = mutation.getDeletions();
ArrayList<StaticBuffer> convertedDeletions = new ArrayList<>(deletions.size());
for (Entry entry : deletions) {
convertedDeletions.add(KCVEntryMutation.ENTRY2COLUMN_FCT.apply(entry));
}
return convertedDeletions;
});
}
return new KCVMutation(mutation.getAdditions(), KeyColumnValueStore.NO_DELETIONS);
}
use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class CQLResultSetKeyIteratorTest method testUneven.
@Test
public void testUneven() throws IOException {
final Array<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> keysMap = generateRandomKeysMap();
final ResultSet resultSet = generateMockedResultSet(keysMap);
final CQLColValGetter getter = new CQLColValGetter(new EntryMetaData[0]);
try (final CQLResultSetKeyIterator resultSetKeyIterator = new CQLResultSetKeyIterator(ALL_COLUMNS, getter, resultSet)) {
final Iterator<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> iterator = keysMap.iterator();
while (resultSetKeyIterator.hasNext()) {
final StaticBuffer next = resultSetKeyIterator.next();
try (final RecordIterator<Entry> entries = resultSetKeyIterator.getEntries()) {
final Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>> current = iterator.next();
final ByteBuffer currentKey = current._1;
final Array<Tuple2<ByteBuffer, ByteBuffer>> columnValues = current._2;
final Iterator<Tuple2<ByteBuffer, ByteBuffer>> columnIterator = columnValues.iterator();
while (entries.hasNext()) {
final Entry entry = entries.next();
final Tuple2<ByteBuffer, ByteBuffer> columnAndValue = columnIterator.next();
assertEquals(currentKey, next.asByteBuffer());
assertEquals(columnAndValue._1, entry.getColumn().asByteBuffer());
assertEquals(columnAndValue._2, entry.getValue().asByteBuffer());
assertEquals(columnIterator.hasNext(), entries.hasNext());
}
}
}
}
}
use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class CqlBinaryRecordReader method completeNextKV.
private KV completeNextKV() throws IOException {
KV completedKV = null;
boolean hasNext;
do {
hasNext = reader.nextKeyValue();
if (!hasNext) {
completedKV = incompleteKV;
incompleteKV = null;
} else {
Row row = reader.getCurrentValue();
StaticArrayBuffer key = StaticArrayBuffer.of(row.getBytesUnsafe(CQLKeyColumnValueStore.KEY_COLUMN_NAME));
StaticBuffer column1 = StaticArrayBuffer.of(row.getBytesUnsafe(CQLKeyColumnValueStore.COLUMN_COLUMN_NAME));
StaticBuffer value = StaticArrayBuffer.of(row.getBytesUnsafe(CQLKeyColumnValueStore.VALUE_COLUMN_NAME));
Entry entry = StaticArrayEntry.of(column1, value);
if (null == incompleteKV) {
// Initialization; this should happen just once in an instance's lifetime
incompleteKV = new KV(key);
} else if (!incompleteKV.key.equals(key)) {
// The underlying Cassandra reader has just changed to a key we haven't seen yet
// This implies that there will be no more entries for the prior key
completedKV = incompleteKV;
incompleteKV = new KV(key);
}
incompleteKV.addEntry(entry);
}
/* Loop ends when either
* A) the cassandra reader ran out of data
* or
* B) the cassandra reader switched keys, thereby completing a KV */
} while (hasNext && null == completedKV);
return completedKV;
}
Aggregations