{"record":{"id":"646448c282daaf24","repo":"apache/druid","slug":"unable-to-write-to-cache","errorCode":null,"errorMessage":"Unable to write to cache","messagePattern":"Unable to write to cache","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/src/main/java/org/apache/druid/client/cache/ForegroundCachePopulator.java","lineNumber":121,"sourceCode":"        {\n          @Override\n          public void after(final boolean isDone, final Throwable thrown) throws Exception\n          {\n            jsonGenerator.close();\n\n            if (isDone) {\n              // Check tooBig, then check maxEntrySize one more time, after closing/flushing jsonGenerator.\n              if (tooBig.isTrue() || (maxEntrySize > 0 && bytes.size() > maxEntrySize)) {\n                cachePopulatorStats.incrementOversized();\n                return;\n              }\n\n              try {\n                cache.put(cacheKey, bytes.toByteArray());\n                cachePopulatorStats.incrementOk();\n              }\n              catch (Exception e) {\n                log.warn(e, \"Unable to write to cache\");\n                cachePopulatorStats.incrementError();\n              }\n            }\n          }\n        }\n    );\n  }\n}\n","sourceCodeStart":103,"sourceCodeEnd":130,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/client/cache/ForegroundCachePopulator.java#L103-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"Cache (memcached) node down or network flake during query; oversized result rows; cache timeouts under load; misconfigured cache hosts in broker runtime properties.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (bytes.length <= maxCacheableSize) { cache.put(key, bytes); }","typeGuard":null,"tryCatchPattern":"try { cache.put(key, bytes); } catch (Exception e) { log.warn(e, \"Unable to write to cache\"); stats.incrementError(); }","preventionTips":["Cap cacheable result sizes","Verify memcached connectivity under load","Treat cache errors as non-fatal by design"],"tags":["druid","cache","query-path"],"backgroundTag":"database-write-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"}