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:
Spike Curtis
2023-12-01 10:02:30 +04:00
committed by GitHub
parent 0cab6e7763
commit 571d358e4b
7 changed files with 104 additions and 0 deletions

View File

@ -122,6 +122,19 @@ DELETE
FROM tailnet_coordinators
WHERE heartbeat_at < now() - INTERVAL '24 HOURS';
-- name: CleanTailnetLostPeers :exec
DELETE
FROM tailnet_peers
WHERE updated_at < now() - INTERVAL '24 HOURS' AND status = 'lost'::tailnet_status;
-- 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
);
-- name: UpsertTailnetPeer :one
INSERT INTO
tailnet_peers (