diff --git a/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/StandardJanusGraph.java b/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/StandardJanusGraph.java index 270c898987d..f054bec9b1b 100644 --- a/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/StandardJanusGraph.java +++ b/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/StandardJanusGraph.java @@ -83,11 +83,11 @@ import org.janusgraph.graphdb.tinkerpop.JanusGraphFeatures; import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexFilterOptimizerStrategy; import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexHasIdOptimizerStrategy; -import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMixedIndexCountStrategy; import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexHasUniquePropertyOptimizerStrategy; import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexIsOptimizerStrategy; import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphIoRegistrationStrategy; import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphLocalQueryOptimizerStrategy; +import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMixedIndexCountStrategy; import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMultiQueryStrategy; import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphStepStrategy; import org.janusgraph.graphdb.transaction.StandardJanusGraphTx; @@ -485,11 +485,17 @@ public void remove() { public EntryList edgeQuery(long vid, SliceQuery query, BackendTransaction tx) { Preconditions.checkArgument(vid > 0); + if (!this.isCacheEnabled()) { + tx.disableCache(); + } return tx.edgeStoreQuery(new KeySliceQuery(idManager.getKey(vid), query)); } public List edgeMultiQuery(LongArrayList vertexIdsAsLongs, SliceQuery query, BackendTransaction tx) { Preconditions.checkArgument(vertexIdsAsLongs != null && !vertexIdsAsLongs.isEmpty()); + if (!this.isCacheEnabled()) { + tx.disableCache(); + } final List vertexIds = new ArrayList<>(vertexIdsAsLongs.size()); for (int i = 0; i < vertexIdsAsLongs.size(); i++) { Preconditions.checkArgument(vertexIdsAsLongs.get(i) > 0); diff --git a/janusgraph-core/src/main/java/org/janusgraph/graphdb/tinkerpop/JanusGraphBlueprintsGraph.java b/janusgraph-core/src/main/java/org/janusgraph/graphdb/tinkerpop/JanusGraphBlueprintsGraph.java index 3da6fc640fd..0078fe522a5 100644 --- a/janusgraph-core/src/main/java/org/janusgraph/graphdb/tinkerpop/JanusGraphBlueprintsGraph.java +++ b/janusgraph-core/src/main/java/org/janusgraph/graphdb/tinkerpop/JanusGraphBlueprintsGraph.java @@ -70,6 +70,8 @@ public abstract class JanusGraphBlueprintsGraph implements JanusGraph { private ThreadLocal txs = ThreadLocal.withInitial(() -> null); + private final ThreadLocal cacheEnabled = ThreadLocal.withInitial(()-> true); + public abstract JanusGraphTransaction newThreadBoundTransaction(); private JanusGraphBlueprintsTransaction getAutoStartTx() { @@ -94,6 +96,13 @@ public JanusGraphTransaction getCurrentThreadTx() { return getAutoStartTx(); } + public void setEnableCache(boolean enableCache) { + this.cacheEnabled.set(enableCache); + } + + public boolean isCacheEnabled() { + return this.cacheEnabled.get(); + } @Override public synchronized void close() { diff --git a/janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/StandardJanusGraphTx.java b/janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/StandardJanusGraphTx.java index e2a53bf0274..f07a7e5ce3b 100644 --- a/janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/StandardJanusGraphTx.java +++ b/janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/StandardJanusGraphTx.java @@ -1202,6 +1202,9 @@ public JanusGraphMultiVertexQuery multiQuery(Collection vertic } public void executeMultiQuery(final Collection vertices, final SliceQuery sq, final QueryProfiler profiler) { + if(!getGraph().isCacheEnabled()) { + txHandle.disableCache(); + } LongArrayList vertexIds = new LongArrayList(vertices.size()); for (InternalVertex v : vertices) { if (!v.isNew() && v.hasId() && (v instanceof CacheVertex) && !v.hasLoadedRelations(sq)) vertexIds.add(v.longId()); @@ -1409,6 +1412,9 @@ else if (query.getResultType() == ElementCategory.VERTEX) { @Override public Iterator execute(final GraphCentricQuery query, final JointIndexQuery indexQuery, final Object exeInfo, final QueryProfiler profiler) { Iterator iterator; + if(!getGraph().isCacheEnabled()) { + txHandle.disableCache(); + } if (!indexQuery.isEmpty()) { final List> retrievals = new ArrayList<>(); // Leave first index for streaming, and prepare the rest for intersecting and lookup