use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.
the class KCVSLog method add.
/**
* Adds the given message (content) to the timeslice for the partition identified by the provided partitionId.
* If a persistor is specified, this persistor is used to add the message otherwise the internal delivery systems are used.
*
* @param content
* @param partitionId
* @param persistor
* @return
*/
private Future<Message> add(StaticBuffer content, int partitionId, ExternalPersistor persistor) {
ResourceUnavailableException.verifyOpen(isOpen, "Log", name);
Preconditions.checkArgument(content != null && content.length() > 0, "Content is empty");
Preconditions.checkArgument(partitionId >= 0 && partitionId < (1 << manager.partitionBitWidth), "Invalid partition id: %s", partitionId);
final Instant timestamp = times.getTime();
KCVSMessage msg = new KCVSMessage(content, timestamp, manager.senderId);
FutureMessage futureMessage = new FutureMessage(msg);
StaticBuffer key = getLogKey(partitionId, (int) (numBucketCounter.incrementAndGet() % numBuckets), getTimeSlice(timestamp));
MessageEnvelope envelope = new MessageEnvelope(futureMessage, key, writeMessage(msg));
if (persistor != null) {
try {
persistor.add(envelope.key, envelope.entry);
envelope.message.delivered();
} catch (JanusGraphException e) {
envelope.message.failed(e);
throw e;
}
} else if (outgoingMsg == null) {
sendMessages(Collections.singletonList(envelope));
} else {
try {
// Produces back pressure when full
outgoingMsg.put(envelope);
log.debug("Enqueued {} for partition {}", envelope, partitionId);
} catch (InterruptedException e) {
throw new JanusGraphException("Got interrupted waiting to send message", e);
}
}
return futureMessage;
}
use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.
the class StandardJanusGraphTx method commit.
/*
* ------------------------------------ Transaction State ------------------------------------
*/
@Override
public synchronized void commit() {
Preconditions.checkArgument(isOpen(), "The transaction has already been closed");
boolean success = false;
if (null != config.getGroupName()) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "commit").inc();
}
try {
if (hasModifications()) {
graph.commit(addedRelations.getAll(), deletedRelations.values(), this);
} else {
txHandle.commit();
}
success = true;
} catch (Exception e) {
try {
txHandle.rollback();
} catch (BackendException e1) {
throw new JanusGraphException("Could not rollback after a failed commit", e);
}
throw new JanusGraphException("Could not commit transaction due to exception during persistence", e);
} finally {
releaseTransaction();
if (null != config.getGroupName() && !success) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "commit.exceptions").inc();
}
}
}
use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.
the class StandardJanusGraphTx method rollback.
@Override
public synchronized void rollback() {
Preconditions.checkArgument(isOpen(), "The transaction has already been closed");
boolean success = false;
if (null != config.getGroupName()) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "rollback").inc();
}
try {
txHandle.rollback();
success = true;
} catch (Exception e) {
throw new JanusGraphException("Could not rollback transaction due to exception", e);
} finally {
releaseTransaction();
if (null != config.getGroupName() && !success) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "rollback.exceptions").inc();
}
}
}
use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.
the class ReadConfigurationBuilderTest method shouldThrowExceptionOnDisallowedUpgradeAndNonEqualStorageVersions.
@Test
public void shouldThrowExceptionOnDisallowedUpgradeAndNonEqualStorageVersions() {
frozenGlobalWriteWithAllowUpgradeMock(false);
JanusGraphException exception = assertThrows(JanusGraphException.class, this::buildConfiguration);
String storageVersion = (globalWrite.has(INITIAL_STORAGE_VERSION)) ? globalWrite.get(INITIAL_STORAGE_VERSION) : "1";
assertEquals(String.format(ReadConfigurationBuilder.INCOMPATIBLE_STORAGE_VERSION_EXCEPTION, storageVersion, JanusGraphConstants.STORAGE_VERSION, null), exception.getMessage());
}
use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.
the class ManagementSystem method updateIndex.
/* --------------
Schema Update
--------------- */
@Override
public IndexJobFuture updateIndex(Index index, SchemaAction updateAction) {
Preconditions.checkArgument(index != null, "Need to provide an index");
Preconditions.checkArgument(updateAction != null, "Need to provide update action");
JanusGraphSchemaVertex schemaVertex = getSchemaVertex(index);
Set<JanusGraphSchemaVertex> dependentTypes;
Set<PropertyKeyVertex> keySubset = ImmutableSet.of();
if (index instanceof RelationTypeIndex) {
dependentTypes = ImmutableSet.of((JanusGraphSchemaVertex) ((InternalRelationType) schemaVertex).getBaseType());
if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
return null;
} else if (index instanceof JanusGraphIndex) {
IndexType indexType = schemaVertex.asIndexType();
dependentTypes = Sets.newHashSet();
if (indexType.isCompositeIndex()) {
if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
return null;
for (PropertyKey key : ((JanusGraphIndex) index).getFieldKeys()) {
dependentTypes.add((PropertyKeyVertex) key);
}
} else {
keySubset = Sets.newHashSet();
MixedIndexType mixedIndexType = (MixedIndexType) indexType;
Set<SchemaStatus> applicableStatus = updateAction.getApplicableStatus();
for (ParameterIndexField field : mixedIndexType.getFieldKeys()) {
if (applicableStatus.contains(field.getStatus()))
keySubset.add((PropertyKeyVertex) field.getFieldKey());
}
if (keySubset.isEmpty())
return null;
dependentTypes.addAll(keySubset);
}
} else
throw new UnsupportedOperationException("Updates not supported for index: " + index);
IndexIdentifier indexId = new IndexIdentifier(index);
StandardScanner.Builder builder;
IndexJobFuture future;
switch(updateAction) {
case REGISTER_INDEX:
setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
updatedTypes.add(schemaVertex);
updatedTypes.addAll(dependentTypes);
setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.REGISTERED, keySubset));
future = new EmptyIndexJobFuture();
break;
case REINDEX:
builder = graph.getBackend().buildEdgeScanJob();
builder.setFinishJob(indexId.getIndexJobFinisher(graph, SchemaAction.ENABLE_INDEX));
builder.setJobId(indexId);
builder.setJob(VertexJobConverter.convert(graph, new IndexRepairJob(indexId.indexName, indexId.relationTypeName)));
try {
future = builder.execute();
} catch (BackendException e) {
throw new JanusGraphException(e);
}
break;
case ENABLE_INDEX:
setStatus(schemaVertex, SchemaStatus.ENABLED, keySubset);
updatedTypes.add(schemaVertex);
if (!keySubset.isEmpty())
updatedTypes.addAll(dependentTypes);
future = new EmptyIndexJobFuture();
break;
case DISABLE_INDEX:
setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
updatedTypes.add(schemaVertex);
if (!keySubset.isEmpty())
updatedTypes.addAll(dependentTypes);
setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.DISABLED, keySubset));
future = new EmptyIndexJobFuture();
break;
case REMOVE_INDEX:
if (index instanceof RelationTypeIndex) {
builder = graph.getBackend().buildEdgeScanJob();
} else {
JanusGraphIndex graphIndex = (JanusGraphIndex) index;
if (graphIndex.isMixedIndex())
throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
builder = graph.getBackend().buildGraphIndexScanJob();
}
builder.setFinishJob(indexId.getIndexJobFinisher());
builder.setJobId(indexId);
builder.setJob(new IndexRemoveJob(graph, indexId.indexName, indexId.relationTypeName));
try {
future = builder.execute();
} catch (BackendException e) {
throw new JanusGraphException(e);
}
break;
default:
throw new UnsupportedOperationException("Update action not supported: " + updateAction);
}
return future;
}
Aggregations