Search in sources :

Example 91 with StaticBuffer

use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.

the class HBaseKeyColumnValueStore method makeDeletionCommand.

/**
 * Convert deletions to a Delete command.
 *
 * @param cfName    The name of the ColumnFamily deletions belong to
 * @param key       The row key
 * @param deletions The name of the columns to delete (a.k.a deletions)
 * @return Delete command or null if deletions were null or empty.
 */
private static Delete makeDeletionCommand(byte[] cfName, byte[] key, List<StaticBuffer> deletions) {
    Preconditions.checkArgument(!deletions.isEmpty());
    Delete deleteCommand = new Delete(key);
    for (StaticBuffer del : deletions) {
        deleteCommand.deleteColumn(cfName, del.as(StaticBuffer.ARRAY_FACTORY));
    }
    return deleteCommand;
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 92 with StaticBuffer

use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.

the class HBaseStoreManager method convertToCommands.

/**
 * Convert Titan internal Mutation representation into HBase native commands.
 *
 * @param mutations    Mutations to convert into HBase commands.
 * @param putTimestamp The timestamp to use for Put commands.
 * @param delTimestamp The timestamp to use for Delete commands.
 * @return Commands sorted by key converted from Titan internal representation.
 * @throws PermanentStorageException
 */
private Map<StaticBuffer, Pair<Put, Delete>> convertToCommands(Map<String, Map<StaticBuffer, KCVMutation>> mutations, final long putTimestamp, final long delTimestamp) throws PermanentStorageException {
    Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = new HashMap<StaticBuffer, Pair<Put, Delete>>();
    for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> entry : mutations.entrySet()) {
        String cfString = getCfNameForStoreName(entry.getKey());
        byte[] cfName = cfString.getBytes();
        for (Map.Entry<StaticBuffer, KCVMutation> m : entry.getValue().entrySet()) {
            StaticBuffer key = m.getKey();
            KCVMutation mutation = m.getValue();
            Pair<Put, Delete> commands = commandsPerKey.get(key);
            if (commands == null) {
                commands = new Pair<Put, Delete>();
                commandsPerKey.put(key, commands);
            }
            if (mutation.hasDeletions()) {
                if (commands.getSecond() == null)
                    commands.setSecond(new Delete(key.as(StaticBuffer.ARRAY_FACTORY), delTimestamp, null));
                for (StaticBuffer b : mutation.getDeletions()) {
                    commands.getSecond().deleteColumns(cfName, b.as(StaticBuffer.ARRAY_FACTORY), delTimestamp);
                }
            }
            if (mutation.hasAdditions()) {
                if (commands.getFirst() == null)
                    commands.setFirst(new Put(key.as(StaticBuffer.ARRAY_FACTORY), putTimestamp));
                for (Entry e : mutation.getAdditions()) {
                    commands.getFirst().add(cfName, e.getArrayColumn(), putTimestamp, e.getArrayValue());
                }
            }
        }
    }
    return commandsPerKey;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConcurrentMap(java.util.concurrent.ConcurrentMap) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Pair(org.apache.hadoop.hbase.util.Pair)

Aggregations

StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)92 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)16 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)15 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)14 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)13 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)13 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)12 HashMap (java.util.HashMap)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Entry (com.thinkaurelius.titan.diskstorage.Entry)10 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)10 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)9 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)8 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)7 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)6 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)6 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)6 Instant (java.time.Instant)6