From 14780dd8ccc0f921b40736621f677a117722910d Mon Sep 17 00:00:00 2001 From: Andrei Matei Date: Fri, 10 Jan 2020 10:46:44 -0500 Subject: [PATCH] server,storage: move Liveness.IsHealthy() to caller IsHealthy() is a very specific function with a single caller. It doesn't deserve to live next to the other liveness code (which code is confusing enough without it). This patch embeds it in the caller. Release note: None --- pkg/server/status.go | 9 ++++++++- pkg/storage/node_liveness.go | 15 --------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/pkg/server/status.go b/pkg/server/status.go index 1a2333048ca3..138194b1b5b0 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -666,10 +666,17 @@ func (s *statusServer) Details( return nil, grpcstatus.Error(codes.Unavailable, "node is not ready") } - isHealthy, err := s.nodeLiveness.IsHealthy(nodeID) + clock := s.admin.server.clock + l, err := s.nodeLiveness.GetLiveness(nodeID) if err != nil { return nil, grpcstatus.Error(codes.Internal, err.Error()) } + ls := l.LivenessStatus( + clock.PhysicalTime(), + 0, /* threshold */ + clock.MaxOffset(), + ) + isHealthy := ls == storagepb.NodeLivenessStatus_LIVE if !isHealthy { return nil, grpcstatus.Error(codes.Unavailable, "node is not ready") } diff --git a/pkg/storage/node_liveness.go b/pkg/storage/node_liveness.go index f24796d1a0fd..4a8e2c5308b1 100644 --- a/pkg/storage/node_liveness.go +++ b/pkg/storage/node_liveness.go @@ -413,21 +413,6 @@ func (nl *NodeLiveness) IsLive(nodeID roachpb.NodeID) (bool, error) { return liveness.IsLive(nl.clock.Now(), nl.clock.MaxOffset()), nil } -// IsHealthy returns whether or not the specified node IsLive and is in a LIVE -// state, i.e. not draining, decommissioning, or otherwise unhealthy. -func (nl *NodeLiveness) IsHealthy(nodeID roachpb.NodeID) (bool, error) { - liveness, err := nl.GetLiveness(nodeID) - if err != nil { - return false, err - } - ls := liveness.LivenessStatus( - nl.clock.Now().GoTime(), - 0, /* threshold */ - nl.clock.MaxOffset(), - ) - return ls == storagepb.NodeLivenessStatus_LIVE, nil -} - // StartHeartbeat starts a periodic heartbeat to refresh this node's // last heartbeat in the node liveness table. The optionally provided // HeartbeatCallback will be invoked whenever this node updates its own liveness.