use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class RelationIdentifier method findRelation.
JanusGraphRelation findRelation(JanusGraphTransaction tx) {
JanusGraphVertex v = ((StandardJanusGraphTx) tx).getInternalVertex(outVertexId);
if (v == null || v.isRemoved())
return null;
JanusGraphVertex typeVertex = tx.getVertex(typeId);
if (typeVertex == null)
return null;
if (!(typeVertex instanceof RelationType))
throw new IllegalArgumentException("Invalid RelationIdentifier: typeID does not reference a type");
RelationType type = (RelationType) typeVertex;
Iterable<? extends JanusGraphRelation> relations;
if (((RelationType) typeVertex).isEdgeLabel()) {
Direction dir = Direction.OUT;
JanusGraphVertex other = ((StandardJanusGraphTx) tx).getInternalVertex(inVertexId);
if (other == null || other.isRemoved())
return null;
if (((StandardJanusGraphTx) tx).isPartitionedVertex(v) && !((StandardJanusGraphTx) tx).isPartitionedVertex(other)) {
// Swap for likely better performance
JanusGraphVertex tmp = other;
other = v;
v = tmp;
dir = Direction.IN;
}
relations = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges();
} else {
relations = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties();
}
for (JanusGraphRelation r : relations) {
// Find current or previous relation
if (r.longId() == relationId || ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId))
return r;
}
return null;
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class PartitionedVertexProgramExecutor method run.
public void run(int numThreads, ScanMetrics metrics) {
StandardJanusGraphTx tx = null;
Map<Long, EntryList> pVertexAggregates = vertexMemory.retrievePartitionAggregates();
// Nothing to do here
if (pVertexAggregates.isEmpty())
return;
try (WorkerPool workers = new WorkerPool(numThreads)) {
tx = VertexJobConverter.startTransaction(graph);
for (Map.Entry<Long, EntryList> partitionedVertices : pVertexAggregates.entrySet()) {
if (partitionedVertices.getValue() == null) {
metrics.incrementCustom(GHOST_PARTITION_VERTEX);
continue;
}
workers.submit(new PartitionedVertexProcessor(partitionedVertices.getKey(), partitionedVertices.getValue(), tx, metrics));
}
} catch (Throwable ex) {
log.error("Could not post-process partitioned vertices", ex);
metrics.incrementCustom(PARTITION_VERTEX_POSTFAIL);
} finally {
if (tx != null && tx.isOpen())
tx.rollback();
}
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class IndexRemoveJob method getQueries.
@Override
public List<SliceQuery> getQueries() {
if (isGlobalGraphIndex()) {
// Everything
return ImmutableList.of(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)));
} else {
RelationTypeIndexWrapper wrapper = (RelationTypeIndexWrapper) index;
InternalRelationType wrappedType = wrapper.getWrappedType();
Direction direction = null;
for (Direction dir : Direction.values()) if (wrappedType.isUnidirected(dir))
direction = dir;
assert direction != null;
StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.get().buildTransaction().readOnly().start();
try {
QueryContainer qc = new QueryContainer(tx);
qc.addQuery().type(wrappedType).direction(direction).relations();
return qc.getSliceQueries();
} finally {
tx.rollback();
}
}
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class StandardJanusGraph method newTransaction.
public StandardJanusGraphTx newTransaction(final TransactionConfiguration configuration) {
if (!isOpen)
ExceptionFactory.graphShutdown();
try {
StandardJanusGraphTx tx = new StandardJanusGraphTx(this, configuration);
tx.setBackendTransaction(openBackendTransaction(tx));
openTransactions.add(tx);
return tx;
} catch (BackendException e) {
throw new JanusGraphException("Could not start new transaction", e);
}
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class StandardJanusGraph method closeInternal.
private synchronized void closeInternal() {
if (!isOpen)
return;
Map<JanusGraphTransaction, RuntimeException> txCloseExceptions = new HashMap<>();
try {
// Unregister instance
String uniqueId = null;
try {
uniqueId = config.getUniqueGraphId();
ModifiableConfiguration globalConfig = GraphDatabaseConfiguration.getGlobalSystemConfig(backend);
globalConfig.remove(REGISTRATION_TIME, uniqueId);
} catch (Exception e) {
log.warn("Unable to remove graph instance uniqueid {}", uniqueId, e);
}
/* Assuming a couple of properties about openTransactions:
* 1. no concurrent modifications during graph shutdown
* 2. all contained txs are open
*/
for (StandardJanusGraphTx otx : openTransactions) {
try {
otx.close();
} catch (RuntimeException e) {
// Catch and store these exceptions, but proceed wit the loop
// Any remaining txs on the iterator should get a chance to close before we throw up
log.warn("Unable to close transaction {}", otx, e);
txCloseExceptions.put(otx, e);
}
}
super.close();
IOUtils.closeQuietly(idAssigner);
IOUtils.closeQuietly(backend);
IOUtils.closeQuietly(queryCache);
IOUtils.closeQuietly(serializer);
} finally {
isOpen = false;
}
// Throw an exception if at least one transaction failed to close
if (1 == txCloseExceptions.size()) {
// TP3's test suite requires that this be of type ISE
throw new IllegalStateException("Unable to close transaction", Iterables.getOnlyElement(txCloseExceptions.values()));
} else if (1 < txCloseExceptions.size()) {
throw new IllegalStateException(String.format("Unable to close %s transactions (see warnings in log output for details)", txCloseExceptions.size()));
}
}
Aggregations