apache/druid · error · QueryException (RE)

Failed to retrieve results from cache for query ID

Error message

Failed to retrieve results from cache for query ID [%s]

What it means

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 [...]'.

Solutions

  1. Clear/flush the result cache so stale entries are re-populated with the current format.
  2. Verify all Druid nodes sharing the cache run the same version.
  3. Check cache backend health for corruption; inspect the wrapped IOException cause.
  4. Temporarily disable result-level caching (populatingCacheConfig/useResultLevelCache) to confirm the cache is the culprit.

Example fix

// after diagnosing stale entries
// flush shared cache, e.g. for memcached: echo 'flush_all' | nc <host> 11211
// or disable result cache use in query context:
query.getContext().put("useResultLevelCache", false);
Defensive patterns

Strategy: try-catch

Validate before calling

// verify cache backend reachable and all nodes on same Druid version before enabling result-level cache

Try / catch

try {
  Sequence<ResultType> seq = runner.run(queryPlus, responseContext);
  // consume
} catch (ResourceIOException | QueryException e) {
  if (e.getMessage().contains("Failed to retrieve results from cache")) {
    // flush cache entry and re-run with cache disabled
    query.getContext().put("useResultLevelCache", false);
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/108595057a95dc7b. Report an issue: GitHub.

Appendix: source

Thrown at server/src/main/java/org/apache/druid/query/ResultLevelCachingQueryRunner.java:242

      log.error("Cached result set is null");
    }
    final Function<Object, T> pullFromCacheFunction = strategy.pullFromCache(true);
    final TypeReference<T> cacheObjectClazz = strategy.getCacheObjectClazz();
    //Skip the resultsetID and its length bytes
    Sequence<T> cachedSequence = Sequences.simple(() -> {
      try {
        int resultOffset = Integer.BYTES + resultSetId.length();
        return objectMapper.readValues(
            objectMapper.getFactory().createParser(
                cachedResult,
                resultOffset,
                cachedResult.length - resultOffset
            ),
            cacheObjectClazz
        );
      }
      catch (IOException e) {
        throw new RE(e, "Failed to retrieve results from cache for query ID [%s]", query.getId());
      }
    });

    return Sequences.map(cachedSequence, pullFromCacheFunction);
  }

  private ResultLevelCachePopulator createResultLevelCachePopulator(
      NamedKey cacheKey,
      String resultSetId
  )
  {
    if (resultSetId != null && populateResultCache) {
      ResultLevelCachePopulator resultLevelCachePopulator = new ResultLevelCachePopulator(
          cache,
          objectMapper,
          cacheKey,
          cacheConfig,
          true

View on GitHub (pinned to 9b90983fd2)