thanos-io/thanos · error
max item size ( ) cannot be bigger than overall cache size…
Error message
max item size (%v) cannot be bigger than overall cache size (%v)
What it means
NewInMemoryIndexCacheWithConfig enforces that the maximum size of any single cached item does not exceed the overall byte budget of the in-memory LRU cache; otherwise every insert of a large item would immediately evict or never fit. It throws this error when config.MaxItemSize > config.MaxSize.
Solutions
- Set max_size to a value >= max_item_size.
- Lower max_item_size below max_size if the total budget is fixed.
- Remove max_item_size to use its default (usually derived from max_size).
Example fix
// before max_size: 100000000 max_item_size: 2147483648 // after max_size: 2147483648 max_item_size: 1073741824
Defensive patterns
Strategy: validation
Validate before calling
if cfg.MaxItemSize > cfg.MaxSize {
return fmt.Errorf("in-memory cache misconfigured: max_item_size (%d) must be <= max_size (%d)", cfg.MaxItemSize, cfg.MaxSize)
} Try / catch
if _, err := storecache.NewInMemoryIndexCacheWithConfig(logger, nil, reg, cfg); err != nil {
if strings.Contains(err.Error(), "cannot be bigger than overall cache size") {
cfg.MaxItemSize = cfg.MaxSize / 2 // or fail fast
}
return err
} Prevention
- Assert max_item_size <= max_size in config tests.
- Pick max_item_size as a fraction (e.g. 1/64) of max_size.
- Keep both values in the same unit (bytes) in generated config.
When it happens
Trigger: Calling NewInMemoryIndexCache or NewInMemoryIndexCacheWithConfig with an InMemoryIndexCacheConfig where MaxItemSize bytes is greater than MaxSize bytes, e.g. max_size: 100MB with max_item_size: 500MB, or MaxItemSize set while MaxSize left small.
Common situations: Hand-tuning store-gateway index-cache limits and swapping the two values; setting max_item_size from a guide without raising max_size; unit confusion between bytes values in YAML config.
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
- invalid FifoCache config
- unsupported compression type
- querier.cache-results may only be enabled in conjunction…
- invalid ResultsCache config for labels tripperware
- unsupported item type
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/f970915cce17bf36.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/store/cache/inmemory.go:94
return config, nil
}
// NewInMemoryIndexCache creates a new thread-safe LRU cache for index entries and ensures the total cache
// size approximately does not exceed maxBytes.
func NewInMemoryIndexCache(logger log.Logger, commonMetrics *CommonMetrics, reg prometheus.Registerer, conf []byte) (*InMemoryIndexCache, error) {
config, err := parseInMemoryIndexCacheConfig(conf)
if err != nil {
return nil, err
}
return NewInMemoryIndexCacheWithConfig(logger, commonMetrics, reg, config)
}
// NewInMemoryIndexCacheWithConfig creates a new thread-safe LRU cache for index entries and ensures the total cache
// size approximately does not exceed maxBytes.
func NewInMemoryIndexCacheWithConfig(logger log.Logger, commonMetrics *CommonMetrics, reg prometheus.Registerer, config InMemoryIndexCacheConfig) (*InMemoryIndexCache, error) {
if config.MaxItemSize > config.MaxSize {
return nil, errors.Errorf("max item size (%v) cannot be bigger than overall cache size (%v)", config.MaxItemSize, config.MaxSize)
}
if commonMetrics == nil {
commonMetrics = NewCommonMetrics(reg)
}
c := &InMemoryIndexCache{
logger: logger,
maxSizeBytes: uint64(config.MaxSize),
maxItemSizeBytes: uint64(config.MaxItemSize),
commonMetrics: commonMetrics,
}
c.evicted = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
Name: "thanos_store_index_cache_items_evicted_total",
Help: "Total number of items that were evicted from the index cache.",
}, []string{"item_type"})
c.evicted.WithLabelValues(CacheTypePostings)View on GitHub (pinned to 35b8b99117)