chore: add replica_host and nats_port to replicas table (#26665)

relates to GRU-69

Adds cluster_host and nats_port to replicas table, to explicitly track NATS routes in the cluster.

I decided to make the NATS support explicit and transport the port number over the replicasync so that different Coder Servers can run on different ports. This is not something customers will typically care about, but is very useful for testing, so that they can all run on localhost within one machine.

I've also gone with a design where the NATS pubsub directly tells replicasync the port number _after_ it opens the socket. This is also very useful for testing because it allows us to have the OS assign the port number at runtime, avoiding races where we fail to bind to a free port.
This commit is contained in:
Spike Curtis
2026-06-24 15:04:04 -04:00
committed by GitHub
parent e0305cfa59
commit e8bd5004a2
10 changed files with 83 additions and 22 deletions
+7 -3
View File
@@ -15,8 +15,10 @@ INSERT INTO replicas (
relay_address,
version,
database_latency,
"primary"
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
"primary",
cluster_host,
nats_port
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *;
-- name: UpdateReplica :one
UPDATE replicas SET
@@ -29,7 +31,9 @@ UPDATE replicas SET
version = $8,
error = $9,
database_latency = $10,
"primary" = $11
"primary" = $11,
cluster_host = $12,
nats_port = $13
WHERE id = $1 RETURNING *;
-- name: DeleteReplicasUpdatedBefore :exec