use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class JanusGraphLocalQueryOptimizerStrategy method apply.
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
if (!traversal.getGraph().isPresent())
return;
Graph graph = traversal.getGraph().get();
// If this is a compute graph then we can't apply local traversal optimisation at this stage.
StandardJanusGraph janusGraph = graph instanceof StandardJanusGraphTx ? ((StandardJanusGraphTx) graph).getGraph() : (StandardJanusGraph) graph;
final boolean useMultiQuery = !TraversalHelper.onGraphComputer(traversal) && janusGraph.getConfiguration().useMultiQuery();
/*
====== VERTEX STEP ======
*/
TraversalHelper.getStepsOfClass(VertexStep.class, traversal).forEach(originalStep -> {
JanusGraphVertexStep vertexStep = new JanusGraphVertexStep(originalStep);
TraversalHelper.replaceStep(originalStep, vertexStep, traversal);
if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
HasStepFolder.foldInHasContainer(vertexStep, traversal);
// We cannot fold in orders or ranges since they are not local
}
assert JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep) || JanusGraphTraversalUtil.isVertexReturnStep(vertexStep);
Step nextStep = JanusGraphTraversalUtil.getNextNonIdentityStep(vertexStep);
if (nextStep instanceof RangeGlobalStep) {
int limit = QueryUtil.convertLimit(((RangeGlobalStep) nextStep).getHighRange());
vertexStep.setLimit(QueryUtil.mergeLimits(limit, vertexStep.getLimit()));
}
if (useMultiQuery) {
vertexStep.setUseMultiQuery(true);
}
});
/*
====== PROPERTIES STEP ======
*/
TraversalHelper.getStepsOfClass(PropertiesStep.class, traversal).forEach(originalStep -> {
JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep(originalStep);
TraversalHelper.replaceStep(originalStep, propertiesStep, traversal);
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, traversal);
// We cannot fold in orders or ranges since they are not local
}
if (useMultiQuery) {
propertiesStep.setUseMultiQuery(true);
}
});
/*
====== EITHER INSIDE LOCAL ======
*/
TraversalHelper.getStepsOfClass(LocalStep.class, traversal).forEach(localStep -> {
Traversal.Admin localTraversal = ((LocalStep<?, ?>) localStep).getLocalChildren().get(0);
Step localStart = localTraversal.getStartStep();
if (localStart instanceof VertexStep) {
JanusGraphVertexStep vertexStep = new JanusGraphVertexStep((VertexStep) localStart);
TraversalHelper.replaceStep(localStart, vertexStep, localTraversal);
if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
HasStepFolder.foldInHasContainer(vertexStep, localTraversal);
HasStepFolder.foldInOrder(vertexStep, localTraversal, traversal, false);
}
HasStepFolder.foldInRange(vertexStep, localTraversal);
unfoldLocalTraversal(traversal, localStep, localTraversal, vertexStep, useMultiQuery);
}
if (localStart instanceof PropertiesStep) {
JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep((PropertiesStep) localStart);
TraversalHelper.replaceStep(localStart, propertiesStep, localTraversal);
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, localTraversal);
HasStepFolder.foldInOrder(propertiesStep, localTraversal, traversal, false);
}
HasStepFolder.foldInRange(propertiesStep, localTraversal);
unfoldLocalTraversal(traversal, localStep, localTraversal, propertiesStep, useMultiQuery);
}
});
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class ManagementLoggerGraphCacheEvictionTest method graphShouldBeRemovedFromCache.
@Test
public void graphShouldBeRemovedFromCache() throws InterruptedException {
final JanusGraphManager jgm = new JanusGraphManager(new Settings());
assertNotNull(jgm);
assertNotNull(JanusGraphManager.getInstance());
assertNull(jgm.getGraph("graph1"));
final Map<String, Object> map = new HashMap<>();
map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
final MapConfiguration config = new MapConfiguration(map);
final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
jgm.putGraph("graph1", graph);
assertEquals("graph1", ((StandardJanusGraph) JanusGraphManager.getInstance().getGraph("graph1")).getGraphName());
final ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
mgmt.evictGraphFromCache();
mgmt.commit();
// wait for log to be asynchronously pulled
Thread.sleep(10000);
assertNull(jgm.getGraph("graph1"));
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class EdgeSerializerTest method testValueOrdering.
@Test
public void testValueOrdering() {
StandardJanusGraph graph = (StandardJanusGraph) StorageSetup.getInMemoryGraph();
JanusGraphManagement management = graph.openManagement();
management.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
for (int i = 1; i <= 5; i++) management.makePropertyKey("key" + i).dataType(Integer.class).make();
management.commit();
JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex();
JanusGraphEdge e1 = v1.addEdge("father", v2);
for (int i = 1; i <= 5; i++) e1.property("key" + i, i);
graph.tx().commit();
e1.remove();
graph.tx().commit();
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class StandardJanusGraphTxTest method createTxWithMockedInternals.
private StandardJanusGraphTx createTxWithMockedInternals() {
StandardJanusGraph mockGraph = createMock(StandardJanusGraph.class);
TransactionConfiguration txConfig = createMock(TransactionConfiguration.class);
GraphDatabaseConfiguration gdbConfig = createMock(GraphDatabaseConfiguration.class);
TimestampProvider tsProvider = createMock(TimestampProvider.class);
Serializer mockSerializer = createMock(Serializer.class);
EdgeSerializer mockEdgeSerializer = createMock(EdgeSerializer.class);
IndexSerializer mockIndexSerializer = createMock(IndexSerializer.class);
RelationType relationType = createMock(RelationType.class);
IDManager idManager = createMock(IDManager.class);
PropertyKey propertyKey = createMock(PropertyKey.class);
DefaultSchemaMaker defaultSchemaMaker = createMock(DefaultSchemaMaker.class);
expect(mockGraph.getConfiguration()).andReturn(gdbConfig);
expect(mockGraph.isOpen()).andReturn(true).anyTimes();
expect(mockGraph.getDataSerializer()).andReturn(mockSerializer);
expect(mockGraph.getEdgeSerializer()).andReturn(mockEdgeSerializer);
expect(mockGraph.getIndexSerializer()).andReturn(mockIndexSerializer);
expect(mockGraph.getIDManager()).andReturn(idManager);
expect(gdbConfig.getTimestampProvider()).andReturn(tsProvider);
expect(txConfig.isSingleThreaded()).andReturn(true);
expect(txConfig.hasPreloadedData()).andReturn(false);
expect(txConfig.hasVerifyExternalVertexExistence()).andReturn(false);
expect(txConfig.hasVerifyInternalVertexExistence()).andReturn(false);
expect(txConfig.getVertexCacheSize()).andReturn(6);
expect(txConfig.isReadOnly()).andReturn(true);
expect(txConfig.getDirtyVertexSize()).andReturn(2);
expect(txConfig.getIndexCacheWeight()).andReturn(2L);
expect(txConfig.getGroupName()).andReturn(null);
expect(txConfig.getAutoSchemaMaker()).andReturn(defaultSchemaMaker);
expect(defaultSchemaMaker.makePropertyKey(isA(PropertyKeyMaker.class), notNull())).andReturn(propertyKey);
expect(relationType.isPropertyKey()).andReturn(false);
expect(propertyKey.isPropertyKey()).andReturn(true);
replayAll();
StandardJanusGraphTx partialMock = createMockBuilder(StandardJanusGraphTx.class).withConstructor(mockGraph, txConfig).addMockedMethod("getRelationType").createMock();
expect(partialMock.getRelationType("Foo")).andReturn(null);
expect(partialMock.getRelationType("Qux")).andReturn(propertyKey);
expect(partialMock.getRelationType("Baz")).andReturn(relationType);
replay(partialMock);
return partialMock;
}
Aggregations