Search in sources :

Example 1 with Entry

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());
}
Also used : HashMap(java.util.HashMap) KCVMutation(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation) QueryPath(org.apache.cassandra.db.filter.QueryPath) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) RowMutation(org.apache.cassandra.db.RowMutation) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 2 with Entry

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;
}
Also used : ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) ByteBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.ByteBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) ByteBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.ByteBufferEntry) Column(org.apache.cassandra.thrift.Column) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) ArrayList(java.util.ArrayList)

Example 3 with Entry

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;
}
Also used : Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) ByteBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.ByteBufferEntry) ByteBuffer(java.nio.ByteBuffer) StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer)

Example 4 with Entry

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

Example 5 with Entry

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

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