use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class RelationTypeIndexWrapper method getSortKey.
@Override
public RelationType[] getSortKey() {
StandardJanusGraphTx tx = type.tx();
long[] ids = type.getSortKey();
RelationType[] keys = new RelationType[ids.length];
for (int i = 0; i < keys.length; i++) {
keys[i] = tx.getExistingRelationType(ids[i]);
}
return keys;
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class StandardTransactionLogProcessor method restoreExternalIndexes.
private void restoreExternalIndexes(Predicate<String> isFailedIndex, TransactionLogHeader.Entry entry) {
// 1) Collect all elements (vertices and relations) and the indexes for which they need to be restored
SetMultimap<String, IndexRestore> indexRestores = HashMultimap.create();
BackendOperation.execute(() -> {
final StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.newTransaction();
try {
entry.getContentAsModifications(serializer).stream().map(m -> ModificationDeserializer.parseRelation(m, tx)).forEach(rel -> {
// Collect affected vertex indexes
for (final MixedIndexType index : getMixedIndexes(rel.getType())) {
if (index.getElement() == ElementCategory.VERTEX && isFailedIndex.apply(index.getBackingIndexName())) {
assert rel.isProperty();
indexRestores.put(index.getBackingIndexName(), new IndexRestore(rel.getVertex(0).longId(), ElementCategory.VERTEX, getIndexId(index)));
}
}
// See if relation itself is affected
for (final RelationType relType : rel.getPropertyKeysDirect()) {
for (final MixedIndexType index : getMixedIndexes(relType)) {
if (index.getElement().isInstance(rel) && isFailedIndex.apply(index.getBackingIndexName())) {
assert rel.id() instanceof RelationIdentifier;
indexRestores.put(index.getBackingIndexName(), new IndexRestore(rel.id(), ElementCategory.getByClazz(rel.getClass()), getIndexId(index)));
}
}
}
});
} finally {
if (tx.isOpen())
tx.rollback();
}
return true;
}, readTime);
// 2) Restore elements per backing index
for (final String indexName : indexRestores.keySet()) {
final StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.newTransaction();
try {
BackendTransaction btx = tx.getTxHandle();
final IndexTransaction indexTx = btx.getIndexTransaction(indexName);
BackendOperation.execute(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
Map<String, Map<String, List<IndexEntry>>> restoredDocs = Maps.newHashMap();
indexRestores.get(indexName).forEach(restore -> {
JanusGraphSchemaVertex indexV = (JanusGraphSchemaVertex) tx.getVertex(restore.indexId);
MixedIndexType index = (MixedIndexType) indexV.asIndexType();
JanusGraphElement element = restore.retrieve(tx);
if (element != null) {
graph.getIndexSerializer().reindexElement(element, index, restoredDocs);
} else {
// Element is deleted
graph.getIndexSerializer().removeElement(restore.elementId, index, restoredDocs);
}
});
indexTx.restore(restoredDocs);
indexTx.commit();
return true;
}
@Override
public String toString() {
return "IndexMutation";
}
}, persistenceTime);
} finally {
if (tx.isOpen())
tx.rollback();
}
}
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class VertexJobConverter method startTransaction.
public static StandardJanusGraphTx startTransaction(StandardJanusGraph graph) {
StandardTransactionBuilder txb = graph.buildTransaction().readOnly();
txb.setPreloadedData(true);
txb.checkInternalVertexExistence(false);
txb.dirtyVertexSize(0);
txb.vertexCacheSize(0);
return (StandardJanusGraphTx) txb.start();
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class CassandraGraphTest method testGraphConfigUsedByTx.
@Test
public void testGraphConfigUsedByTx() {
close();
WriteConfiguration wc = getConfiguration();
wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.newTransaction();
assertEquals("TWO", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions().get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
assertEquals("THREE", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions().get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
tx.rollback();
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class JanusGraphSchemaVertex method getDefinition.
@Override
public TypeDefinitionMap getDefinition() {
TypeDefinitionMap def = definition;
if (def == null) {
def = new TypeDefinitionMap();
Iterable<JanusGraphVertexProperty> ps;
if (isLoaded()) {
StandardJanusGraphTx tx = tx();
ps = (Iterable) RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(longId(), BaseKey.SchemaDefinitionProperty, Direction.OUT), tx);
} else {
ps = query().type(BaseKey.SchemaDefinitionProperty).properties();
}
for (JanusGraphVertexProperty property : ps) {
TypeDefinitionDescription desc = property.valueOrNull(BaseKey.SchemaDefinitionDesc);
Preconditions.checkArgument(desc != null && desc.getCategory().isProperty());
def.setValue(desc.getCategory(), property.value());
}
assert def.size() > 0;
definition = def;
}
assert def != null;
return def;
}
Aggregations