mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
Generated
+26
-6
@@ -23739,7 +23739,7 @@ func (q *sqlQuerier) DeleteReplicasUpdatedBefore(ctx context.Context, updatedAt
|
||||
}
|
||||
|
||||
const getReplicaByID = `-- name: GetReplicaByID :one
|
||||
SELECT id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary" FROM replicas WHERE id = $1
|
||||
SELECT id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary", cluster_host, nats_port FROM replicas WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetReplicaByID(ctx context.Context, id uuid.UUID) (Replica, error) {
|
||||
@@ -23758,12 +23758,14 @@ func (q *sqlQuerier) GetReplicaByID(ctx context.Context, id uuid.UUID) (Replica,
|
||||
&i.Version,
|
||||
&i.Error,
|
||||
&i.Primary,
|
||||
&i.ClusterHost,
|
||||
&i.NATSPort,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getReplicasUpdatedAfter = `-- name: GetReplicasUpdatedAfter :many
|
||||
SELECT id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary" FROM replicas WHERE updated_at > $1 AND stopped_at IS NULL
|
||||
SELECT id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary", cluster_host, nats_port FROM replicas WHERE updated_at > $1 AND stopped_at IS NULL
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time.Time) ([]Replica, error) {
|
||||
@@ -23788,6 +23790,8 @@ func (q *sqlQuerier) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time
|
||||
&i.Version,
|
||||
&i.Error,
|
||||
&i.Primary,
|
||||
&i.ClusterHost,
|
||||
&i.NATSPort,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -23813,8 +23817,10 @@ INSERT INTO replicas (
|
||||
relay_address,
|
||||
version,
|
||||
database_latency,
|
||||
"primary"
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary"
|
||||
"primary",
|
||||
cluster_host,
|
||||
nats_port
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary", cluster_host, nats_port
|
||||
`
|
||||
|
||||
type InsertReplicaParams struct {
|
||||
@@ -23828,6 +23834,8 @@ type InsertReplicaParams struct {
|
||||
Version string `db:"version" json:"version"`
|
||||
DatabaseLatency int32 `db:"database_latency" json:"database_latency"`
|
||||
Primary bool `db:"primary" json:"primary"`
|
||||
ClusterHost string `db:"cluster_host" json:"cluster_host"`
|
||||
NATSPort int32 `db:"nats_port" json:"nats_port"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertReplica(ctx context.Context, arg InsertReplicaParams) (Replica, error) {
|
||||
@@ -23842,6 +23850,8 @@ func (q *sqlQuerier) InsertReplica(ctx context.Context, arg InsertReplicaParams)
|
||||
arg.Version,
|
||||
arg.DatabaseLatency,
|
||||
arg.Primary,
|
||||
arg.ClusterHost,
|
||||
arg.NATSPort,
|
||||
)
|
||||
var i Replica
|
||||
err := row.Scan(
|
||||
@@ -23857,6 +23867,8 @@ func (q *sqlQuerier) InsertReplica(ctx context.Context, arg InsertReplicaParams)
|
||||
&i.Version,
|
||||
&i.Error,
|
||||
&i.Primary,
|
||||
&i.ClusterHost,
|
||||
&i.NATSPort,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -23872,8 +23884,10 @@ UPDATE replicas SET
|
||||
version = $8,
|
||||
error = $9,
|
||||
database_latency = $10,
|
||||
"primary" = $11
|
||||
WHERE id = $1 RETURNING id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary"
|
||||
"primary" = $11,
|
||||
cluster_host = $12,
|
||||
nats_port = $13
|
||||
WHERE id = $1 RETURNING id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary", cluster_host, nats_port
|
||||
`
|
||||
|
||||
type UpdateReplicaParams struct {
|
||||
@@ -23888,6 +23902,8 @@ type UpdateReplicaParams struct {
|
||||
Error string `db:"error" json:"error"`
|
||||
DatabaseLatency int32 `db:"database_latency" json:"database_latency"`
|
||||
Primary bool `db:"primary" json:"primary"`
|
||||
ClusterHost string `db:"cluster_host" json:"cluster_host"`
|
||||
NATSPort int32 `db:"nats_port" json:"nats_port"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) UpdateReplica(ctx context.Context, arg UpdateReplicaParams) (Replica, error) {
|
||||
@@ -23903,6 +23919,8 @@ func (q *sqlQuerier) UpdateReplica(ctx context.Context, arg UpdateReplicaParams)
|
||||
arg.Error,
|
||||
arg.DatabaseLatency,
|
||||
arg.Primary,
|
||||
arg.ClusterHost,
|
||||
arg.NATSPort,
|
||||
)
|
||||
var i Replica
|
||||
err := row.Scan(
|
||||
@@ -23918,6 +23936,8 @@ func (q *sqlQuerier) UpdateReplica(ctx context.Context, arg UpdateReplicaParams)
|
||||
&i.Version,
|
||||
&i.Error,
|
||||
&i.Primary,
|
||||
&i.ClusterHost,
|
||||
&i.NATSPort,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user