mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: add queries to clean lost connections in PGCoordinator (#10938)
Adds cleanup queries to clean out "lost" peer and tunnel state after 24 hours. We leave this state in the database so that anything trying to connect to the peer can see that it was lost, but clean it up after 24 hours to ensure our table doesn't grow without bounds.
This commit is contained in:
@ -4522,6 +4522,31 @@ func (q *sqlQuerier) CleanTailnetCoordinators(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const cleanTailnetLostPeers = `-- name: CleanTailnetLostPeers :exec
|
||||
DELETE
|
||||
FROM tailnet_peers
|
||||
WHERE updated_at < now() - INTERVAL '24 HOURS' AND status = 'lost'::tailnet_status
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) CleanTailnetLostPeers(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, cleanTailnetLostPeers)
|
||||
return err
|
||||
}
|
||||
|
||||
const cleanTailnetTunnels = `-- name: CleanTailnetTunnels :exec
|
||||
DELETE FROM tailnet_tunnels
|
||||
WHERE updated_at < now() - INTERVAL '24 HOURS' AND
|
||||
NOT EXISTS (
|
||||
SELECT 1 FROM tailnet_peers
|
||||
WHERE id = tailnet_tunnels.src_id AND coordinator_id = tailnet_tunnels.coordinator_id
|
||||
)
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) CleanTailnetTunnels(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, cleanTailnetTunnels)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteAllTailnetClientSubscriptions = `-- name: DeleteAllTailnetClientSubscriptions :exec
|
||||
DELETE
|
||||
FROM tailnet_client_subscriptions
|
||||
|
Reference in New Issue
Block a user