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
- Inspect the logged exception for the underlying cache.put failure and fix the cache backend (connectivity, memory).
- Verify cache host configuration and timeouts in the broker's cache config.
- Enable caching only for results below size thresholds (query cache config: cache result size limits).
- 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
- Cap cacheable result sizes
- Verify memcached connectivity under load
- Treat cache errors as non-fatal by design
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
- Could not populate cache
- Expected 0 resource count, got
- Multiple monitors on the same cache causing race conditions…
- Unable to get SHA1 digest instance
- A-Not-B requires at least 1 sketch
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)