Merge lp:~axwalk/juju-core/apiclient-open-parallel-fixes into lp:~go-bot/juju-core/trunk
Proposed by
Andrew Wilkins
Status: | Merged |
---|---|
Approved by: | Andrew Wilkins |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2526 |
Proposed branch: | lp:~axwalk/juju-core/apiclient-open-parallel-fixes |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
141 lines (+48/-12) 3 files modified
state/api/apiclient.go (+33/-11) state/api/apiclient_test.go (+11/-1) state/api/export_test.go (+4/-0) |
To merge this branch: | bzr merge lp:~axwalk/juju-core/apiclient-open-parallel-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+213569@code.launchpad.net |
Commit message
state/api: fixes to parallel api.Open
With these changes, api.Open will now
do the right thing if one of the dialers
succeeds before all are started. We also
introduce a short delay between starting
dialers, to avoid unnecessary dial
attempts.
Description of the change
state/api: fixes to parallel api.Open
With these changes, api.Open will now
do the right thing if one of the dialers
succeeds before all are started. We also
introduce a short delay between starting
dialers, to avoid unnecessary dial
attempts.
To post a comment you must log in.
Reviewers: mp+213569_ code.launchpad. net,
Message:
Please take a look.
Description:
state/api: fixes to parallel api.Open
With these changes, api.Open will now
do the right thing if one of the dialers
succeeds before all are started. We also
introduce a short delay between starting
dialers, to avoid unnecessary dial
attempts.
https:/ /code.launchpad .net/~axwalk/ juju-core/ apiclient- open-parallel- fixes/+ merge/213569
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/82900045/
Affected files (+49, -12 lines): apiclient. go apiclient_ test.go export_ test.go
A [revision details]
M state/api/
M state/api/
M state/api/
Index: [revision details] 20140401002201- jdbrb1jd9gomhhc i
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: state/api/ apiclient. go api/apiclient. go' apiclient. go 2014-03-31 14:43:24 +0000 apiclient. go 2014-04-01 03:13:49 +0000
=== modified file 'state/
--- state/api/
+++ state/api/
@@ -6,6 +6,7 @@
import (
"crypto/tls"
"crypto/x509"
+ "fmt"
"io"
"time"
@@ -84,6 +85,10 @@ rval: 50 * time.Millisecond,
// DialOpts holds configuration parameters that control the
// Dialing behavior when connecting to a state server.
type DialOpts struct {
+ // DialAddressInterval is the amount of time to wait
+ // before starting to dial another address.
+ DialAddressInterval time.Duration
+
// Timeout is the amount of time to wait contacting
// a state server.
Timeout time.Duration
@@ -97,8 +102,9 @@
// parameters for contacting a state server.
func DefaultDialOpts() DialOpts {
return DialOpts{
- Timeout: 10 * time.Minute,
- RetryDelay: 2 * time.Second,
+ DialAddressInte
+ Timeout: 10 * time.Minute,
+ RetryDelay: 2 * time.Second,
}
}
@@ -114,9 +120,16 @@ NewTry( maxParallelDial , nil) After(opts. DialAddressInte rval): newWebsocketDia ler(cfg, opts)) Try.Start. ler(cfg *websocket.Config, opts DialOpts) func(<-chan rategy{ Start() ; a.Next(); {
try := parallel.
defer try.Kill()
for _, addr := range info.Addrs {
- if err := dialWebsocket(addr, opts, pool, try); err != nil {
+ err := dialWebsocket(addr, opts, pool, try)
+ if err == parallel.ErrStopped {
+ break
+ } else if err != nil {
return nil, err
}
+ select {
+ case <-time.
+ case <-try.Dead():
+ }
}
try.Close()
result, err := try.Result()
@@ -160,28 +173,36 @@
RootCAs: rootCAs,
ServerName: "anything",
}
+ return try.Start(
+}
+
+// new WebsocketDialler returns a function that
+// can be passed to utils/parallel.
+func newWebsocketDia
struct{}) (io.Closer, error) {
openAttempt := utils.AttemptSt
Total: opts.Timeout,
Delay: opts.RetryDelay,
}
- return try.Start(func(stop <-chan struct{}) (io.Closer, error) {
- err := parallel.ErrStopped
+ return func(stop <-chan struct{}) (io.Closer, error) {
for a := openAttempt.
select {
case <-stop:
- break
+ return nil, parallel.ErrStopped
default:
}...