Search in sources :

Example 1 with BackendException

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

the class KCVSConfiguration method toMap.

private Map<String, Object> toMap() {
    Map<String, Object> entries = Maps.newHashMap();
    List<Entry> result = BackendOperation.execute(new BackendOperation.Transactional<List<Entry>>() {

        @Override
        public List<Entry> call(StoreTransaction txh) throws BackendException {
            return store.getSlice(new KeySliceQuery(rowKey, BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)), txh);
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
    for (Entry entry : result) {
        String key = staticBuffer2String(entry.getColumnAs(StaticBuffer.STATIC_FACTORY));
        Object value = staticBuffer2Object(entry.getValueAs(StaticBuffer.STATIC_FACTORY), Object.class);
        entries.put(key, value);
    }
    return entries;
}
Also used : Entry(com.thinkaurelius.titan.diskstorage.Entry) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) ArrayList(java.util.ArrayList) List(java.util.List) BackendOperation(com.thinkaurelius.titan.diskstorage.util.BackendOperation) BackendException(com.thinkaurelius.titan.diskstorage.BackendException)

Example 2 with BackendException

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

the class KCVSConfiguration method get.

/**
     * Reads the configuration property for this StoreManager
     *
     * @param key Key identifying the configuration property
     * @return Value stored for the key or null if the configuration property has not (yet) been defined.
     * @throws com.thinkaurelius.titan.diskstorage.BackendException
     */
@Override
public <O> O get(final String key, final Class<O> datatype) {
    StaticBuffer column = string2StaticBuffer(key);
    final KeySliceQuery query = new KeySliceQuery(rowKey, column, BufferUtil.nextBiggerBuffer(column));
    StaticBuffer result = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() {

        @Override
        public StaticBuffer call(StoreTransaction txh) throws BackendException {
            List<Entry> entries = store.getSlice(query, txh);
            if (entries.isEmpty())
                return null;
            return entries.get(0).getValueAs(StaticBuffer.STATIC_FACTORY);
        }

        @Override
        public String toString() {
            return "getConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
    if (result == null)
        return null;
    return staticBuffer2Object(result, datatype);
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ArrayList(java.util.ArrayList) List(java.util.List) BackendOperation(com.thinkaurelius.titan.diskstorage.util.BackendOperation) BackendException(com.thinkaurelius.titan.diskstorage.BackendException)

Example 3 with BackendException

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

the class KCVSConfiguration method close.

@Override
public void close() {
    try {
        store.close();
        txProvider.close();
        IOUtils.closeQuietly(serializer);
    } catch (BackendException e) {
        throw new TitanException("Could not close configuration store", e);
    }
}
Also used : TitanException(com.thinkaurelius.titan.core.TitanException) BackendException(com.thinkaurelius.titan.diskstorage.BackendException)

Example 4 with BackendException

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

the class ManagementSystem method addIndexKey.

@Override
public void addIndexKey(final TitanGraphIndex index, final PropertyKey key, Parameter... parameters) {
    Preconditions.checkArgument(index != null && key != null && index instanceof TitanGraphIndexWrapper && !(key instanceof BaseKey), "Need to provide valid index and key");
    if (parameters == null)
        parameters = new Parameter[0];
    IndexType indexType = ((TitanGraphIndexWrapper) index).getBaseIndex();
    Preconditions.checkArgument(indexType instanceof MixedIndexType, "Can only add keys to an external index, not %s", index.name());
    Preconditions.checkArgument(indexType instanceof IndexTypeWrapper && key instanceof TitanSchemaVertex && ((IndexTypeWrapper) indexType).getSchemaBase() instanceof TitanSchemaVertex);
    TitanSchemaVertex indexVertex = (TitanSchemaVertex) ((IndexTypeWrapper) indexType).getSchemaBase();
    for (IndexField field : indexType.getFieldKeys()) Preconditions.checkArgument(!field.getFieldKey().equals(key), "Key [%s] has already been added to index %s", key.name(), index.name());
    //Assemble parameters
    boolean addMappingParameter = !ParameterType.MAPPED_NAME.hasParameter(parameters);
    Parameter[] extendedParas = new Parameter[parameters.length + 1 + (addMappingParameter ? 1 : 0)];
    System.arraycopy(parameters, 0, extendedParas, 0, parameters.length);
    int arrPosition = parameters.length;
    if (addMappingParameter)
        extendedParas[arrPosition++] = ParameterType.MAPPED_NAME.getParameter(graph.getIndexSerializer().getDefaultFieldName(key, parameters, indexType.getBackingIndexName()));
    extendedParas[arrPosition++] = ParameterType.STATUS.getParameter(key.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
    addSchemaEdge(indexVertex, key, TypeDefinitionCategory.INDEX_FIELD, extendedParas);
    updateSchemaVertex(indexVertex);
    indexType.resetCache();
    //Check to see if the index supports this
    if (!graph.getIndexSerializer().supports((MixedIndexType) indexType, ParameterIndexField.of(key, parameters))) {
        throw new TitanException("Could not register new index field '" + key.name() + "' with index backend as the data type, cardinality or parameter combination is not supported.");
    }
    try {
        IndexSerializer.register((MixedIndexType) indexType, key, transaction.getTxHandle());
    } catch (BackendException e) {
        throw new TitanException("Could not register new index field with index backend", e);
    }
    if (!indexVertex.isNew())
        updatedTypes.add(indexVertex);
    if (!key.isNew())
        updateIndex(index, SchemaAction.REGISTER_INDEX);
}
Also used : MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) BaseKey(com.thinkaurelius.titan.graphdb.types.system.BaseKey) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) IndexTypeWrapper(com.thinkaurelius.titan.graphdb.types.indextype.IndexTypeWrapper) TitanException(com.thinkaurelius.titan.core.TitanException) Parameter(com.thinkaurelius.titan.core.schema.Parameter) IndexType(com.thinkaurelius.titan.graphdb.types.IndexType) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) IndexField(com.thinkaurelius.titan.graphdb.types.IndexField) ParameterIndexField(com.thinkaurelius.titan.graphdb.types.ParameterIndexField)

Example 5 with BackendException

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

the class MetricInstrumentedStore method runWithMetrics.

static <T> T runWithMetrics(StoreTransaction txh, String storeName, String name, StorageCallable<T> impl) throws BackendException {
    if (!txh.getConfiguration().hasGroupName()) {
        return impl.call();
    }
    String prefix = txh.getConfiguration().getGroupName();
    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 (BackendException 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) BackendException(com.thinkaurelius.titan.diskstorage.BackendException)

Aggregations

BackendException (com.thinkaurelius.titan.diskstorage.BackendException)25 ArrayList (java.util.ArrayList)7 PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)6 TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)6 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)6 TException (org.apache.thrift.TException)6 List (java.util.List)5 TitanException (com.thinkaurelius.titan.core.TitanException)4 BackendOperation (com.thinkaurelius.titan.diskstorage.util.BackendOperation)4 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 KeeperException (org.apache.zookeeper.KeeperException)3 Timer (com.codahale.metrics.Timer)2 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)2 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)2 Entry (com.thinkaurelius.titan.diskstorage.Entry)2 IndexEntry (com.thinkaurelius.titan.diskstorage.indexing.IndexEntry)2