Lines Matching refs:rr
165 func (rr *roundRobin) watchAddrUpdates() error {
166 updates, err := rr.w.Next()
171 rr.mu.Lock()
172 defer rr.mu.Unlock()
181 for _, v := range rr.addrs {
191 rr.addrs = append(rr.addrs, &addrInfo{addr: addr})
193 for i, v := range rr.addrs {
195 copy(rr.addrs[i:], rr.addrs[i+1:])
196 rr.addrs = rr.addrs[:len(rr.addrs)-1]
205 open := make([]Address, len(rr.addrs))
206 for i, v := range rr.addrs {
209 if rr.done {
213 case <-rr.addrCh:
216 rr.addrCh <- open
220 func (rr *roundRobin) Start(target string, config BalancerConfig) error {
221 rr.mu.Lock()
222 defer rr.mu.Unlock()
223 if rr.done {
226 if rr.r == nil {
230 rr.addrs = append(rr.addrs, &addrInfo{addr: Address{Addr: target}})
233 w, err := rr.r.Resolve(target)
237 rr.w = w
238 rr.addrCh = make(chan []Address, 1)
241 if err := rr.watchAddrUpdates(); err != nil {
251 func (rr *roundRobin) Up(addr Address) func(error) {
252 rr.mu.Lock()
253 defer rr.mu.Unlock()
255 for _, a := range rr.addrs {
267 if cnt == 1 && rr.waitCh != nil {
268 close(rr.waitCh)
269 rr.waitCh = nil
272 rr.down(addr, err)
277 func (rr *roundRobin) down(addr Address, err error) {
278 rr.mu.Lock()
279 defer rr.mu.Unlock()
280 for _, a := range rr.addrs {
289 func (rr *roundRobin) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), …
291 rr.mu.Lock()
292 if rr.done {
293 rr.mu.Unlock()
298 if len(rr.addrs) > 0 {
299 if rr.next >= len(rr.addrs) {
300 rr.next = 0
302 next := rr.next
304 a := rr.addrs[next]
305 next = (next + 1) % len(rr.addrs)
308 rr.next = next
309 rr.mu.Unlock()
312 if next == rr.next {
319 if len(rr.addrs) == 0 {
320 rr.mu.Unlock()
325 addr = rr.addrs[rr.next].addr
326 rr.next++
327 rr.mu.Unlock()
331 if rr.waitCh == nil {
333 rr.waitCh = ch
335 ch = rr.waitCh
337 rr.mu.Unlock()
344 rr.mu.Lock()
345 if rr.done {
346 rr.mu.Unlock()
351 if len(rr.addrs) > 0 {
352 if rr.next >= len(rr.addrs) {
353 rr.next = 0
355 next := rr.next
357 a := rr.addrs[next]
358 next = (next + 1) % len(rr.addrs)
361 rr.next = next
362 rr.mu.Unlock()
365 if next == rr.next {
372 if rr.waitCh == nil {
374 rr.waitCh = ch
376 ch = rr.waitCh
378 rr.mu.Unlock()
383 func (rr *roundRobin) Notify() <-chan []Address {
384 return rr.addrCh
387 func (rr *roundRobin) Close() error {
388 rr.mu.Lock()
389 defer rr.mu.Unlock()
390 if rr.done {
393 rr.done = true
394 if rr.w != nil {
395 rr.w.Close()
397 if rr.waitCh != nil {
398 close(rr.waitCh)
399 rr.waitCh = nil
401 if rr.addrCh != nil {
402 close(rr.addrCh)