diff --git a/internal/wrr/random.go b/internal/wrr/random.go index 25bbd82594d..4d91fc6f580 100644 --- a/internal/wrr/random.go +++ b/internal/wrr/random.go @@ -20,7 +20,6 @@ package wrr import ( "fmt" "sort" - "sync" "google.golang.org/grpc/internal/grpcrand" ) @@ -38,7 +37,6 @@ func (w *weightedItem) String() string { // randomWRR is a struct that contains weighted items implement weighted random algorithm. type randomWRR struct { - mu sync.RWMutex items []*weightedItem // Are all item's weights equal equalWeights bool @@ -52,8 +50,6 @@ func NewRandom() WRR { var grpcrandInt63n = grpcrand.Int63n func (rw *randomWRR) Next() (item any) { - rw.mu.RLock() - defer rw.mu.RUnlock() if len(rw.items) == 0 { return nil } @@ -72,8 +68,6 @@ func (rw *randomWRR) Next() (item any) { } func (rw *randomWRR) Add(item any, weight int64) { - rw.mu.Lock() - defer rw.mu.Unlock() accumulatedWeight := weight equalWeights := true if len(rw.items) > 0 { diff --git a/internal/wrr/wrr.go b/internal/wrr/wrr.go index d0d82cf4f01..91a40d7357e 100644 --- a/internal/wrr/wrr.go +++ b/internal/wrr/wrr.go @@ -21,12 +21,12 @@ package wrr // WRR defines an interface that implements weighted round robin. type WRR interface { - // Add adds an item with weight to the WRR set. - // - // Add and Next need to be thread safe. + // Add adds an item with weight to the WRR set. Add must be only called + // before any calls to Next. Add(item any, weight int64) // Next returns the next picked item. // - // Add and Next need to be thread safe. + // Next needs to be thread safe. Add may not be called after any call to + // Next. Next() any }