use of com.thinkaurelius.titan.diskstorage.StorageException 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.StorageException in project titan by thinkaurelius.
the class MetricInstrumentedStore method runWithMetrics.
static <T> T runWithMetrics(String prefix, String storeName, String name, StorageCallable<T> impl) throws StorageException {
if (null == prefix) {
return impl.call();
}
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(impl);
final MetricManager mgr = MetricManager.INSTANCE;
mgr.getCounter(prefix, storeName, name, M_CALLS).inc();
final Timer.Context tc = mgr.getTimer(prefix, storeName, name, M_TIME).time();
try {
return impl.call();
} catch (StorageException e) {
mgr.getCounter(prefix, storeName, name, M_EXCEPTIONS).inc();
throw e;
} catch (RuntimeException e) {
mgr.getCounter(prefix, storeName, name, M_EXCEPTIONS).inc();
throw e;
} finally {
tc.stop();
}
}
use of com.thinkaurelius.titan.diskstorage.StorageException 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.StorageException in project titan by thinkaurelius.
the class ElasticSearchIndex method register.
@Override
public void register(String store, String key, KeyInformation information, TransactionHandle tx) throws StorageException {
XContentBuilder mapping = null;
Class<?> dataType = information.getDataType();
Mapping map = Mapping.getMapping(information);
Preconditions.checkArgument(map == Mapping.DEFAULT || AttributeUtil.isString(dataType), "Specified illegal mapping [%s] for data type [%s]", map, dataType);
try {
mapping = XContentFactory.jsonBuilder().startObject().startObject(store).startObject("properties").startObject(key);
if (AttributeUtil.isString(dataType)) {
log.debug("Registering string type for {}", key);
mapping.field("type", "string");
if (map == Mapping.STRING)
mapping.field("index", "not_analyzed");
} else if (dataType == Float.class || dataType == FullFloat.class) {
log.debug("Registering float type for {}", key);
mapping.field("type", "float");
} else if (dataType == Double.class || dataType == FullDouble.class) {
log.debug("Registering double type for {}", key);
mapping.field("type", "double");
} else if (dataType == Byte.class) {
log.debug("Registering byte type for {}", key);
mapping.field("type", "byte");
} else if (dataType == Short.class) {
log.debug("Registering short type for {}", key);
mapping.field("type", "short");
} else if (dataType == Integer.class) {
log.debug("Registering integer type for {}", key);
mapping.field("type", "integer");
} else if (dataType == Long.class) {
log.debug("Registering long type for {}", key);
mapping.field("type", "long");
} else if (dataType == Boolean.class) {
log.debug("Registering boolean type for {}", key);
mapping.field("type", "boolean");
} else if (dataType == Geoshape.class) {
log.debug("Registering geo_point type for {}", key);
mapping.field("type", "geo_point");
}
mapping.endObject().endObject().endObject().endObject();
} catch (IOException e) {
throw new PermanentStorageException("Could not render json for put mapping request", e);
}
try {
PutMappingResponse response = client.admin().indices().preparePutMapping(indexName).setIgnoreConflicts(false).setType(store).setSource(mapping).execute().actionGet();
} catch (Exception e) {
throw convert(e);
}
}
Aggregations