maytasm commented on code in PR #20815:
URL: https://github.com/apache/druid/pull/20815#discussion_r4456399974
##########
server/src/main/java/org/apache/druid/query/ResultLevelCachingQueryRunner.java:
##########
@@ -206,6 +209,27 @@ private byte[] fetchResultsFromResultLevelCache(
return null;
}
+ private byte[] computeResultLevelCacheKey()
+ {
+ final byte[] queryCacheKey = strategy.computeResultLevelCacheKey(query);
+ if (!cacheConfig.isIncludeDatasourceAndIntervalsInResultLevelCacheKey()) {
+ return queryCacheKey;
+ }
+ // The cached value still starts with the ETag, which is checked before
the entry is used. Adding the datasource
+ // and intervals to the key gives queries that differ only by interval or
datasource their own entries, instead of
+ // one shared entry that each of them overwrites.
+ final CacheKeyBuilder builder = new
CacheKeyBuilder(RESULT_LEVEL_CACHE_KEY_WITH_DATASOURCE_AND_INTERVALS)
+ .appendByteArray(queryCacheKey);
+ final byte[] dataSourceCacheKey = query.getDataSource().getCacheKey();
+ if (dataSourceCacheKey != null) {
+ builder.appendByteArray(dataSourceCacheKey);
Review Comment:
- A collision is very unlikely. One query's key would have to equal another
query's key followed by bytes shaped exactly like a datasource cache key.
Although is possible as you pointed out.
- Despite that, the ETag still catches it. Each cache value starts with an
ETag, a SHA-1 of the segment IDs, the clipped query intervals and the query
cache key (CachingClusteredClient.computeResultLevelCachingEtag, around lineĀ
821). Segment IDs include the datasource and interval, so a collision between
different datasources or intervals fails the ETag check. It then behaves like
today's default: a miss, and the entry gets overwritten.
- It's a simple fix so let me push a change
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]