Search in sources :

Example 86 with StaticBuffer

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

the class ConsistentKeyLocker method tryWriteLockOnce.

private WriteResult tryWriteLockOnce(StaticBuffer key, StaticBuffer del, StoreTransaction txh) {
    Throwable t = null;
    final long before = times.getApproxNSSinceEpoch();
    StaticBuffer newLockCol = serializer.toLockCol(before, rid);
    Entry newLockEntry = new StaticBufferEntry(newLockCol, zeroBuf);
    try {
        store.mutate(key, Arrays.asList(newLockEntry), null == del ? ImmutableList.<StaticBuffer>of() : Arrays.asList(del), overrideTimestamp(txh, before));
    } catch (StorageException e) {
        t = e;
    }
    final long after = times.getApproxNSSinceEpoch();
    return new WriteResult(before, after, newLockCol, t);
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException)

Example 87 with StaticBuffer

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

the class OrderedKeyValueStoreManagerAdapter method mutateMany.

@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws StorageException {
    Map<String, KVMutation> converted = new HashMap<String, KVMutation>(mutations.size());
    for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> storeEntry : mutations.entrySet()) {
        OrderedKeyValueStoreAdapter store = openDatabase(storeEntry.getKey());
        Preconditions.checkNotNull(store);
        KVMutation mut = new KVMutation();
        for (Map.Entry<StaticBuffer, KCVMutation> entry : storeEntry.getValue().entrySet()) {
            StaticBuffer key = entry.getKey();
            KCVMutation mutation = entry.getValue();
            if (mutation.hasAdditions()) {
                for (Entry addition : mutation.getAdditions()) {
                    mut.addition(new KeyValueEntry(store.concatenate(key, addition.getColumn()), addition.getValue()));
                }
            }
            if (mutation.hasDeletions()) {
                for (StaticBuffer column : mutation.getDeletions()) {
                    mut.deletion(store.concatenate(key, column));
                }
            }
        }
        converted.put(storeEntry.getKey(), mut);
    }
    manager.mutateMany(converted, txh);
}
Also used : HashMap(java.util.HashMap) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 88 with StaticBuffer

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

the class TransactionalIDManager method getIDBlock.

@Override
public long[] getIDBlock(int partition) throws StorageException {
    long blockSize = getBlockSize(partition);
    StaticBuffer partitionKey = getPartitionKey(partition);
    for (int retry = 0; retry < idApplicationRetryCount; retry++) {
        StoreTransaction txh = null;
        try {
            txh = manager.beginTransaction(new StoreTxConfig(metricsPrefix));
            long current = getCurrentID(partitionKey, txh);
            if (Long.MAX_VALUE - blockSize <= current) {
                throw new IDPoolExhaustedException("Exhausted id block for partition [" + partition + "]");
            }
            assert Long.MAX_VALUE - blockSize > current;
            long next = current + blockSize;
            idStore.mutate(partitionKey, ImmutableList.of(StaticBufferEntry.of(DEFAULT_COLUMN, ByteBufferUtil.getLongBuffer(next))), KeyColumnValueStore.NO_DELETIONS, txh);
            txh.commit();
            return new long[] { current, next };
        } catch (StorageException e) {
            log.warn("Storage exception while allocating id block - retrying in {} ms: {}", idApplicationWaitMS, e);
            if (txh != null)
                txh.rollback();
            if (idApplicationWaitMS > 0)
                TimeUtility.INSTANCE.sleepUntil(System.currentTimeMillis() + idApplicationWaitMS, log);
        }
    }
    throw new TemporaryLockingException("Exceeded timeout count [" + idApplicationRetryCount + "] when attempting to allocate next id block");
}
Also used : IDPoolExhaustedException(com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) TemporaryLockingException(com.thinkaurelius.titan.diskstorage.locking.TemporaryLockingException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException)

Example 89 with StaticBuffer

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

the class HBaseStoreManager method mutateMany.

@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws StorageException {
    // TODO: use same timestamp functionality as Cassandra
    // final Timestamp timestamp = super.getTimestamp(txh);
    // Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = convertToCommands(mutations, timestamp.additionTime, timestamp.deletionTime);
    final long delTS = System.currentTimeMillis();
    final long putTS = delTS + 1;
    Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = convertToCommands(mutations, putTS, delTS);
    // actual batch operation
    List<Row> batch = new ArrayList<Row>(commandsPerKey.size());
    // convert sorted commands into representation required for 'batch' operation
    for (Pair<Put, Delete> commands : commandsPerKey.values()) {
        if (commands.getFirst() != null)
            batch.add(commands.getFirst());
        if (commands.getSecond() != null)
            batch.add(commands.getSecond());
    }
    try {
        HTableInterface table = null;
        try {
            table = connectionPool.getTable(tableName);
            table.batch(batch);
            table.flushCommits();
        } finally {
            IOUtils.closeQuietly(table);
        }
    } catch (IOException e) {
        throw new TemporaryStorageException(e);
    } catch (InterruptedException e) {
        throw new TemporaryStorageException(e);
    }
    waitUntil(putTS);
}
Also used : IOException(java.io.IOException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Pair(org.apache.hadoop.hbase.util.Pair)

Example 90 with StaticBuffer

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

the class HBaseKeyColumnValueStore method getHelper.

private List<List<Entry>> getHelper(List<StaticBuffer> keys, Filter getFilter) throws StorageException {
    List<Get> requests = new ArrayList<Get>(keys.size());
    {
        for (StaticBuffer key : keys) {
            requests.add(new Get(key.as(StaticBuffer.ARRAY_FACTORY)).addFamily(columnFamilyBytes).setFilter(getFilter));
        }
    }
    List<List<Entry>> results = new ArrayList<List<Entry>>();
    try {
        HTableInterface table = null;
        Result[] r = null;
        try {
            table = pool.getTable(tableName);
            r = table.get(requests);
        } finally {
            IOUtils.closeQuietly(table);
        }
        if (r == null)
            return Collections.emptyList();
        for (Result result : r) {
            List<Entry> entries = new ArrayList<Entry>(result.size());
            Map<byte[], byte[]> fmap = result.getFamilyMap(columnFamilyBytes);
            if (null != fmap) {
                for (Map.Entry<byte[], byte[]> ent : fmap.entrySet()) {
                    entries.add(StaticBufferEntry.of(new StaticArrayBuffer(ent.getKey()), new StaticArrayBuffer(ent.getValue())));
                }
            }
            results.add(entries);
        }
        return results;
    } catch (IOException e) {
        throw new TemporaryStorageException(e);
    }
}
Also used : StaticArrayBuffer(com.thinkaurelius.titan.diskstorage.util.StaticArrayBuffer) IOException(java.io.IOException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ImmutableMap(com.google.common.collect.ImmutableMap)

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