influxdata/influxdb · error · Error

last cache already exists for database and table, but it…

Error message

last cache already exists for database and table, but it was configured differently: {reason}

What it means

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.

Solutions

  1. Drop the existing last cache first, then create it with the new configuration
  2. Align the new configuration with the existing one (match key/value columns, size, TTL) so creation is idempotent
  3. Read the `reason` in the message to see exactly which field differs and fix that field
  4. Guard creation code: check for CacheAlreadyExists and treat same-config as success, different-config as an explicit drop+recreate

Example fix

// before
provider.create_last_cache(db, table, new_cfg)?; // fails if exists with different cfg
// after
if let Err(Error::CacheAlreadyExists { reason }) =
    provider.create_last_cache(db, table, new_cfg)
{
    provider.drop_last_cache(db, table)?;
    provider.create_last_cache(db, table, new_cfg)?;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// compare existing config with desired before creating
if let Some(existing) = provider.get_last_cache(db, table) {
    if existing.config() != desired_cfg {
        provider.drop_last_cache(db, table)?;
    }
}

Type guard

fn is_cache_already_exists(err: &Error) -> Option<&str> {
    if let Error::CacheAlreadyExists { reason } = err { Some(reason) } else { None }
}

Try / catch

match provider.create_last_cache(db, table, cfg) {
    Err(Error::CacheAlreadyExists { reason }) if reason_is_expected(&reason) => {
        // treat matching re-creation as success
    }
    r => r?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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'.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/2ab8c197d31ae6aa. Report an issue: GitHub.

Appendix: source

Thrown at influxdb3_cache/src/last_cache/mod.rs:18

//! The Last-N-Value cache holds the most N recent values for a column or set of columns on a table

use influxdb3_id::ColumnId;

mod cache;
pub use cache::CreateLastCacheArgs;
mod metrics;
mod provider;
pub use provider::{LastCacheProvider, background_catalog_update};
mod table_function;
use schema::InfluxColumnType;
pub use table_function::{LAST_CACHE_UDTF_NAME, LastCacheFunction};

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("invalid cache size")]
    InvalidCacheSize,
    #[error(
        "last cache already exists for database and table, but it was configured differently: {reason}"
    )]
    CacheAlreadyExists { reason: String },
    #[error("specified column (name: {column_name}) does not exist in the table definition")]
    ColumnDoesNotExistByName { column_name: String },
    #[error("specified column (id: {column_id}) does not exist in the table definition")]
    ColumnDoesNotExistById { column_id: ColumnId },
    #[error("specified key column (id: {column_id}) does not exist in the table schema")]
    KeyColumnDoesNotExist { column_id: ColumnId },
    #[error("specified key column (name: {column_name}) does not exist in the table schema")]
    KeyColumnDoesNotExistByName { column_name: String },
    #[error("key column must be string, int, uint, or bool types, got: {column_type}")]
    InvalidKeyColumn { column_type: InfluxColumnType },
    #[error("specified value column ({column_id}) does not exist in the table schema")]
    ValueColumnDoesNotExist { column_id: ColumnId },
    #[error("requested last cache does not exist")]
    CacheDoesNotExist,
}

View on GitHub (pinned to 06200ef96b)