File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ func (p *epsilonGreedyHostPool) SetEpsilon(newEpsilon float32) {
7171 p .epsilon = newEpsilon
7272}
7373
74+ func (p * epsilonGreedyHostPool ) SetHosts (hosts []string ) {
75+ p .Lock ()
76+ defer p .Unlock ()
77+ p .standardHostPool .setHosts (hosts )
78+ for _ , h := range p .hostList {
79+ h .epsilonCounts = make ([]int64 , epsilonBuckets )
80+ h .epsilonValues = make ([]int64 , epsilonBuckets )
81+ }
82+ }
83+
7484func (p * epsilonGreedyHostPool ) epsilonGreedyDecay () {
7585 durationPerBucket := p .decayDuration / epsilonBuckets
7686 ticker := time .Tick (durationPerBucket )
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ type HostPool interface {
4545
4646 ResetAll ()
4747 Hosts () []string
48+ SetHosts ([]string )
4849}
4950
5051type standardHostPool struct {
@@ -146,6 +147,26 @@ func (p *standardHostPool) ResetAll() {
146147 p .doResetAll ()
147148}
148149
150+ func (p * standardHostPool ) SetHosts (hosts []string ) {
151+ p .Lock ()
152+ defer p .Unlock ()
153+ p .setHosts (hosts )
154+ }
155+
156+ func (p * standardHostPool ) setHosts (hosts []string ) {
157+ p .hosts = make (map [string ]* hostEntry , len (hosts ))
158+ p .hostList = make ([]* hostEntry , len (hosts ))
159+
160+ for i , h := range hosts {
161+ e := & hostEntry {
162+ host : h ,
163+ retryDelay : p .initialRetryDelay ,
164+ }
165+ p .hosts [h ] = e
166+ p .hostList [i ] = e
167+ }
168+ }
169+
149170// this actually performs the logic to reset,
150171// and should only be called when the lock has
151172// already been acquired
You can’t perform that action at this time.
0 commit comments