Skip to content

Commit

Permalink
PLT-191: expose caching through JG API
Browse files Browse the repository at this point in the history
  • Loading branch information
n5nk committed Dec 11, 2023
1 parent 8c073e4 commit 8b16f49
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<EntryList> edgeMultiQuery(LongArrayList vertexIdsAsLongs, SliceQuery query, BackendTransaction tx) {
Preconditions.checkArgument(vertexIdsAsLongs != null && !vertexIdsAsLongs.isEmpty());
if (!this.isCacheEnabled()) {
tx.disableCache();
}
final List<StaticBuffer> vertexIds = new ArrayList<>(vertexIdsAsLongs.size());
for (int i = 0; i < vertexIdsAsLongs.size(); i++) {
Preconditions.checkArgument(vertexIdsAsLongs.get(i) > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public abstract class JanusGraphBlueprintsGraph implements JanusGraph {

private ThreadLocal<JanusGraphBlueprintsTransaction> txs = ThreadLocal.withInitial(() -> null);

private final ThreadLocal<Boolean> cacheEnabled = ThreadLocal.withInitial(()-> true);

public abstract JanusGraphTransaction newThreadBoundTransaction();

private JanusGraphBlueprintsTransaction getAutoStartTx() {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,9 @@ public JanusGraphMultiVertexQuery multiQuery(Collection<JanusGraphVertex> vertic
}

public void executeMultiQuery(final Collection<InternalVertex> 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());
Expand Down Expand Up @@ -1409,6 +1412,9 @@ else if (query.getResultType() == ElementCategory.VERTEX) {
@Override
public Iterator<JanusGraphElement> execute(final GraphCentricQuery query, final JointIndexQuery indexQuery, final Object exeInfo, final QueryProfiler profiler) {
Iterator<JanusGraphElement> iterator;
if(!getGraph().isCacheEnabled()) {
txHandle.disableCache();
}
if (!indexQuery.isEmpty()) {
final List<QueryUtil.IndexCall<Object>> retrievals = new ArrayList<>();
// Leave first index for streaming, and prepare the rest for intersecting and lookup
Expand Down

0 comments on commit 8b16f49

Please sign in to comment.