Search in sources :

Example 6 with Entry

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);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Example 7 with Entry

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);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Example 8 with Entry

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);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)

Example 9 with Entry

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++;
            }
        }
    }
}
Also used : Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) LongArrayList(com.carrotsearch.hppc.LongArrayList) LongArrayList(com.carrotsearch.hppc.LongArrayList) CacheVertex(com.thinkaurelius.titan.graphdb.vertices.CacheVertex) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Example 10 with Entry

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;
}
Also used : InternalType(com.thinkaurelius.titan.graphdb.internal.InternalType) StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Aggregations

Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)18 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)14 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)10 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)8 Test (org.junit.Test)7 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)5 HashMap (java.util.HashMap)5 ByteBuffer (java.nio.ByteBuffer)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)3 ByteBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.ByteBufferEntry)3 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)3 KeyColumn (com.thinkaurelius.titan.diskstorage.util.KeyColumn)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)2 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)2 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)2 StaticByteBuffer (com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer)2 List (java.util.List)2