mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-05-11 09:46:54 +00:00
dd2f044f2b
Closes #921 ## Summary Follow-up to #920 (incremental auto-vacuum). Addresses both items from the adversarial review: ### 1. RW connection caching Previously, every call to `openRW(dbPath)` opened a new SQLite RW connection and closed it after use. This happened in: - `runIncrementalVacuum` (~4x/hour) - `PruneOldPackets`, `PruneOldMetrics`, `RemoveStaleObservers` - `buildAndPersistEdges`, `PruneNeighborEdges` - All neighbor persist operations Now a single `*sql.DB` handle (with `MaxOpenConns(1)`) is cached process-wide via `cachedRW(dbPath)`. The underlying connection pool manages serialization. The original `openRW()` function is retained for one-shot test usage. ### 2. DBConfig dedup `DBConfig` was defined identically in both `cmd/server/config.go` and `cmd/ingestor/config.go`. Extracted to `internal/dbconfig/` as a shared package; both binaries now use a type alias (`type DBConfig = dbconfig.DBConfig`). ## Tests added | Test | File | |------|------| | `TestCachedRW_ReturnsSameHandle` | `cmd/server/rw_cache_test.go` | | `TestCachedRW_100Calls_SingleConnection` | `cmd/server/rw_cache_test.go` | | `TestGetIncrementalVacuumPages_Default` | `internal/dbconfig/dbconfig_test.go` | | `TestGetIncrementalVacuumPages_Configured` | `internal/dbconfig/dbconfig_test.go` | ## Verification ``` ok github.com/corescope/server 20.069s ok github.com/corescope/ingestor 47.117s ok github.com/meshcore-analyzer/dbconfig 0.003s ``` Both binaries build cleanly. 100 sequential `cachedRW()` calls return the same handle with exactly 1 entry in the cache map. --------- Co-authored-by: you <you@example.com>
36 lines
1.1 KiB
Modula-2
36 lines
1.1 KiB
Modula-2
module github.com/corescope/server
|
|
|
|
go 1.22
|
|
|
|
require (
|
|
github.com/gorilla/mux v1.8.1
|
|
github.com/gorilla/websocket v1.5.3
|
|
github.com/meshcore-analyzer/geofilter v0.0.0
|
|
github.com/meshcore-analyzer/sigvalidate v0.0.0
|
|
modernc.org/sqlite v1.34.5
|
|
)
|
|
|
|
replace github.com/meshcore-analyzer/geofilter => ../../internal/geofilter
|
|
|
|
replace github.com/meshcore-analyzer/sigvalidate => ../../internal/sigvalidate
|
|
|
|
require github.com/meshcore-analyzer/packetpath v0.0.0
|
|
|
|
replace github.com/meshcore-analyzer/packetpath => ../../internal/packetpath
|
|
|
|
require github.com/meshcore-analyzer/dbconfig v0.0.0
|
|
|
|
replace github.com/meshcore-analyzer/dbconfig => ../../internal/dbconfig
|
|
|
|
require (
|
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
|
github.com/google/uuid v1.6.0 // indirect
|
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
|
github.com/ncruces/go-strftime v0.1.9 // indirect
|
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
|
golang.org/x/sys v0.22.0 // indirect
|
|
modernc.org/libc v1.55.3 // indirect
|
|
modernc.org/mathutil v1.6.0 // indirect
|
|
modernc.org/memory v1.8.0 // indirect
|
|
)
|