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:
@@ -667,6 +667,8 @@ func (api *API) workspaceProxyRegister(rw http.ResponseWriter, r *http.Request)
|
||||
Error: req.ReplicaError,
|
||||
DatabaseLatency: 0,
|
||||
Primary: false,
|
||||
ClusterHost: "", // TODO
|
||||
NATSPort: 0, // TODO
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("update replica: %w", err)
|
||||
@@ -684,6 +686,8 @@ func (api *API) workspaceProxyRegister(rw http.ResponseWriter, r *http.Request)
|
||||
Version: req.Version,
|
||||
DatabaseLatency: 0,
|
||||
Primary: false,
|
||||
ClusterHost: "", // TODO
|
||||
NATSPort: 0, // TODO
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("insert replica: %w", err)
|
||||
@@ -826,6 +830,8 @@ func (api *API) workspaceProxyDeregister(rw http.ResponseWriter, r *http.Request
|
||||
Error: replica.Error,
|
||||
DatabaseLatency: replica.DatabaseLatency,
|
||||
Primary: replica.Primary,
|
||||
ClusterHost: "", // TODO
|
||||
NATSPort: 0, // TODO
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("update replica: %w", err)
|
||||
|
||||
@@ -77,6 +77,8 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, ps pubsub.P
|
||||
// #nosec G115 - Safe conversion for microseconds latency which is expected to be within int32 range
|
||||
DatabaseLatency: int32(databaseLatency.Microseconds()),
|
||||
Primary: true,
|
||||
ClusterHost: "", // TODO
|
||||
NATSPort: 0, // TODO
|
||||
})
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("insert replica: %w", err)
|
||||
@@ -327,6 +329,8 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
|
||||
// #nosec G115 - Safe conversion for microseconds latency which is expected to be within int32 range
|
||||
DatabaseLatency: int32(databaseLatency.Microseconds()),
|
||||
Primary: m.self.Primary,
|
||||
ClusterHost: "", // TODO
|
||||
NATSPort: 0, // TODO
|
||||
})
|
||||
if err != nil {
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -346,6 +350,8 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
|
||||
// #nosec G115 - Safe conversion for microseconds latency which is expected to be within int32 range
|
||||
DatabaseLatency: int32(databaseLatency.Microseconds()),
|
||||
Primary: m.self.Primary,
|
||||
ClusterHost: "", // TODO
|
||||
NATSPort: 0, // TODO
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("update replica: %w", err)
|
||||
@@ -497,6 +503,8 @@ func (m *Manager) Close() error {
|
||||
Error: m.self.Error,
|
||||
DatabaseLatency: 0, // A stopped replica has no latency.
|
||||
Primary: false, // A stopped replica cannot be primary.
|
||||
ClusterHost: "", // TODO
|
||||
NATSPort: 0, // TODO
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("update replica: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user