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);
}
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);
}
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");
}
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);
}
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);
}
}
Aggregations