health: Use sync.RWMutex instead of sync.Mutex (#3058)
This commit is contained in:

committed by
Menghan Li

parent
663e4ce0c9
commit
7aa94b7eef
@ -35,7 +35,7 @@ import (
|
|||||||
|
|
||||||
// Server implements `service Health`.
|
// Server implements `service Health`.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
mu sync.Mutex
|
mu sync.RWMutex
|
||||||
// If shutdown is true, it's expected all serving status is NOT_SERVING, and
|
// If shutdown is true, it's expected all serving status is NOT_SERVING, and
|
||||||
// will stay in NOT_SERVING.
|
// will stay in NOT_SERVING.
|
||||||
shutdown bool
|
shutdown bool
|
||||||
@ -54,8 +54,8 @@ func NewServer() *Server {
|
|||||||
|
|
||||||
// Check implements `service Health`.
|
// Check implements `service Health`.
|
||||||
func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
||||||
s.mu.Lock()
|
s.mu.RLock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.RUnlock()
|
||||||
if servingStatus, ok := s.statusMap[in.Service]; ok {
|
if servingStatus, ok := s.statusMap[in.Service]; ok {
|
||||||
return &healthpb.HealthCheckResponse{
|
return &healthpb.HealthCheckResponse{
|
||||||
Status: servingStatus,
|
Status: servingStatus,
|
||||||
|
Reference in New Issue
Block a user