Skip to content

Commit

Permalink
server,storage: move Liveness.IsHealthy() to caller
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andreimatei committed Jan 10, 2020
1 parent 4eb19eb commit 14780dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
9 changes: 8 additions & 1 deletion pkg/server/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
15 changes: 0 additions & 15 deletions pkg/storage/node_liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 14780dd

Please sign in to comment.