DeepSeek V4.1 Flash · Balanced

unified-storage-performance-optimizations-grafana-codex

Grafana · Go · S · 30–99 lines · 5 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
2 of 3
Comments published
4
Comments matching a bug
2
Comments not matching
2
Cost of this PR
$0.129

Published comments (4)

highbugpkg/storage/unified/search/bleve.go:137-139

Concurrent cache misses can build duplicate indexes for same key — `getOrCreateIndex` now checks `GetIndex` outside any per-key lock, so two concurrent misses build separate indexes in the same directory and one caller keeps writing to an index already replaced in `b.cache`, making those documents unsearchable. Add per-key deduplication or an in-flight map so only one build per `NamespacedResource` runs at a time.

highbugpkg/storage/unified/resource/search.go:216

Logging TotalDocs races with watcher cache writes — The watch goroutine started just above can write the same cache under `cacheMu` while this call reads it, causing a concurrent map read/write panic. Synchronize `TotalDocs` with the cache writer or run it before the watcher starts.

mediumbugpkg/storage/unified/resource/server.go:258-262

Eager Init leaks watcher on unmanaged in-process servers — In-process servers from `restoptions.go` and `legacy_storage.go` have no `Stop` call site, so each construction starts a broadcaster goroutine and appends a subscriber to `dashboardSqlAccess.subscribers` that is never removed. Keep initialization lazy for servers that are not lifecycle-managed, or trigger shutdown for those construction paths.

mediumbugpkg/storage/unified/resource/server.go:258-262

Init failure leaks watcher and event-pump goroutines — The discarded instance never gets `Stop`, so the broadcaster and the `backend.WatchWriteEvents` subscription from `initWatcher`, plus the search event pump, keep running against the database forever. Call `s.cancel()` and close the started watchers on the error path before returning.

Gold bugs found (2)

mediumBuildIndex now locks only the final cache assignment, so concurrent callers for the same uncached key all build the same expensive index in parallel and the last one overwrites the others.
highThe new startup log calls TotalDocs, which iterates the index cache without a lock, after the event goroutine that can add indexes has started, so a concurrent map read and write can crash the process.

Gold bugs missed (1)

mediumThe PR skips the storage-server module integration test on postgres instead of fixing the failure, removing coverage of the new eager initialization on postgres.