{"record":{"id":"108595057a95dc7b","repo":"apache/druid","slug":"failed-to-retrieve-results-from-cache-for-query-id","errorCode":null,"errorMessage":"Failed to retrieve results from cache for query ID [%s]","messagePattern":"Failed to retrieve results from cache for query ID \\[(.+?)\\]","errorType":"exception","errorClass":"QueryException (RE)","httpStatus":null,"severity":"error","filePath":"server/src/main/java/org/apache/druid/query/ResultLevelCachingQueryRunner.java","lineNumber":242,"sourceCode":"      log.error(\"Cached result set is null\");\n    }\n    final Function<Object, T> pullFromCacheFunction = strategy.pullFromCache(true);\n    final TypeReference<T> cacheObjectClazz = strategy.getCacheObjectClazz();\n    //Skip the resultsetID and its length bytes\n    Sequence<T> cachedSequence = Sequences.simple(() -> {\n      try {\n        int resultOffset = Integer.BYTES + resultSetId.length();\n        return objectMapper.readValues(\n            objectMapper.getFactory().createParser(\n                cachedResult,\n                resultOffset,\n                cachedResult.length - resultOffset\n            ),\n            cacheObjectClazz\n        );\n      }\n      catch (IOException e) {\n        throw new RE(e, \"Failed to retrieve results from cache for query ID [%s]\", query.getId());\n      }\n    });\n\n    return Sequences.map(cachedSequence, pullFromCacheFunction);\n  }\n\n  private ResultLevelCachePopulator createResultLevelCachePopulator(\n      NamedKey cacheKey,\n      String resultSetId\n  )\n  {\n    if (resultSetId != null && populateResultCache) {\n      ResultLevelCachePopulator resultLevelCachePopulator = new ResultLevelCachePopulator(\n          cache,\n          objectMapper,\n          cacheKey,\n          cacheConfig,\n          true","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/query/ResultLevelCachingQueryRunner.java#L224-L260","documentation":"ResultLevelCachingQueryRunner.deserializeResults() reads cached result bytes from the level-2 result cache and deserializes them into the query's result type. If deserialization throws an IOException (corrupt cache entry, incompatible cached format after upgrade, wrong cacheObjectClazz), it throws a ResourceIOException/RE with 'Failed to retrieve results from cache for query ID [...]'.","triggerScenarios":"Reading a cached entry whose bytes cannot be parsed: cache data written by a different Druid version, corrupted cache storage, or a cache key collision between query types.","commonSituations":"Upgrading Druid while a shared cache (e.g., Redis/Memcached) still holds entries serialized by the old version; cache backend data corruption; populating and reading caches across clusters with different result formats.","solutions":["Clear/flush the result cache so stale entries are re-populated with the current format.","Verify all Druid nodes sharing the cache run the same version.","Check cache backend health for corruption; inspect the wrapped IOException cause.","Temporarily disable result-level caching (populatingCacheConfig/useResultLevelCache) to confirm the cache is the culprit."],"exampleFix":"// after diagnosing stale entries\n// flush shared cache, e.g. for memcached: echo 'flush_all' | nc <host> 11211\n// or disable result cache use in query context:\nquery.getContext().put(\"useResultLevelCache\", false);","handlingStrategy":"try-catch","validationCode":"// verify cache backend reachable and all nodes on same Druid version before enabling result-level cache","typeGuard":null,"tryCatchPattern":"try {\n  Sequence<ResultType> seq = runner.run(queryPlus, responseContext);\n  // consume\n} catch (ResourceIOException | QueryException e) {\n  if (e.getMessage().contains(\"Failed to retrieve results from cache\")) {\n    // flush cache entry and re-run with cache disabled\n    query.getContext().put(\"useResultLevelCache\", false);\n  }\n}","preventionTips":["Flush shared result caches on Druid upgrades","Pin all cluster nodes to the same Druid version","Monitor cache backend for corruption"],"tags":["cache","deserialization","query"],"backgroundTag":"cache-deserialization-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}