use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class CassandraEmbeddedStoreManager method mutateMany.
/*
* This implementation can't handle counter columns.
*
* The private method internal_batch_mutate in CassandraServer as of 1.2.0
* provided most of the following method after transaction handling.
*/
@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws StorageException {
Preconditions.checkNotNull(mutations);
final Timestamp timestamp = getTimestamp(txh);
int size = 0;
for (Map<StaticBuffer, KCVMutation> mutation : mutations.values()) size += mutation.size();
Map<StaticBuffer, RowMutation> rowMutations = new HashMap<StaticBuffer, RowMutation>(size);
for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> mutEntry : mutations.entrySet()) {
String columnFamily = mutEntry.getKey();
for (Map.Entry<StaticBuffer, KCVMutation> titanMutation : mutEntry.getValue().entrySet()) {
StaticBuffer key = titanMutation.getKey();
KCVMutation mut = titanMutation.getValue();
RowMutation rm = rowMutations.get(key);
if (rm == null) {
rm = new RowMutation(keySpaceName, key.asByteBuffer());
rowMutations.put(key, rm);
}
if (mut.hasAdditions()) {
for (Entry e : mut.getAdditions()) {
// TODO are these asByteBuffer() calls too expensive?
QueryPath path = new QueryPath(columnFamily, null, e.getColumn().asByteBuffer());
rm.add(path, e.getValue().asByteBuffer(), timestamp.additionTime);
}
}
if (mut.hasDeletions()) {
for (StaticBuffer col : mut.getDeletions()) {
QueryPath path = new QueryPath(columnFamily, null, col.asByteBuffer());
rm.delete(path, timestamp.deletionTime);
}
}
}
}
mutate(new ArrayList<RowMutation>(rowMutations.values()), getTx(txh).getWriteConsistencyLevel().getDBConsistency());
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class CassandraThriftKeyColumnValueStore method excludeLastColumn.
private static List<Entry> excludeLastColumn(List<ColumnOrSuperColumn> row, ByteBuffer lastColumn) {
List<Entry> entries = new ArrayList<Entry>();
for (ColumnOrSuperColumn r : row) {
Column c = r.getColumn();
// Skip column if it is equal to columnEnd because columnEnd is exclusive
if (lastColumn.equals(c.bufferForName()))
break;
entries.add(new ByteBufferEntry(c.bufferForName(), c.bufferForValue()));
}
return entries;
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class CassandraThriftKeyColumnValueStore method getSlice.
/**
* Call Cassandra's Thrift get_slice() method.
* <p/>
* When columnEnd equals columnStart, and both startInclusive
* and endInclusive are true, then this method calls
* {@link #get(java.nio.ByteBuffer, java.nio.ByteBuffer, com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)}
* instead of calling Thrift's getSlice() method and returns
* a one-element list containing the result.
* <p/>
* When columnEnd equals columnStart and either startInclusive
* or endInclusive is false (or both are false), then this
* method returns an empty list without making any Thrift calls.
* <p/>
* If columnEnd = columnStart + 1, and both startInclusive and
* startExclusive are false, then the arguments effectively form
* an empty interval. In this case, as in the one previous,
* an empty list is returned. However, it may not necessarily
* be handled efficiently; a Thrift call might still be made
* before returning the empty list.
*
* @throws com.thinkaurelius.titan.diskstorage.StorageException
* when columnEnd < columnStart
*/
@Override
public List<Entry> getSlice(KeySliceQuery query, StoreTransaction txh) throws StorageException {
ByteBuffer key = query.getKey().asByteBuffer();
List<Entry> slice = getNamesSlice(Arrays.asList(query.getKey()), query, txh).get(key);
return (slice == null) ? Collections.<Entry>emptyList() : slice;
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class ExpirationStoreCache method multiQuery.
@Override
public List<List<Entry>> multiQuery(List<StaticBuffer> keys, SliceQuery query, BackendTransaction tx) {
List<Entry>[] results = (List<Entry>[]) new List[keys.size()];
List<StaticBuffer> remainingKeys = new ArrayList<StaticBuffer>(keys.size());
KeySliceQuery[] ksqs = new KeySliceQuery[keys.size()];
for (int i = 0; i < keys.size(); i++) {
StaticBuffer key = keys.get(i);
ksqs[i] = new KeySliceQuery(key, query);
List<Entry> result = null;
if (!isExpired(ksqs[i]))
result = cache.getIfPresent(ksqs[i]);
else
ksqs[i] = null;
if (result != null)
results[i] = result;
else
remainingKeys.add(key);
}
List<List<Entry>> subresults = tx.edgeStoreMultiQuery(remainingKeys, query);
int pos = 0;
for (int i = 0; i < results.length; i++) {
if (results[i] != null)
continue;
assert pos < subresults.size();
List<Entry> subresult = subresults.get(pos);
assert subresult != null;
results[i] = subresult;
if (ksqs[i] != null)
cache.put(ksqs[i], subresult);
pos++;
}
assert pos == subresults.size();
return Arrays.asList(results);
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method testDeleteLocksInSimplestCase.
/**
* Delete a single lock without any timeouts, errors, etc.
*
* @throws StorageException shouldn't happen
*/
@Test
public void testDeleteLocksInSimplestCase() throws StorageException {
// Setup a LockStatus for defaultLockID
final ConsistentKeyLockStatus lockStatus = makeStatusNow();
currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
@SuppressWarnings("serial") Map<KeyColumn, ConsistentKeyLockStatus> expectedMap = new HashMap<KeyColumn, ConsistentKeyLockStatus>() {
{
put(defaultLockID, lockStatus);
}
};
expect(lockState.getLocksForTx(defaultTx)).andReturn(expectedMap);
StaticBuffer del = codec.toLockCol(lockStatus.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid);
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(Arrays.asList(del)), eq(defaultTx));
expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
ctrl.replay();
locker.deleteLocks(defaultTx);
}
Aggregations