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