Skip to content

Commit b8c3d58

Browse files
committed
Merge branch 'feature/fix_single_node_refresh' into develop
2 parents a68164d + 88e0695 commit b8c3d58

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ In an attempt to make this library more "idiomatic" some functions have been ren
3232
- Renamed `WriteChanges` to `ChangeResponse`, this is now a general type and can be used when dealing with changefeeds.
3333
- Removed depth limit when encoding values using `Expr`
3434

35+
## Fixed
36+
- Fixed issue causing nodes to remain unhealthy when host discovery is disabled (#195)
37+
3538
### Removed
3639

3740
- Removed `CacheSize` and `DataCenter` optional arguments in `TableCreateOpts`.

cluster.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,14 @@ func (c *Cluster) connectNodes(hosts []Host) {
206206
continue
207207
}
208208

209-
if c.opts.DiscoverHosts {
210-
var results []nodeStatus
211-
err = cursor.All(&results)
212-
if err != nil {
213-
continue
214-
}
209+
var results []nodeStatus
210+
err = cursor.All(&results)
211+
if err != nil {
212+
continue
213+
}
215214

216-
for _, result := range results {
217-
node, err := c.connectNodeWithStatus(result)
218-
if err == nil {
219-
if _, ok := nodeSet[node.ID]; !ok {
220-
log.WithFields(logrus.Fields{
221-
"id": node.ID,
222-
"host": node.Host.String(),
223-
}).Debug("Connected to node")
224-
nodeSet[node.ID] = node
225-
}
226-
}
227-
}
228-
} else {
229-
node, err := c.connectNode(host.String(), []Host{host})
215+
for _, result := range results {
216+
node, err := c.connectNodeWithStatus(result)
230217
if err == nil {
231218
if _, ok := nodeSet[node.ID]; !ok {
232219
log.WithFields(logrus.Fields{

node.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import (
88
p "github.com/dancannon/gorethink/ql2"
99
)
1010

11+
const (
12+
maxNodeHealth = 100
13+
)
14+
1115
// Node represents a database server in the cluster
1216
type Node struct {
1317
ID string
@@ -30,7 +34,7 @@ func newNode(id string, aliases []Host, cluster *Cluster, pool *Pool) *Node {
3034
aliases: aliases,
3135
cluster: cluster,
3236
pool: pool,
33-
health: 100,
37+
health: maxNodeHealth,
3438
refreshDoneChan: make(chan struct{}),
3539
}
3640
// Start node refresh loop
@@ -170,14 +174,14 @@ func (n *Node) Refresh() {
170174
n.ResetHealth()
171175
}
172176

173-
// DecrementHealth decreases the nodes health by 1 (the nodes health starts at 100)
177+
// DecrementHealth decreases the nodes health by 1 (the nodes health starts at maxNodeHealth)
174178
func (n *Node) DecrementHealth() {
175179
atomic.AddInt64(&n.health, -1)
176180
}
177181

178-
// ResetHealth sets the nodes health back to 100 (fully healthy)
182+
// ResetHealth sets the nodes health back to maxNodeHealth (fully healthy)
179183
func (n *Node) ResetHealth() {
180-
atomic.StoreInt64(&n.health, 100)
184+
atomic.StoreInt64(&n.health, maxNodeHealth)
181185
}
182186

183187
// IsHealthy checks the nodes health by ensuring that the health counter is above 0.

0 commit comments

Comments
 (0)