{"record":{"id":"2af09c68b04b6ef7","repo":"influxdata/influxdb","slug":"cannot-overwrite-an-an-existing-cache-message","errorCode":null,"errorMessage":"cannot overwrite an an existing cache: {message}","messagePattern":"cannot overwrite an an existing cache: (.+?)","errorType":"validation","errorClass":"CacheError","httpStatus":null,"severity":"error","filePath":"influxdb3_cache/src/distinct_cache/cache.rs","lineNumber":31,"sourceCode":"use indexmap::IndexMap;\nuse influxdb3_catalog::catalog::legacy;\nuse influxdb3_catalog::catalog::{MaxAge, MaxCardinality, TableDefinition};\nuse influxdb3_id::{ColumnId, ColumnIdentifier};\nuse influxdb3_wal::{FieldData, Row};\nuse iox_time::TimeProvider;\nuse observability_deps::tracing::debug;\nuse schema::{InfluxColumnType, InfluxFieldType};\n\n#[derive(Debug, thiserror::Error)]\npub enum CacheError {\n    #[error(\"must pass a non-empty set of column ids\")]\n    EmptyColumnSet,\n    #[error(\n        \"cannot use a column of type {attempted} in a distinct value cache, only \\\n                    tags and string fields can be used\"\n    )]\n    NonTagOrStringColumn { attempted: InfluxColumnType },\n    #[error(\"cannot overwrite an an existing cache: {message}\")]\n    ConfigurationMismatch { message: String },\n    #[error(\"unexpected error: {0}\")]\n    Unexpected(#[from] anyhow::Error),\n}\n\n/// A cache for storing distinct values for a set of columns in a table\n#[derive(Debug)]\npub(crate) struct DistinctCache {\n    time_provider: Arc<dyn TimeProvider>,\n    /// The maximum number of unique value combinations in the cache\n    max_cardinality: usize,\n    /// The maximum age for entries in the cache\n    max_age: Duration,\n    /// The fixed Arrow schema used to produce record batches from the cache\n    schema: SchemaRef,\n    /// Holds current state of the cache\n    pub(crate) state: DistinctCacheState,\n    /// The identifiers of the columns used in the cache","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_cache/src/distinct_cache/cache.rs#L13-L49","documentation":"CacheError::ConfigurationMismatch is returned when trying to create a distinct cache that would overwrite an existing cache with a different configuration. The cache name already exists and the requested definition (columns, table) does not match, so the provider refuses the silent overwrite. Note the message contains a typo ('an an').","triggerScenarios":"Calling create_cache/new_cache with a cache name that already exists but specifying different columns or table than the existing cache definition.","commonSituations":"Re-running a CREATE DISTINCT CACHE statement with edited column lists; infrastructure-as-code applying a modified cache definition over an existing one.","solutions":["Drop the existing cache first (DROP DISTINCT CACHE / provider.delete_cache) then recreate it with the new configuration","Reuse the existing cache if the current configuration is acceptable","Use a new cache name for the different configuration"],"exampleFix":"-- before\nCREATE DISTINCT CACHE \"events_cache\" ON events (host, region); -- exists with different columns\n-- after\nDROP DISTINCT CACHE \"events_cache\";\nCREATE DISTINCT CACHE \"events_cache\" ON events (host, region);","handlingStrategy":"try-catch","validationCode":"// Check for an existing cache with the same name and compare its definition before creating\nlet existing = provider.get_cache(table_id, &cache_name);\nif let Ok(c) = existing { /* compare columns/table before calling new_cache */ }","typeGuard":null,"tryCatchPattern":"// Rust\nmatch provider.new_cache(table_id, cols) {\n    Err(ProviderError::Cache(CacheError::ConfigurationMismatch { message })) => {\n        warn!(%message, \"cache exists with different config; dropping and recreating\");\n        provider.delete_cache(table_id, &cache_name)?;\n        provider.new_cache(table_id, cols)\n    }\n    other => other,\n}","preventionTips":["Drop and recreate explicitly when changing a cache definition","Version cache names (e.g. events_cache_v2) when configurations change","Keep cache definitions in version control so drift is visible"],"tags":["distinct-cache","conflict","influxdb3"],"backgroundTag":"conflicting-config-options","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"}