agali-09 commented on code in PR #20815:
URL: https://github.com/apache/druid/pull/20815#discussion_r4455641551
##########
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:
Do we need to length-prefix or add a seperator between queryCacheKey and
dataSourceCacheKey byte arrays to avoid collisions?
Though appendByteArray() adds 0x01 as a type marker, that byte can also
appear in the data. For example, [AA] + [BB, 01, CC] and [AA, 01, BB] + [CC]
both encode as 01 AA 01 BB 01 CC.
```
public CacheKeyBuilder appendByteArray(byte[] input)
{
appendItem(BYTE_ARRAY_KEY, input);
return this;
}
...
private void appendItem(byte typeKey, byte[] input)
{
final Item item = new Item(typeKey, input);
items.add(item);
size += item.byteSize();
}
```
--
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]