{"record":{"id":"cb419aa100c06729","repo":"influxdata/influxdb","slug":"cache-not-found","errorCode":null,"errorMessage":"cache not found","messagePattern":"cache not found","errorType":"exception","errorClass":"ProviderError","httpStatus":null,"severity":"error","filePath":"influxdb3_cache/src/distinct_cache/provider.rs","lineNumber":19,"sourceCode":"use std::{collections::HashMap, sync::Arc, time::Duration};\n\nuse super::{\n    CacheError,\n    cache::{CreateDistinctCacheArgs, DistinctCache},\n};\nuse arrow::datatypes::SchemaRef;\nuse influxdb3_catalog::catalog::{Catalog, CatalogEvent, CatalogUpdateReceiver, IfNotDeleted};\nuse influxdb3_id::{DbId, DistinctCacheId, TableId};\nuse influxdb3_wal::{WalContents, WalOp};\nuse iox_time::TimeProvider;\nuse observability_deps::tracing::error;\nuse parking_lot::RwLock;\n\n#[derive(Debug, thiserror::Error)]\npub enum ProviderError {\n    #[error(\"cache error: {0}\")]\n    Cache(#[from] CacheError),\n    #[error(\"cache not found\")]\n    CacheNotFound,\n    #[error(\"unexpected error: {0:#}\")]\n    Unexpected(#[from] anyhow::Error),\n}\n\n/// Triple nested map for storing a multiple distinct value caches per table.\n///\n/// That is, the map nesting is `database -> table -> cache id`\ntype CacheMap = RwLock<HashMap<DbId, HashMap<TableId, HashMap<DistinctCacheId, DistinctCache>>>>;\n\n/// Provides the distinct value caches for the running instance of InfluxDB\n#[derive(Debug)]\npub struct DistinctCacheProvider {\n    pub(crate) time_provider: Arc<dyn TimeProvider>,\n    pub(crate) catalog: Arc<Catalog>,\n    pub(crate) cache_map: CacheMap,\n}\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_cache/src/distinct_cache/provider.rs#L1-L37","documentation":"ProviderError::CacheNotFound is returned by the distinct value cache provider when a lookup is requested for a cache id that does not exist under the given database/table in the triple nested map (database -> table -> cache id). The provider stores multiple distinct value caches per table, and this variant signals the requested entry is absent rather than that a cache operation failed. It is thrown by the library when callers reference a cache by name/id that was never created or has been removed.","triggerScenarios":"Calling provider methods such as get_cache/cache lookup with a cache_id that was never created for that database and table; referencing a distinct cache after it was deleted; passing the wrong cache id or a cache that belongs to a different database/table pair.","commonSituations":"Typo in the cache name/id in application config; querying a cache before its creation code ran; environment drift where the cache creation migration was not applied; attempting to write or read a distinct cache after a drop operation; using a cache id from one table against another table.","solutions":["Check the cache id/name for typos and confirm it matches the one used at creation time","Verify the cache exists for the exact database and table pair you are querying (the map is nested database -> table -> cache id)","Create the distinct cache (via the provider's create/add API) before reading or writing it","Check that the cache was not deleted by a concurrent operation or migration and recreate it if needed"],"exampleFix":"// before\nlet cache = provider.get_cache(db, table, cache_id)?;\n// after\nmatch provider.get_cache(db, table, cache_id) {\n    Ok(cache) => { /* use cache */ }\n    Err(ProviderError::CacheNotFound) => {\n        let cache = provider.create_cache(db, table, cache_id, config)?;\n    }\n    Err(e) => return Err(e.into()),\n}","handlingStrategy":"try-catch","validationCode":"// Rust: check existence before use\nif !provider.has_cache(db, table, cache_id) {\n    return Err(format!(\"distinct cache {cache_id} not found for {db}.{table}\"));\n}","typeGuard":"fn is_cache_not_found(err: &ProviderError) -> bool {\n    matches!(err, ProviderError::CacheNotFound)\n}","tryCatchPattern":"match provider.get_cache(db, table, cache_id) {\n    Ok(c) => c,\n    Err(ProviderError::CacheNotFound) => initialize_default_cache(),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Centralize cache creation in a single bootstrap step that runs before any read/write","Keep cache ids in constants or enums rather than ad-hoc strings","Include database and table in logs when a cache is missing to spot wrong-pair lookups"],"tags":["cache","not-found","distinct-cache","rust"],"backgroundTag":"entity-not-found","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}