Added RPC calls to get the status from the master on non-master nodes
Release / release (push) Has been cancelled
Release / release (push) Has been cancelled
This commit is contained in:
@@ -189,7 +189,7 @@ func (c *controlServer) handleConn(ctx context.Context, conn net.Conn) {
|
|||||||
func (c *controlServer) dispatch(ctx context.Context, req CtrlRequest) CtrlResponse {
|
func (c *controlServer) dispatch(ctx context.Context, req CtrlRequest) CtrlResponse {
|
||||||
switch req.Method {
|
switch req.Method {
|
||||||
case CtrlStatus:
|
case CtrlStatus:
|
||||||
return ok(c.d.buildStatus())
|
return ok(c.d.buildStatusForCLI(ctx))
|
||||||
|
|
||||||
case CtrlMutate:
|
case CtrlMutate:
|
||||||
var body MutateBody
|
var body MutateBody
|
||||||
|
|||||||
@@ -113,6 +113,35 @@ func (d *Daemon) registerHandlers() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buildStatusForCLI is what the local control plane returns to `qu
|
||||||
|
// status`. Peers, quorum, and term come from the local view; check
|
||||||
|
// state is fetched from the master because the aggregator only runs
|
||||||
|
// there. If the master is unknown or unreachable, falls back to the
|
||||||
|
// local view (which will show "unknown" for every check).
|
||||||
|
func (d *Daemon) buildStatusForCLI(ctx context.Context) transport.StatusResponse {
|
||||||
|
local := d.buildStatus()
|
||||||
|
if d.quorum.IsMaster() {
|
||||||
|
return local
|
||||||
|
}
|
||||||
|
masterID := d.quorum.Master()
|
||||||
|
if masterID == "" {
|
||||||
|
return local
|
||||||
|
}
|
||||||
|
addr := d.addressOf(masterID)
|
||||||
|
if addr == "" {
|
||||||
|
return local
|
||||||
|
}
|
||||||
|
callCtx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
var remote transport.StatusResponse
|
||||||
|
if err := d.client.Call(callCtx, masterID, addr, transport.MethodStatus, transport.StatusRequest{}, &remote); err != nil {
|
||||||
|
d.logger.Printf("status: fetch from master %s: %v", masterID, err)
|
||||||
|
return local
|
||||||
|
}
|
||||||
|
local.Checks = remote.Checks
|
||||||
|
return local
|
||||||
|
}
|
||||||
|
|
||||||
// buildStatus is shared by both the inter-node Status RPC handler and
|
// buildStatus is shared by both the inter-node Status RPC handler and
|
||||||
// the local control plane's "status" command.
|
// the local control plane's "status" command.
|
||||||
func (d *Daemon) buildStatus() transport.StatusResponse {
|
func (d *Daemon) buildStatus() transport.StatusResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user