apache/druid · warning

Unable to write to cache

Error message

Unable to write to cache

What it means

ForegroundCachePopulator writes query results into the cache inline while the query result is streamed to the caller. A failure during cache.put is caught, logged as 'Unable to write to cache', and counted as an error in cachePopulatorStats. Query results are not affected — caching is strictly best-effort.

Solutions

  1. Inspect the logged exception for the underlying cache.put failure and fix the cache backend (connectivity, memory).
  2. Verify cache host configuration and timeouts in the broker's cache config.
  3. Enable caching only for results below size thresholds (query cache config: cache result size limits).
  4. Monitor cachePopulator error metrics; occasional errors under load are benign.
Defensive patterns

Strategy: try-catch

Validate before calling

if (bytes.length <= maxCacheableSize) { cache.put(key, bytes); }

Try / catch

try { cache.put(key, bytes); } catch (Exception e) { log.warn(e, "Unable to write to cache"); stats.incrementError(); }

Prevention

When it happens

Trigger: Within the Sequence the populator wraps, cache.put(cacheKey, bytes) throws — cache backend unavailable (e.g. memcached connection reset), entry too large, or cache closed mid-query.

Common situations: Cache (memcached) node down or network flake during query; oversized result rows; cache timeouts under load; misconfigured cache hosts in broker runtime properties.

Related errors


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

Appendix: source

Thrown at server/src/main/java/org/apache/druid/client/cache/ForegroundCachePopulator.java:121

        {
          @Override
          public void after(final boolean isDone, final Throwable thrown) throws Exception
          {
            jsonGenerator.close();

            if (isDone) {
              // Check tooBig, then check maxEntrySize one more time, after closing/flushing jsonGenerator.
              if (tooBig.isTrue() || (maxEntrySize > 0 && bytes.size() > maxEntrySize)) {
                cachePopulatorStats.incrementOversized();
                return;
              }

              try {
                cache.put(cacheKey, bytes.toByteArray());
                cachePopulatorStats.incrementOk();
              }
              catch (Exception e) {
                log.warn(e, "Unable to write to cache");
                cachePopulatorStats.incrementError();
              }
            }
          }
        }
    );
  }
}

View on GitHub (pinned to 9b90983fd2)