Search in sources :

Example 26 with StorageException

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);
}
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 27 with StorageException

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();
    }
}
Also used : MetricManager(com.thinkaurelius.titan.util.stats.MetricManager) Timer(com.codahale.metrics.Timer) StorageException(com.thinkaurelius.titan.diskstorage.StorageException)

Example 28 with StorageException

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");
}
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 29 with StorageException

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);
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) Mapping(com.thinkaurelius.titan.core.Mapping) IOException(java.io.IOException) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticSearchInterruptedException(org.elasticsearch.ElasticSearchInterruptedException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TitanException(com.thinkaurelius.titan.core.TitanException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) IndexMissingException(org.elasticsearch.indices.IndexMissingException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) IOException(java.io.IOException)

Aggregations

StorageException (com.thinkaurelius.titan.diskstorage.StorageException)29 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)22 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)20 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)9 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)9 TException (org.apache.thrift.TException)9 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)8 ArrayList (java.util.ArrayList)7 Cassandra (org.apache.cassandra.thrift.Cassandra)7 TitanException (com.thinkaurelius.titan.core.TitanException)6 NotFoundException (org.apache.cassandra.thrift.NotFoundException)6 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)6 SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)5 IOException (java.io.IOException)4 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 CfDef (org.apache.cassandra.thrift.CfDef)4 ColumnParent (org.apache.cassandra.thrift.ColumnParent)4 KsDef (org.apache.cassandra.thrift.KsDef)4 SliceRange (org.apache.cassandra.thrift.SliceRange)4