influxdata/influxdb · error · Error

invalid cache size

Error message

invalid cache size

What it means

Error::InvalidCacheSize is thrown by the last-n-nodes cache when a configured cache size is invalid. The last cache is bounded by a maximum number of entries, and creating or resizing it with a non-positive or otherwise unacceptable size fails with this error. It is a configuration validation failure at cache creation/update time.

Solutions

  1. Set the cache size to a positive integer within the allowed range
  2. Audit the cache configuration source (SQL statement, config file, or API call) for a zero or negative size
  3. Use the library's size constructor (which validates) instead of raw integers to catch invalid sizes early
  4. Check the influxdb3_cache version's accepted size limits and adjust the configuration

Example fix

// before
let size = LastCacheSize::new(0); // panics/errors later: invalid cache size
// after
let n = 0usize;
if n == 0 { return Err("last cache size must be > 0".into()); }
let size = LastCacheSize::new(n);
Defensive patterns

Strategy: validation

Validate before calling

// validate before calling the cache API
fn valid_size(n: usize) -> Result<usize, String> {
    if n == 0 { Err("last cache size must be a positive integer".into()) }
    else { Ok(n) }
}

Try / catch

match provider.create_last_cache(db, table, cfg) {
    Err(Error::InvalidCacheSize) => {
        // fall back to a sane default
        provider.create_last_cache(db, table, cfg.with_size(default_size))?
    }
    r => r?,
}

Prevention

When it happens

Trigger: Calling last cache creation APIs (e.g. create/upsert with a LastCacheSize argument) with a size of 0 or a value out of the accepted range; passing an invalid max card/size field in cache configuration via the write path or SQL CREATE CACHE.

Common situations: Copy-pasted config with size 0; computing the size dynamically and passing an uninitialized/empty value; unit mismatches (entries vs bytes); version changes where previously accepted sizes are now rejected.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

//! 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")]

View on GitHub (pinned to 06200ef96b)