Skip to content

Commit f45485f

Browse files
authored
fix(interactive): Log Query Cache Hit (#4439)
<!-- Thanks for your contribution! please review https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before opening an issue. --> ## What do these changes do? as titled. <!-- Please give a short brief about these changes. --> ## Related issue number <!-- Are there any issues opened that will be resolved by merging this change? --> Fixes
1 parent e964b99 commit f45485f

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ public PhysicalPlan planPhysical(LogicalPlan logicalPlan) {
188188
return new ProcedurePhysicalBuilder(graphConfig, irMeta, logicalPlan).build();
189189
}
190190
}
191+
192+
public @Nullable QueryLogger getQueryLogger() {
193+
return this.queryLogger;
194+
}
195+
196+
public String getQuery() {
197+
return query;
198+
}
191199
}
192200

193201
public static class Summary {

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/QueryCache.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
import com.google.common.cache.CacheBuilder;
2222
import com.google.common.cache.CacheLoader;
2323
import com.google.common.cache.LoadingCache;
24+
import com.google.common.collect.ImmutableMap;
25+
import com.google.common.collect.Maps;
2426

2527
import org.checkerframework.checker.nullness.qual.Nullable;
2628

2729
import java.util.List;
30+
import java.util.Map;
2831
import java.util.Objects;
2932
import java.util.concurrent.ExecutionException;
3033

@@ -36,7 +39,14 @@ public QueryCache(Configs configs) {
3639
this.cache =
3740
CacheBuilder.newBuilder()
3841
.maximumSize(cacheSize)
39-
.build(CacheLoader.from(key -> new Value(key.instance.plan(), null)));
42+
.build(
43+
CacheLoader.from(
44+
key ->
45+
new Value(
46+
key.instance.plan(),
47+
null,
48+
ImmutableMap.of(
49+
"instance", key.instance))));
4050
}
4151

4252
public class Key {
@@ -69,10 +79,16 @@ public Key createKey(GraphPlanner.PlannerInstance instance) {
6979
public static class Value {
7080
public final GraphPlanner.Summary summary;
7181
public @Nullable Result result;
82+
public final Map<String, Object> debugInfo;
7283

7384
public Value(GraphPlanner.Summary summary, Result result) {
85+
this(summary, result, Maps.newHashMap());
86+
}
87+
88+
public Value(GraphPlanner.Summary summary, Result result, Map<String, Object> debugInfo) {
7489
this.summary = Objects.requireNonNull(summary);
7590
this.result = result;
91+
this.debugInfo = debugInfo;
7692
}
7793
}
7894

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/executor/GraphQueryExecutor.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.alibaba.graphscope.common.utils.ClassUtils;
3131
import com.alibaba.graphscope.gaia.proto.IrResult;
3232
import com.alibaba.graphscope.gremlin.plugin.MetricsCollector;
33+
import com.alibaba.graphscope.gremlin.plugin.QueryLogger;
3334
import com.alibaba.graphscope.gremlin.plugin.QueryStatusCallback;
3435
import com.google.common.base.Preconditions;
3536

@@ -134,6 +135,7 @@ public StatementResult run(
134135
graphPlanner.instance(
135136
statement, irMeta, statusCallback.getQueryLogger()));
136137
QueryCache.Value cacheValue = queryCache.get(cacheKey);
138+
logCacheHit(cacheKey, cacheValue);
137139
Preconditions.checkArgument(
138140
cacheValue != null,
139141
"value should have been loaded automatically in query cache");
@@ -234,4 +236,21 @@ private boolean metaProcedureCall(LogicalPlan plan) {
234236
RexProcedureCall procedureCall = (RexProcedureCall) plan.getProcedureCall();
235237
return procedureCall.getMode() == StoredProcedureMeta.Mode.SCHEMA;
236238
}
239+
240+
private void logCacheHit(QueryCache.Key key, QueryCache.Value value) {
241+
GraphPlanner.PlannerInstance cacheInstance =
242+
(GraphPlanner.PlannerInstance) value.debugInfo.get("instance");
243+
if (cacheInstance != null && cacheInstance != key.instance) {
244+
QueryLogger queryLogger = key.instance.getQueryLogger();
245+
if (queryLogger != null) {
246+
queryLogger.info(
247+
"query hit the cache, cached query id [ {} ], cached query statement [ {}"
248+
+ " ]",
249+
cacheInstance.getQueryLogger() == null
250+
? 0L
251+
: cacheInstance.getQueryLogger().getQueryId(),
252+
cacheInstance.getQuery());
253+
}
254+
}
255+
}
237256
}

0 commit comments

Comments
 (0)