{"record":{"id":"f970915cce17bf36","repo":"thanos-io/thanos","slug":"max-item-size-v-cannot-be-bigger-than-overall-c","errorCode":null,"errorMessage":"max item size (%v) cannot be bigger than overall cache size (%v)","messagePattern":"max item size \\((.+?)\\) cannot be bigger than overall cache size \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/cache/inmemory.go","lineNumber":94,"sourceCode":"\treturn config, nil\n}\n\n// NewInMemoryIndexCache creates a new thread-safe LRU cache for index entries and ensures the total cache\n// size approximately does not exceed maxBytes.\nfunc NewInMemoryIndexCache(logger log.Logger, commonMetrics *CommonMetrics, reg prometheus.Registerer, conf []byte) (*InMemoryIndexCache, error) {\n\tconfig, err := parseInMemoryIndexCacheConfig(conf)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn NewInMemoryIndexCacheWithConfig(logger, commonMetrics, reg, config)\n}\n\n// NewInMemoryIndexCacheWithConfig creates a new thread-safe LRU cache for index entries and ensures the total cache\n// size approximately does not exceed maxBytes.\nfunc NewInMemoryIndexCacheWithConfig(logger log.Logger, commonMetrics *CommonMetrics, reg prometheus.Registerer, config InMemoryIndexCacheConfig) (*InMemoryIndexCache, error) {\n\tif config.MaxItemSize > config.MaxSize {\n\t\treturn nil, errors.Errorf(\"max item size (%v) cannot be bigger than overall cache size (%v)\", config.MaxItemSize, config.MaxSize)\n\t}\n\n\tif commonMetrics == nil {\n\t\tcommonMetrics = NewCommonMetrics(reg)\n\t}\n\n\tc := &InMemoryIndexCache{\n\t\tlogger:           logger,\n\t\tmaxSizeBytes:     uint64(config.MaxSize),\n\t\tmaxItemSizeBytes: uint64(config.MaxItemSize),\n\t\tcommonMetrics:    commonMetrics,\n\t}\n\n\tc.evicted = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{\n\t\tName: \"thanos_store_index_cache_items_evicted_total\",\n\t\tHelp: \"Total number of items that were evicted from the index cache.\",\n\t}, []string{\"item_type\"})\n\tc.evicted.WithLabelValues(CacheTypePostings)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/cache/inmemory.go#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nmax_size: 100000000\nmax_item_size: 2147483648\n// after\nmax_size: 2147483648\nmax_item_size: 1073741824","handlingStrategy":"validation","validationCode":"if cfg.MaxItemSize > cfg.MaxSize {\n\treturn fmt.Errorf(\"in-memory cache misconfigured: max_item_size (%d) must be <= max_size (%d)\", cfg.MaxItemSize, cfg.MaxSize)\n}","typeGuard":null,"tryCatchPattern":"if _, err := storecache.NewInMemoryIndexCacheWithConfig(logger, nil, reg, cfg); err != nil {\n\tif strings.Contains(err.Error(), \"cannot be bigger than overall cache size\") {\n\t\tcfg.MaxItemSize = cfg.MaxSize / 2 // or fail fast\n\t}\n\treturn err\n}","preventionTips":["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."],"tags":["config","cache","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}