{"record":{"id":"2ab8c197d31ae6aa","repo":"influxdata/influxdb","slug":"last-cache-already-exists-for-database-and-table-but-it-was","errorCode":null,"errorMessage":"last cache already exists for database and table, but it was configured differently: {reason}","messagePattern":"last cache already exists for database and table, but it was configured differently: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"influxdb3_cache/src/last_cache/mod.rs","lineNumber":18,"sourceCode":"//! The Last-N-Value cache holds the most N recent values for a column or set of columns on a table\n\nuse influxdb3_id::ColumnId;\n\nmod cache;\npub use cache::CreateLastCacheArgs;\nmod metrics;\nmod provider;\npub use provider::{LastCacheProvider, background_catalog_update};\nmod table_function;\nuse schema::InfluxColumnType;\npub use table_function::{LAST_CACHE_UDTF_NAME, LastCacheFunction};\n\n#[derive(Debug, thiserror::Error)]\npub enum Error {\n    #[error(\"invalid cache size\")]\n    InvalidCacheSize,\n    #[error(\n        \"last cache already exists for database and table, but it was configured differently: {reason}\"\n    )]\n    CacheAlreadyExists { reason: String },\n    #[error(\"specified column (name: {column_name}) does not exist in the table definition\")]\n    ColumnDoesNotExistByName { column_name: String },\n    #[error(\"specified column (id: {column_id}) does not exist in the table definition\")]\n    ColumnDoesNotExistById { column_id: ColumnId },\n    #[error(\"specified key column (id: {column_id}) does not exist in the table schema\")]\n    KeyColumnDoesNotExist { column_id: ColumnId },\n    #[error(\"specified key column (name: {column_name}) does not exist in the table schema\")]\n    KeyColumnDoesNotExistByName { column_name: String },\n    #[error(\"key column must be string, int, uint, or bool types, got: {column_type}\")]\n    InvalidKeyColumn { column_type: InfluxColumnType },\n    #[error(\"specified value column ({column_id}) does not exist in the table schema\")]\n    ValueColumnDoesNotExist { column_id: ColumnId },\n    #[error(\"requested last cache does not exist\")]\n    CacheDoesNotExist,\n}","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_cache/src/last_cache/mod.rs#L1-L36","documentation":"Error::CacheAlreadyExists is returned when creating a last cache for a database and table that already has one, but the new configuration differs from the existing one (reason included in the message). InfluxDB allows only one last cache per table; re-creating it with different settings is rejected so silent config drift cannot occur. If the configuration matches exactly, the call typically succeeds idempotently; only a mismatch raises this error.","triggerScenarios":"Issuing CREATE Last CACHE (or calling create_last_cache) for a table that already has a cache with different key columns, value columns, count, or TTL; re-running a migration/setup script after the cache settings were edited; replaying a creation statement with changed parameters.","commonSituations":"Idempotent bootstrap scripts where someone changed the cache definition between runs; two deploy pipelines provisioning the same table with different cache configs; after upgrading, altered defaults make an identical statement effectively 'different'.","solutions":["Drop the existing last cache first, then create it with the new configuration","Align the new configuration with the existing one (match key/value columns, size, TTL) so creation is idempotent","Read the `reason` in the message to see exactly which field differs and fix that field","Guard creation code: check for CacheAlreadyExists and treat same-config as success, different-config as an explicit drop+recreate"],"exampleFix":"// before\nprovider.create_last_cache(db, table, new_cfg)?; // fails if exists with different cfg\n// after\nif let Err(Error::CacheAlreadyExists { reason }) =\n    provider.create_last_cache(db, table, new_cfg)\n{\n    provider.drop_last_cache(db, table)?;\n    provider.create_last_cache(db, table, new_cfg)?;\n}","handlingStrategy":"try-catch","validationCode":"// compare existing config with desired before creating\nif let Some(existing) = provider.get_last_cache(db, table) {\n    if existing.config() != desired_cfg {\n        provider.drop_last_cache(db, table)?;\n    }\n}","typeGuard":"fn is_cache_already_exists(err: &Error) -> Option<&str> {\n    if let Error::CacheAlreadyExists { reason } = err { Some(reason) } else { None }\n}","tryCatchPattern":"match provider.create_last_cache(db, table, cfg) {\n    Err(Error::CacheAlreadyExists { reason }) if reason_is_expected(&reason) => {\n        // treat matching re-creation as success\n    }\n    r => r?,\n}","preventionTips":["Treat last cache creation as one-per-table and keep its definition in one place (config-as-code)","Drop-then-create when intentionally changing cache settings","Make idempotent setup scripts compare the reason field to distinguish drift from true conflicts"],"tags":["cache","conflict","last-cache","rust"],"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"}