Search in sources :

Example 1 with TitanException

use of com.thinkaurelius.titan.core.TitanException in project titan by thinkaurelius.

the class StandardIDPool method nextID.

@Override
public synchronized long nextID() {
    assert currentIndex <= currentBlock.numIds();
    if (currentIndex == currentBlock.numIds()) {
        try {
            nextBlock();
        } catch (InterruptedException e) {
            throw new TitanException("Could not renew id block due to interruption", e);
        }
    }
    if (currentIndex == renewBlockIndex) {
        startIDBlockGetter();
    }
    long returnId = currentBlock.getId(currentIndex);
    currentIndex++;
    if (returnId >= idUpperBound)
        throw new IDPoolExhaustedException("Reached id upper bound of " + idUpperBound);
    log.trace("partition({})-namespace({}) Returned id: {}", partition, idNamespace, returnId);
    return returnId;
}
Also used : TitanException(com.thinkaurelius.titan.core.TitanException)

Example 2 with TitanException

use of com.thinkaurelius.titan.core.TitanException in project titan by thinkaurelius.

the class BackendTransaction method edgeStoreMultiQuery.

public Map<StaticBuffer, EntryList> edgeStoreMultiQuery(final List<StaticBuffer> keys, final SliceQuery query) {
    if (storeFeatures.hasMultiQuery()) {
        return executeRead(new Callable<Map<StaticBuffer, EntryList>>() {

            @Override
            public Map<StaticBuffer, EntryList> call() throws Exception {
                return cacheEnabled ? edgeStore.getSlice(keys, query, storeTx) : edgeStore.getSliceNoCache(keys, query, storeTx);
            }

            @Override
            public String toString() {
                return "MultiEdgeStoreQuery";
            }
        });
    } else {
        final Map<StaticBuffer, EntryList> results = new HashMap<StaticBuffer, EntryList>(keys.size());
        if (threadPool == null || keys.size() < MIN_TASKS_TO_PARALLELIZE) {
            for (StaticBuffer key : keys) {
                results.put(key, edgeStoreQuery(new KeySliceQuery(key, query)));
            }
        } else {
            final CountDownLatch doneSignal = new CountDownLatch(keys.size());
            final AtomicInteger failureCount = new AtomicInteger(0);
            EntryList[] resultArray = new EntryList[keys.size()];
            for (int i = 0; i < keys.size(); i++) {
                threadPool.execute(new SliceQueryRunner(new KeySliceQuery(keys.get(i), query), doneSignal, failureCount, resultArray, i));
            }
            try {
                doneSignal.await();
            } catch (InterruptedException e) {
                throw new TitanException("Interrupted while waiting for multi-query to complete", e);
            }
            if (failureCount.get() > 0) {
                throw new TitanException("Could not successfully complete multi-query. " + failureCount.get() + " individual queries failed.");
            }
            for (int i = 0; i < keys.size(); i++) {
                assert resultArray[i] != null;
                results.put(keys.get(i), resultArray[i]);
            }
        }
        return results;
    }
}
Also used : HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) TitanException(com.thinkaurelius.titan.core.TitanException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TitanException(com.thinkaurelius.titan.core.TitanException) HashMap(java.util.HashMap) Map(java.util.Map) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Example 3 with TitanException

use of com.thinkaurelius.titan.core.TitanException 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 TitanException

use of com.thinkaurelius.titan.core.TitanException 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 TitanException

use of com.thinkaurelius.titan.core.TitanException in project titan by thinkaurelius.

the class ManagementUtil method awaitIndexUpdate.

private static void awaitIndexUpdate(TitanGraph g, String indexName, String relationTypeName, long time, TemporalUnit unit) {
    Preconditions.checkArgument(g != null && g.isOpen(), "Need to provide valid, open graph instance");
    Preconditions.checkArgument(time > 0 && unit != null, "Need to provide valid time interval");
    Preconditions.checkArgument(StringUtils.isNotBlank(indexName), "Need to provide an index name");
    StandardTitanGraph graph = (StandardTitanGraph) g;
    TimestampProvider times = graph.getConfiguration().getTimestampProvider();
    Instant end = times.getTime().plus(Duration.of(time, unit));
    boolean isStable = false;
    while (times.getTime().isBefore(end)) {
        TitanManagement mgmt = graph.openManagement();
        try {
            if (StringUtils.isNotBlank(relationTypeName)) {
                RelationTypeIndex idx = mgmt.getRelationIndex(mgmt.getRelationType(relationTypeName), indexName);
                Preconditions.checkArgument(idx != null, "Index could not be found: %s @ %s", indexName, relationTypeName);
                isStable = idx.getIndexStatus().isStable();
            } else {
                TitanGraphIndex idx = mgmt.getGraphIndex(indexName);
                Preconditions.checkArgument(idx != null, "Index could not be found: %s", indexName);
                isStable = true;
                for (PropertyKey key : idx.getFieldKeys()) {
                    if (!idx.getIndexStatus(key).isStable())
                        isStable = false;
                }
            }
        } finally {
            mgmt.rollback();
        }
        if (isStable)
            break;
        try {
            times.sleepFor(Duration.ofMillis(500));
        } catch (InterruptedException e) {
        }
    }
    if (!isStable)
        throw new TitanException("Index did not stabilize within the given amount of time. For sufficiently long " + "wait periods this is most likely caused by a failed/incorrectly shut down Titan instance or a lingering transaction.");
}
Also used : StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) TimestampProvider(com.thinkaurelius.titan.diskstorage.util.time.TimestampProvider) Instant(java.time.Instant) TitanException(com.thinkaurelius.titan.core.TitanException) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Aggregations

TitanException (com.thinkaurelius.titan.core.TitanException)19 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)4 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)3 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)3 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)3 StandardTitanGraph (com.thinkaurelius.titan.graphdb.database.StandardTitanGraph)3 CompositeIndexType (com.thinkaurelius.titan.graphdb.types.CompositeIndexType)3 IndexType (com.thinkaurelius.titan.graphdb.types.IndexType)3 TitanSchemaVertex (com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)3 List (java.util.List)3 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)2 ScanMetrics (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)2 StandardScanner (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.StandardScanner)2 StandardIDPool (com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Function (com.google.common.base.Function)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1