{"record":{"id":"26a594e95defa0ab","repo":"apache/druid","slug":"cannot-get-cache-s","errorCode":null,"errorMessage":"Cannot get cache: %s","messagePattern":"Cannot get cache: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/cache/CacheScheduler.java","lineNumber":104,"sourceCode":"     * Returns the last cache state, either {@link NoCache} or {@link VersionedCache}.\n     */\n    public CacheState getCacheState()\n    {\n      return impl.cacheStateHolder.get();\n    }\n\n    /**\n     * @return the entry's cache if it is already initialized and not yet closed\n     * @throws IllegalStateException if the entry's cache is not yet initialized, or {@link #close()} has\n     * already been called\n     */\n    public Map<String, String> getCache()\n    {\n      CacheState cacheState = getCacheState();\n      if (cacheState instanceof VersionedCache) {\n        return ((VersionedCache) cacheState).getCache();\n      } else {\n        throw new ISE(\"Cannot get cache: %s\", cacheState);\n      }\n    }\n\n    @VisibleForTesting\n    Future<?> getUpdaterFuture()\n    {\n      return impl.updaterFuture;\n    }\n\n    @VisibleForTesting\n    public void awaitTotalUpdates(int totalUpdates) throws InterruptedException\n    {\n      impl.updateCounter.awaitCount(totalUpdates);\n    }\n\n    @VisibleForTesting\n    public void awaitTotalUpdatesWithTimeout(int totalUpdates, long timeoutMills)\n        throws InterruptedException, TimeoutException","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/cache/CacheScheduler.java#L86-L122","documentation":"CacheScheduler.Entry.getCache() returns the materialized lookup map only while the entry's CacheState is a VersionedCache (a successfully loaded snapshot). If the entry is in any other state — e.g. it was deleted, or the cache creation failed — there is no cache to return and this ISE is thrown with the current state.","triggerScenarios":"Calling entry.getCache() after the entry has been closed/deleted via scheduler.delete(entry), or before/since an update replaced the versioned snapshot with a non-VersionedCache state.","commonSituations":"Concurrent lookup deletion while another thread reads the cache; using a stale Entry reference after shutdown; tests driving entry lifecycle without waiting for load completion.","solutions":["Check entry lifecycle before reading: only call getCache() on a live, scheduled entry.","Use the Entry's cacheFuture/getUpdaterFuture or await the update future before reading the cache.","Fix code to re-fetch the entry from the scheduler after delete/replace instead of caching the reference."],"exampleFix":"// before\nEntry entry = scheduler.schedule(ns);\nscheduler.delete(entry);\nMap<String,String> m = entry.getCache(); // ISE\n// after\nEntry entry = scheduler.schedule(ns);\nMap<String,String> m = entry.getCache(); // read while live\nscheduler.delete(entry);","handlingStrategy":"try-catch","validationCode":"if (entry.getCacheState() instanceof VersionedCache) { entry.getCache(); }","typeGuard":"boolean readable(Entry e) { return e.getCacheState() instanceof VersionedCache; }","tryCatchPattern":"try { return entry.getCache(); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Cannot get cache:\")) { return Collections.emptyMap(); } throw e; }","preventionTips":["Await the entry's update future before reading the cache","Never reuse Entry references after scheduler.delete(entry)","Re-fetch entries from the scheduler instead of caching them"],"tags":["lifecycle","lookup-cache","concurrency"],"backgroundTag":"invalid-state-transition","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}