diff --git a/README.md b/README.md index bc56db03..030c9bd3 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,8 @@ usage can be tuned via the optional `db-config` section in config.json under "soft-heap-limit-mb": 16384, "max-open-connections": 4, "max-idle-connections": 4, - "max-idle-time-minutes": 10 + "max-idle-time-minutes": 10, + "busy-timeout-ms": 60000 } } } @@ -166,6 +167,7 @@ are used. | `max-open-connections` | 4 | Maximum number of open database connections. | | `max-idle-connections` | 4 | Maximum number of idle database connections kept in the pool. | | `max-idle-time-minutes` | 10 | Maximum time in minutes a connection can sit idle before being closed. | +| `busy-timeout-ms` | 60000 | SQLite busy timeout in milliseconds. When a write is blocked by another writer, SQLite retries internally with backoff for up to this duration before returning `SQLITE_BUSY`. | ### Sizing Guidelines diff --git a/cmd/cc-backend/main.go b/cmd/cc-backend/main.go index 9e1ea8aa..12faeae5 100644 --- a/cmd/cc-backend/main.go +++ b/cmd/cc-backend/main.go @@ -126,6 +126,9 @@ func initDatabase() error { if dc.ConnectionMaxIdleTimeMins > 0 { cfg.ConnectionMaxIdleTime = time.Duration(dc.ConnectionMaxIdleTimeMins) * time.Minute } + if dc.BusyTimeoutMs > 0 { + cfg.BusyTimeoutMs = dc.BusyTimeoutMs + } repository.SetConfig(cfg) } repository.Connect(config.Keys.DB) diff --git a/internal/config/config.go b/internal/config/config.go index e04d0a72..517c920e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -88,6 +88,7 @@ type DbConfig struct { MaxOpenConnections int `json:"max-open-connections"` MaxIdleConnections int `json:"max-idle-connections"` ConnectionMaxIdleTimeMins int `json:"max-idle-time-minutes"` + BusyTimeoutMs int `json:"busy-timeout-ms"` } type NodeStateRetention struct { diff --git a/internal/config/schema.go b/internal/config/schema.go index 64d9bcf8..26eacab9 100644 --- a/internal/config/schema.go +++ b/internal/config/schema.go @@ -201,6 +201,10 @@ var configSchema = ` "max-idle-time-minutes": { "description": "Maximum idle time for a connection in minutes (default: 10).", "type": "integer" + }, + "busy-timeout-ms": { + "description": "SQLite busy timeout in milliseconds. When a write is blocked, SQLite retries with backoff for up to this duration before returning SQLITE_BUSY (default: 60000).", + "type": "integer" } } }