Add production hardening: health check, streamer panic fix, db maintenance
- Add health check endpoint at /.well-known/healthcheck.json that verifies database and RIS Live connectivity, returns 200/503 - Fix panic in streamer when encountering unknown RIS message types by logging a warning and continuing instead of crashing - Add DBMaintainer for periodic database maintenance: - VACUUM every 6 hours to reclaim space - ANALYZE every hour to update query statistics - Graceful shutdown support - Add Vacuum() and Analyze() methods to database interface
This commit is contained in:
@@ -1950,3 +1950,23 @@ func (d *Database) getIPv6Info(ctx context.Context, ip string, parsedIP net.IP)
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
// Vacuum runs the SQLite VACUUM command to reclaim unused space and defragment the database.
|
||||
func (d *Database) Vacuum(ctx context.Context) error {
|
||||
_, err := d.db.ExecContext(ctx, "VACUUM")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to vacuum database: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Analyze runs the SQLite ANALYZE command to update query planner statistics.
|
||||
func (d *Database) Analyze(ctx context.Context) error {
|
||||
_, err := d.db.ExecContext(ctx, "ANALYZE")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to analyze database: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -81,6 +81,10 @@ type Store interface {
|
||||
|
||||
// Lifecycle
|
||||
Close() error
|
||||
|
||||
// Maintenance operations
|
||||
Vacuum(ctx context.Context) error
|
||||
Analyze(ctx context.Context) error
|
||||
}
|
||||
|
||||
// Ensure Database implements Store
|
||||
|
||||
Reference in New Issue
Block a user