Skip to content

Commit

Permalink
Merge #43873
Browse files Browse the repository at this point in the history
43873: storage: messing with Liveness.IsHealthy r=andreimatei a=andreimatei

See individual commits.

Co-authored-by: Andrei Matei <andrei@cockroachlabs.com>
  • Loading branch information
craig[bot] and andreimatei committed Jan 10, 2020
2 parents e3e0c7c + 14780dd commit 8635e9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 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(),
nl.GetLivenessThreshold(),
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
3 changes: 1 addition & 2 deletions pkg/storage/storagepb/liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ func (l *Liveness) IsLive(now hlc.Timestamp, maxOffset time.Duration) bool {
return now.Less(expiration)
}

// IsDead returns whether the node is considered dead at the given time with the
// given threshold.
// IsDead returns true if the liveness expired more than threshold ago.
func (l *Liveness) IsDead(now hlc.Timestamp, threshold time.Duration) bool {
deadAsOf := hlc.Timestamp(l.Expiration).GoTime().Add(threshold)
return !now.GoTime().Before(deadAsOf)
Expand Down

0 comments on commit 8635e9d

Please sign in to comment.