mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: improve coordinator peer mapping performance (#23696)
- Skipping DB querying entirely for peers that aren't actually connected to our coordinator - Opportunistically batching the queries for peers
This commit is contained in:
@@ -96,28 +96,6 @@ DELETE
|
||||
FROM tailnet_tunnels
|
||||
WHERE coordinator_id = $1 and src_id = $2;
|
||||
|
||||
-- name: GetTailnetTunnelPeerIDs :many
|
||||
SELECT dst_id as peer_id, coordinator_id, updated_at
|
||||
FROM tailnet_tunnels
|
||||
WHERE tailnet_tunnels.src_id = $1
|
||||
UNION
|
||||
SELECT src_id as peer_id, coordinator_id, updated_at
|
||||
FROM tailnet_tunnels
|
||||
WHERE tailnet_tunnels.dst_id = $1;
|
||||
|
||||
-- name: GetTailnetTunnelPeerBindings :many
|
||||
SELECT id AS peer_id, coordinator_id, updated_at, node, status
|
||||
FROM tailnet_peers
|
||||
WHERE id IN (
|
||||
SELECT dst_id as peer_id
|
||||
FROM tailnet_tunnels
|
||||
WHERE tailnet_tunnels.src_id = $1
|
||||
UNION
|
||||
SELECT src_id as peer_id
|
||||
FROM tailnet_tunnels
|
||||
WHERE tailnet_tunnels.dst_id = $1
|
||||
);
|
||||
|
||||
-- For PG Coordinator HTMLDebug
|
||||
|
||||
-- name: GetAllTailnetCoordinators :many
|
||||
@@ -128,3 +106,22 @@ SELECT * FROM tailnet_peers;
|
||||
|
||||
-- name: GetAllTailnetTunnels :many
|
||||
SELECT * FROM tailnet_tunnels;
|
||||
|
||||
-- name: GetTailnetTunnelPeerIDsBatch :many
|
||||
SELECT src_id AS lookup_id, dst_id AS peer_id, coordinator_id, updated_at
|
||||
FROM tailnet_tunnels WHERE src_id = ANY(@ids :: uuid[])
|
||||
UNION ALL
|
||||
SELECT dst_id AS lookup_id, src_id AS peer_id, coordinator_id, updated_at
|
||||
FROM tailnet_tunnels WHERE dst_id = ANY(@ids :: uuid[]);
|
||||
|
||||
-- name: GetTailnetTunnelPeerBindingsBatch :many
|
||||
SELECT tp.id AS peer_id, tp.coordinator_id, tp.updated_at, tp.node, tp.status,
|
||||
tunnels.lookup_id
|
||||
FROM (
|
||||
SELECT dst_id AS peer_id, src_id AS lookup_id
|
||||
FROM tailnet_tunnels WHERE src_id = ANY(@ids :: uuid[])
|
||||
UNION
|
||||
SELECT src_id AS peer_id, dst_id AS lookup_id
|
||||
FROM tailnet_tunnels WHERE dst_id = ANY(@ids :: uuid[])
|
||||
) tunnels
|
||||
INNER JOIN tailnet_peers tp ON tp.id = tunnels.peer_id;
|
||||
|
||||
Reference in New Issue
Block a user