-
Notifications
You must be signed in to change notification settings - Fork 4.6k
addrConn: change address to slice of address #1376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
9aca425
6c3802c
79d8768
cf20124
cb61eea
8dd35b4
0410e70
181dc4f
061729f
e3363f0
44c8b7c
65cf9da
0bff2f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,3 +395,40 @@ func (rr *roundRobin) Close() error { | |
} | ||
return nil | ||
} | ||
|
||
type pickFirst struct { | ||
rr *roundRobin | ||
} | ||
|
||
// PickFirst Balancer is a simple balancer for testing multi-addresses in one addrConn. | ||
// By using this balancer, all address shares the same addrConn. | ||
// Although it wrapped by RoundRobin balancer, the logic of all methods work fine because | ||
|
||
// balancer.Get() returns the address Up by resetTransport() | ||
func PickFirst(r naming.Resolver) Balancer { | ||
return &pickFirst{rr: &roundRobin{r: r}} | ||
} | ||
|
||
// The only difference is using ff.watchAddrUpdates() to use findFirstMD | ||
|
||
func (ff *pickFirst) Start(target string, config BalancerConfig) error { | ||
|
||
return ff.rr.Start(target, config) | ||
|
||
} | ||
|
||
// Up sets the connected state of addr and sends notification if there are pending | ||
// Get() calls. | ||
func (ff *pickFirst) Up(addr Address) func(error) { | ||
return ff.rr.Up(addr) | ||
} | ||
|
||
// Get returns the next addr in the rotation. | ||
func (ff *pickFirst) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) { | ||
addr, put, err = ff.rr.Get(ctx, opts) | ||
return | ||
} | ||
|
||
func (ff *pickFirst) Notify() <-chan []Address { | ||
return ff.rr.addrCh | ||
|
||
} | ||
|
||
func (ff *pickFirst) Close() error { | ||
return ff.rr.Close() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go on pickFirst instead, otherwise it will be visible in our godoc, but it's intended for readers of the code (not the API).