Debian Codegraph @

cluster.go

raw symbols SCIP
1 package rethinkdbscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/
2
3 import (
4 "errorsscip-go gomod github.com/golang/go/src go1.14 errors/"
5 "fmtscip-go gomod github.com/golang/go/src go1.14 fmt/"
6 "sortscip-go gomod github.com/golang/go/src go1.14 sort/"
7 "stringsscip-go gomod github.com/golang/go/src go1.14 strings/"
8 "syncscip-go gomod github.com/golang/go/src go1.14 sync/"
9 "sync/atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/"
10 "timescip-go gomod github.com/golang/go/src go1.14 time/"
11
12 "github.com/hailocab/go-hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/"
13 "github.com/sirupsen/logrusscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/"
14 "golang.org/x/net/contextscip-go gomod golang.org/x/net eb5bcb51f2a3 `golang.org/x/net/context`/"
15 "gopkg.in/cenkalti/backoff.v2scip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/"
16 )
17
18 var errClusterClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/errClusterClosed. = errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("rethinkdb: cluster is closed")
19
20 const (
21 clusterWorkingscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/clusterWorking. = 0
22 clusterClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/clusterClosed. = 1
23 )
24
25 // A Cluster represents a connection to a RethinkDB cluster, a cluster is created
26 // by the Session and should rarely be created manually.
27 //
28 // The cluster keeps track of all nodes in the cluster and if requested can listen
29 // for cluster changes and start tracking a new node if one appears. Currently
30 // nodes are removed from the pool if they become unhealthy (100 failed queries).
31 // This should hopefully soon be replaced by a backoff system.
32 type Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster# struct {
33 optsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#opts. *ConnectOptsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ConnectOpts#
34
35 muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu. syncscip-go gomod github.com/golang/go/src go1.14 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#
36 seedsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#seeds. []Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host# // Initial host nodes specified by user.
37 hpscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#hp. hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/.HostPoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPool#
38 nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes. map[string]*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node# // Active nodes in cluster.
39 closedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#closed. int32 // 0 - working, 1 - closed
40
41 connFactoryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connFactory. connFactoryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/connFactory#
42
43 discoverIntervalscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#discoverInterval. timescip-go gomod github.com/golang/go/src go1.14 time/.Durationscip-go gomod github.com/golang/go/src go1.14 time/Duration#
44 }
45
46 // NewCluster creates a new cluster by connecting to the given hosts.
47 func NewClusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/NewCluster().(hosts []Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#, opts *ConnectOptsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ConnectOpts#) (*Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#, error) {
48 c := &Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#{
49 hpscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#hp.: newHostPoolscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/newHostPool().(opts),
50 seedsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#seeds.: hosts,
51 optsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#opts.: opts,
52 closedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#closed.: clusterWorkingscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/clusterWorking.,
53 connFactoryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connFactory.: NewConnectionscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/NewConnection().,
54 }
55
56 err := c.runscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#run().()
57 if err != nil {
58 return nil, err
59 }
60
61 return c, nil
62 }
63
64 func newHostPoolscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/newHostPool().(opts *ConnectOptsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ConnectOpts#) hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/.HostPoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPool# {
65 return hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/.NewEpsilonGreedyscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/NewEpsilonGreedy().([]string{}, opts.HostDecayDurationscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ConnectOpts#HostDecayDuration., &hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/.LinearEpsilonValueCalculatorscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/LinearEpsilonValueCalculator#{})
66 }
67
68 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) runscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#run().() error {
69 // Attempt to connect to each host and discover any additional hosts if host
70 // discovery is enabled
71 if err := c.connectClusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connectCluster().(); err != nil {
72 return err
73 }
74
75 if !c.IsConnectedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#IsConnected().() {
76 return ErrNoConnectionsStartedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ErrNoConnectionsStarted.
77 }
78 return nil
79 }
80
81 // Query executes a ReQL query using the cluster to connect to the database
82 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) Queryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#Query().(ctx contextscip-go gomod golang.org/x/net eb5bcb51f2a3 `golang.org/x/net/context`/.Contextscip-go gomod golang.org/x/net eb5bcb51f2a3 `golang.org/x/net/context`/Context#, q Queryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Query#) (cursor *Cursorscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cursor#, err error) {
83 for i := 0; i < c.numRetriesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#numRetries().(); i++ {
84 var node *Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#
85 var hpr hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/.HostPoolResponsescip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#
86
87 node, hpr, err = c.GetNextNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNextNode().()
88 if err != nil {
89 return nil, err
90 }
91
92 cursor, err = node.Queryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Query().(ctx, q)
93 hpr.Markscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#Mark().(err)
94
95 if !shouldRetryQueryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/shouldRetryQuery().(q, err) {
96 break
97 }
98 }
99
100 return cursor, err
101 }
102
103 // Exec executes a ReQL query using the cluster to connect to the database
104 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) Execscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#Exec().(ctx contextscip-go gomod golang.org/x/net eb5bcb51f2a3 `golang.org/x/net/context`/.Contextscip-go gomod golang.org/x/net eb5bcb51f2a3 `golang.org/x/net/context`/Context#, q Queryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Query#) (err error) {
105 for i := 0; i < c.numRetriesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#numRetries().(); i++ {
106 var node *Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#
107 var hpr hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/.HostPoolResponsescip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#
108
109 node, hpr, err = c.GetNextNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNextNode().()
110 if err != nil {
111 return err
112 }
113
114 err = node.Execscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Exec().(ctx, q)
115 hpr.Markscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#Mark().(err)
116
117 if !shouldRetryQueryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/shouldRetryQuery().(q, err) {
118 break
119 }
120 }
121
122 return err
123 }
124
125 // Server returns the server name and server UUID being used by a connection.
126 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) Serverscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#Server().() (response ServerResponsescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ServerResponse#, err error) {
127 for i := 0; i < c.numRetriesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#numRetries().(); i++ {
128 var node *Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#
129 var hpr hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/.HostPoolResponsescip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#
130
131 node, hpr, err = c.GetNextNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNextNode().()
132 if err != nil {
133 return ServerResponsescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ServerResponse#{}, err
134 }
135
136 response, err = node.Serverscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Server().()
137 hpr.Markscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#Mark().(err)
138
139 // This query should not fail so retry if any error is detected
140 if err == nil {
141 break
142 }
143 }
144
145 return response, err
146 }
147
148 // SetInitialPoolCap sets the initial capacity of the connection pool.
149 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) SetInitialPoolCapscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#SetInitialPoolCap().(n int) {
150 for _, node := range c.GetNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNodes().() {
151 node.SetInitialPoolCapscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#SetInitialPoolCap().(n)
152 }
153 }
154
155 // SetMaxIdleConns sets the maximum number of connections in the idle
156 // connection pool.
157 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) SetMaxIdleConnsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#SetMaxIdleConns().(n int) {
158 for _, node := range c.GetNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNodes().() {
159 node.SetMaxIdleConnsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#SetMaxIdleConns().(n)
160 }
161 }
162
163 // SetMaxOpenConns sets the maximum number of open connections to the database.
164 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) SetMaxOpenConnsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#SetMaxOpenConns().(n int) {
165 for _, node := range c.GetNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNodes().() {
166 node.SetMaxOpenConnsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#SetMaxOpenConns().(n)
167 }
168 }
169
170 // Close closes the cluster
171 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) Closescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#Close().(optArgs ...CloseOptsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/CloseOpts#) error {
172 if c.isClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#isClosed().() {
173 return nil
174 }
175
176 for _, node := range c.GetNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNodes().() {
177 err := node.Closescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Close().(optArgs...)
178 if err != nil {
179 return err
180 }
181 }
182
183 c.hpscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#hp..Closescip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPool#Close().()
184 atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.StoreInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/StoreInt32().(&c.closedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#closed., clusterClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/clusterClosed.)
185
186 return nil
187 }
188
189 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) isClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#isClosed().() bool {
190 return atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.LoadInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/LoadInt32().(&c.closedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#closed.) == clusterClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/clusterClosed.
191 }
192
193 // discover attempts to find new nodes in the cluster using the current nodes
194 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) discoverscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#discover().() {
195 // Keep retrying with exponential backoff.
196 b := backoffscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/.NewExponentialBackOffscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/NewExponentialBackOff().()
197 // Never finish retrying (max interval is still 60s)
198 b.MaxElapsedTimescip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/ExponentialBackOff#MaxElapsedTime. = 0
199 if c.discoverIntervalscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#discoverInterval. != 0 {
200 b.InitialIntervalscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/ExponentialBackOff#InitialInterval. = c.discoverIntervalscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#discoverInterval.
201 }
202
203 // Keep trying to discover new nodes
204 for {
205 if c.isClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#isClosed().() {
206 return
207 }
208
209 _ = backoffscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/.RetryNotifyscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/RetryNotify().(func() error {
210 if c.isClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#isClosed().() {
211 return backoffscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/.Permanentscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/Permanent().(errClusterClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/errClusterClosed.)
212 }
213 // If no hosts try seeding nodes
214 if len(c.GetNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNodes().()) == 0 {
215 return c.connectClusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connectCluster().()
216 }
217
218 return c.listenForNodeChangesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#listenForNodeChanges().()
219 }, b, func(err error, wait timescip-go gomod github.com/golang/go/src go1.14 time/.Durationscip-go gomod github.com/golang/go/src go1.14 time/Duration#) {
220 Logscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Log..Debugfscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Logger#Debugf().("Error discovering hosts %s, waiting: %s", err, wait)
221 })
222 }
223 }
224
225 // listenForNodeChanges listens for changes to node status using change feeds.
226 // This function will block until the query fails
227 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) listenForNodeChangesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#listenForNodeChanges().() error {
228 // Start listening to changes from a random active node
229 node, hpr, err := c.GetNextNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNextNode().()
230 if err != nil {
231 return err
232 }
233
234 q, err := newQueryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/newQuery().(
235 DBscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/DB().(SystemDatabasescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/SystemDatabase.).Tablescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Term#Table().(ServerStatusSystemTablescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ServerStatusSystemTable.).Changesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Term#Changes().(ChangesOptsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ChangesOpts#{IncludeInitialscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ChangesOpts#IncludeInitial.: true}),
236 map[string]interface{}{},
237 c.optsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#opts.,
238 )
239 if err != nil {
240 return fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("Error building query: %s", err)
241 }
242
243 cursor, err := node.Queryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Query().(contextscip-go gomod golang.org/x/net eb5bcb51f2a3 `golang.org/x/net/context`/.Backgroundscip-go gomod golang.org/x/net eb5bcb51f2a3 `golang.org/x/net/context`/Background().(), q) // no need for timeout due to Changes()
244 if err != nil {
245 hpr.Markscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#Mark().(err)
246 return err
247 }
248 defer func() { _ = cursor.Closescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cursor#Close().() }()
249
250 // Keep reading node status updates from changefeed
251 var result struct {
252 NewVal *nodeStatusscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus# `rethinkdb:"new_val"`
253 OldVal *nodeStatusscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus# `rethinkdb:"old_val"`
254 }
255 for cursor.Nextscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cursor#Next().(&result) {
256 addr := fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("%s:%d", result.NewVal.Networkscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#Network..Hostnamescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatusNetwork#Hostname., result.NewVal.Networkscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#Network..ReqlPortscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatusNetwork#ReqlPort.)
257 addr = stringsscip-go gomod github.com/golang/go/src go1.14 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.14 strings/ToLower().(addr)
258
259 if result.NewVal != nil && result.OldVal == nil {
260 // added new node
261 if !c.nodeExistsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodeExists().(result.NewVal.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#ID.) {
262 // Connect to node using exponential backoff (give up after waiting 5s)
263 // to give the node time to start-up.
264 b := backoffscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/.NewExponentialBackOffscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/NewExponentialBackOff().()
265 b.MaxElapsedTimescip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/ExponentialBackOff#MaxElapsedTime. = timescip-go gomod github.com/golang/go/src go1.14 time/.Secondscip-go gomod github.com/golang/go/src go1.14 time/Second. * 5
266
267 err = backoffscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/.Retryscip-go gomod gopkg.in/cenkalti/backoff.v2 v2.2.1 `gopkg.in/cenkalti/backoff.v2`/Retry().(func() error {
268 node, err := c.connectNodeWithStatusscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connectNodeWithStatus().(result.NewVal)
269 if err == nil {
270 c.addNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#addNode().(node)
271
272 Logscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Log..WithFieldsscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Logger#WithFields().(logrusscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/.Fieldsscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Fields#{
273 "id": node.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#ID.,
274 "host": node.Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Host..Stringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#String().(),
275 }).Debugscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Entry#Debug().("Connected to node")
276 }
277 return err
278 }, b)
279 if err != nil {
280 return err
281 }
282 }
283 } else if result.OldVal != nil && result.NewVal == nil {
284 // removed old node
285 oldNode := c.removeNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#removeNode().(result.OldVal.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#ID.)
286 if oldNode != nil {
287 _ = oldNode.Closescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Close().()
288 }
289 } else {
290 // node updated
291 // nothing to do - assuming node can't change it's hostname in a single Changes() message
292 }
293 }
294
295 err = cursor.Errscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cursor#Err().()
296 hpr.Markscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#Mark().(err)
297 return err
298 }
299
300 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) connectClusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connectCluster().() error {
301 nodeSet := map[string]*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#{}
302 var attemptErr error
303
304 // Attempt to connect to each seed host
305 for _, host := range c.seedsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#seeds. {
306 conn, err := c.connFactoryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connFactory.(host.Stringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#String().(), c.optsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#opts.)
307 if err != nil {
308 attemptErr = err
309 Logscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Log..Warnfscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Logger#Warnf().("Error creating connection: %s", err.Error())
310 continue
311 }
312
313 svrRsp, err := conn.Serverscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Connection#Server().()
314 if err != nil {
315 attemptErr = err
316 Logscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Log..Warnfscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Logger#Warnf().("Error fetching server ID: %s", err)
317 _ = conn.Closescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Connection#Close().()
318
319 continue
320 }
321 _ = conn.Closescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Connection#Close().()
322
323 node, err := c.connectNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connectNode().(svrRsp.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ServerResponse#ID., []Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#{host})
324 if err != nil {
325 attemptErr = err
326 Logscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Log..Warnfscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Logger#Warnf().("Error connecting to node: %s", err)
327 continue
328 }
329
330 if _, ok := nodeSet[node.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#ID.]; !ok {
331 Logscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Log..WithFieldsscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Logger#WithFields().(logrusscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/.Fieldsscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Fields#{
332 "id": node.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#ID.,
333 "host": node.Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Host..Stringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#String().(),
334 }).Debugscip-go gomod github.com/sirupsen/logrus v1.0.6 `github.com/sirupsen/logrus`/Entry#Debug().("Connected to node")
335
336 nodeSet[node.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#ID.] = node
337 } else {
338 // dublicate node
339 _ = node.Closescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Close().()
340 }
341 }
342
343 // If no nodes were contactable then return the last error, this does not
344 // include driver errors such as if there was an issue building the
345 // query
346 if len(nodeSet) == 0 {
347 if attemptErr != nil {
348 return attemptErr
349 }
350 return ErrNoConnectionsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ErrNoConnections.
351 }
352
353 var nodes []*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#
354 for _, node := range nodeSet {
355 nodes = append(nodes, node)
356 }
357 c.replaceNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#replaceNodes().(nodes)
358
359 if c.optsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#opts..DiscoverHostsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ConnectOpts#DiscoverHosts. {
360 go c.discoverscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#discover().()
361 }
362
363 return nil
364 }
365
366 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) connectNodeWithStatusscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connectNodeWithStatus().(s *nodeStatusscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#) (*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#, error) {
367 aliases := make([]Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#, len(s.Networkscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#Network..CanonicalAddressesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatusNetwork#CanonicalAddresses.))
368 for i, aliasAddress := range s.Networkscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#Network..CanonicalAddressesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatusNetwork#CanonicalAddresses. {
369 aliases[i] = NewHostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/NewHost().(aliasAddress.Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatusNetworkAddr#Host., int(s.Networkscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#Network..ReqlPortscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatusNetwork#ReqlPort.))
370 }
371
372 return c.connectNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connectNode().(s.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/nodeStatus#ID., aliases)
373 }
374
375 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) connectNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connectNode().(id string, aliases []Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#) (*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#, error) {
376 var pool *Poolscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Pool#
377 var err error
378
379 for len(aliases) > 0 {
380 pool, err = newPoolscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/newPool().(aliases[0], c.optsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#opts., c.connFactoryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#connFactory.)
381 if err != nil {
382 aliases = aliases[1:]
383 continue
384 }
385
386 err = pool.Pingscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Pool#Ping().()
387 if err != nil {
388 aliases = aliases[1:]
389 continue
390 }
391
392 // Ping successful so break out of loop
393 break
394 }
395
396 if err != nil {
397 return nil, err
398 }
399 if len(aliases) == 0 {
400 return nil, ErrInvalidNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ErrInvalidNode.
401 }
402
403 return newNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/newNode().(id, aliases, pool), nil
404 }
405
406 // IsConnected returns true if cluster has nodes and is not already connClosed.
407 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) IsConnectedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#IsConnected().() bool {
408 return (len(c.GetNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNodes().()) > 0) && !c.isClosedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#isClosed().()
409 }
410
411 // GetNextNode returns a random node on the cluster
412 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) GetNextNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNextNode().() (*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#, hostpoolscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/.HostPoolResponsescip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#, error) {
413 if !c.IsConnectedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#IsConnected().() {
414 return nil, nil, ErrNoConnectionsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ErrNoConnections.
415 }
416 c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..RLockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#RLock().()
417 defer c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..RUnlockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#RUnlock().()
418
419 nodes := c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes.
420 hpr := c.hpscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#hp..Getscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPool#Get().()
421 if n, ok := nodes[hpr.Hostscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPoolResponse#Host().()]; ok {
422 if !n.Closedscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Closed().() {
423 return n, hpr, nil
424 }
425 }
426
427 return nil, nil, ErrNoConnectionsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ErrNoConnections.
428 }
429
430 // GetNodes returns a list of all nodes in the cluster
431 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) GetNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#GetNodes().() []*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node# {
432 c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..RLockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#RLock().()
433 defer c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..RUnlockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#RUnlock().()
434 nodes := make([]*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#, 0, len(c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes.))
435 for _, n := range c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes. {
436 nodes = append(nodes, n)
437 }
438
439 return nodes
440 }
441
442 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) nodeExistsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodeExists().(nodeID string) bool {
443 c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..RLockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#RLock().()
444 defer c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..RUnlockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#RUnlock().()
445 for _, node := range c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes. {
446 if node.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#ID. == nodeID {
447 return true
448 }
449 }
450 return false
451 }
452
453 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) addNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#addNode().(node *Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#) {
454 host := node.Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Host..Stringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#String().()
455 c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..Lockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#Lock().()
456 defer c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..Unlockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#Unlock().()
457 if _, exist := c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes.[host]; exist {
458 // addNode() should be called only if the node doesn't exist
459 return
460 }
461
462 c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes.[host] = node
463
464 hosts := make([]string, 0, len(c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes.))
465 for _, n := range c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes. {
466 hosts = append(hosts, n.Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Host..Stringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#String().())
467 }
468 c.hpscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#hp..SetHostsscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPool#SetHosts().(hosts)
469 }
470
471 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) replaceNodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#replaceNodes().(nodes []*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#) {
472 nodesMap := make(map[string]*Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#, len(nodes))
473 hosts := make([]string, len(nodes))
474 for i, node := range nodes {
475 host := node.Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Host..Stringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#String().()
476
477 nodesMap[host] = node
478 hosts[i] = host
479 }
480
481 sortscip-go gomod github.com/golang/go/src go1.14 sort/.Stringsscip-go gomod github.com/golang/go/src go1.14 sort/Strings().(hosts) // unit tests stability
482
483 c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..Lockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#Lock().()
484 c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes. = nodesMap
485 c.hpscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#hp..SetHostsscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPool#SetHosts().(hosts)
486 c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..Unlockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#Unlock().()
487 }
488
489 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) removeNodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#removeNode().(nodeID string) *Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node# {
490 c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..Lockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#Lock().()
491 defer c.muscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#mu..Unlockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#Unlock().()
492 var rmNode *Nodescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#
493 for _, node := range c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes. {
494 if node.IDscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#ID. == nodeID {
495 rmNode = node
496 break
497 }
498 }
499 if rmNode == nil {
500 return nil
501 }
502
503 delete(c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes., rmNode.Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Host..Stringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#String().())
504
505 hosts := make([]string, 0, len(c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes.))
506 for _, n := range c.nodesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#nodes. {
507 hosts = append(hosts, n.Hostscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Node#Host..Stringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Host#String().())
508 }
509 c.hpscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#hp..SetHostsscip-go gomod github.com/hailocab/go-hostpool e80d13ce29ed `github.com/hailocab/go-hostpool`/HostPool#SetHosts().(hosts)
510
511 return rmNode
512 }
513
514 func (c *Clusterscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#) numRetriesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#numRetries().() int {
515 if n := c.optsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/Cluster#opts..NumRetriesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6`/ConnectOpts#NumRetries.; n > 0 {
516 return n
517 }
518
519 return 3
520 }