use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method testDeleteLocksSkipsToNextLockOnPermanentStorageException.
/**
* Same as
* {@link #testDeleteLocksSkipsToNextLockAfterMaxTemporaryStorageExceptions()}
* , except instead of exceeding the temporary exception retry count on a
* lock, that lock throws a single permanent exception.
*
* @throws StorageException shoudn't happen
*/
@Test
public void testDeleteLocksSkipsToNextLockOnPermanentStorageException() throws StorageException {
ConsistentKeyLockStatus defaultLS = makeStatusNow();
currentTimeNS++;
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, defaultLS)));
List<StaticBuffer> dels = ImmutableList.of(codec.toLockCol(defaultLS.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid));
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
expectLastCall().andThrow(new PermanentStorageException("Storage cluster has been destroyed by a tornado"));
expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
// lockState.release(defaultTx, defaultLockID);
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method testDeleteLocksRetriesOnTemporaryStorageException.
/**
* Lock deletion should retry if the first store mutation throws a temporary
* exception.
*
* @throws StorageException shouldn't happen
*/
@Test
public void testDeleteLocksRetriesOnTemporaryStorageException() throws StorageException {
ConsistentKeyLockStatus defaultLS = makeStatusNow();
currentTimeNS++;
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, defaultLS)));
List<StaticBuffer> dels = ImmutableList.of(codec.toLockCol(defaultLS.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid));
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
expectLastCall().andThrow(new TemporaryStorageException("Storage cluster is backlogged"));
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
// lockState.release(defaultTx, defaultLockID);
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method recordSuccessfulLockWrite.
private LockInfo recordSuccessfulLockWrite(StoreTransaction tx, long duration, TimeUnit tu, StaticBuffer del) throws StorageException {
expect(times.getApproxNSSinceEpoch()).andReturn(++currentTimeNS);
final long lockNS = currentTimeNS;
StaticBuffer lockCol = codec.toLockCol(lockNS, defaultLockRid);
Entry add = new StaticBufferEntry(lockCol, defaultLockVal);
StaticBuffer k = eq(defaultLockKey);
// assert null != add;
final List<Entry> adds = eq(Arrays.<Entry>asList(add));
// assert null != adds;
final List<StaticBuffer> dels;
if (null != del) {
dels = eq(Arrays.<StaticBuffer>asList(del));
} else {
dels = eq(ImmutableList.<StaticBuffer>of());
}
store.mutate(k, adds, dels, eq(tx));
currentTimeNS += TimeUnit.NANOSECONDS.convert(duration, tu);
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
ConsistentKeyLockStatus status = new ConsistentKeyLockStatus(lockNS, TimeUnit.NANOSECONDS, lockNS + defaultExpireNS, TimeUnit.NANOSECONDS);
return new LockInfo(lockNS, status, lockCol);
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class StandardTitanTx method executeMultiQuery.
public void executeMultiQuery(final Collection<InternalVertex> vertices, final SliceQuery sq) {
LongArrayList vids = new LongArrayList(vertices.size());
for (InternalVertex v : vertices) {
if (!v.isNew() && v.hasId() && (v instanceof CacheVertex) && !v.hasLoadedRelations(sq))
vids.add(v.getID());
}
if (!vids.isEmpty()) {
List<List<Entry>> results = graph.edgeMultiQuery(vids, sq, txHandle);
int pos = 0;
for (TitanVertex v : vertices) {
if (pos < vids.size() && vids.get(pos) == v.getID()) {
final List<Entry> vresults = results.get(pos);
((CacheVertex) v).loadRelations(sq, new Retriever<SliceQuery, List<Entry>>() {
@Override
public List<Entry> get(SliceQuery query) {
return vresults;
}
});
pos++;
}
}
}
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry in project titan by thinkaurelius.
the class IndexSerializer method processSingleCondition.
private List<Object> processSingleCondition(ElementType resultType, PredicateCondition pc, final int limit, BackendTransaction tx) {
Preconditions.checkArgument(resultType == ElementType.EDGE || resultType == ElementType.VERTEX);
Preconditions.checkArgument(pc.getPredicate() == Cmp.EQUAL, "Only equality index retrievals are supported on standard index");
Preconditions.checkNotNull(pc.getValue());
Preconditions.checkArgument(limit >= 0);
TitanKey key = (TitanKey) pc.getKey();
Preconditions.checkArgument(key.hasIndex(Titan.Token.STANDARD_INDEX, resultType.getElementType()), "Cannot retrieve for given property key - it does not have an index [%s]", key.getName());
Object value = pc.getValue();
StaticBuffer column = getUniqueIndexColumn(key);
KeySliceQuery sq = new KeySliceQuery(getIndexKey(value), column, SliceQuery.pointRange(column), ((InternalType) key).isStatic(Direction.IN)).setLimit(limit);
List<Entry> r;
if (resultType == ElementType.VERTEX) {
r = tx.vertexIndexQuery(sq);
} else {
r = tx.edgeIndexQuery(sq);
}
List<Object> results = new ArrayList<Object>(r.size());
for (Entry entry : r) {
ReadBuffer entryValue = entry.getReadValue();
if (resultType == ElementType.VERTEX) {
results.add(VariableLong.readPositive(entryValue));
} else {
results.add(bytebuffer2RelationId(entryValue));
}
}
Preconditions.checkArgument(!(resultType == ElementType.VERTEX && key.isUnique(Direction.IN)) || results.size() <= 1);
return results;
}
Aggregations