Skip to content

Commit 565dcf8

Browse files
committed
Added HostDecayDuration and fixed issues with hostpool
1 parent 18e7367 commit 565dcf8

File tree

7 files changed

+50
-24
lines changed

7 files changed

+50
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66
### Added
77
- Added `UUID` term
88
- Added `Values` term
9-
- Added `IncludeInitial` to `ChangesOpts`
9+
- Added `IncludeInitial` and `ChangefeedQueueSize` to `ChangesOpts`
1010
- Added `UseJSONNumber` to `ConnectOpts` which changes the way the JSON unmarshal works when deserializing JSON with interface{}, it's preferred to use json.Number instead float64 as it preserves the original precision.
11+
- Added `HostDecayDuration` to `ConnectOpts` to configure how hosts are selected. For more information see the godoc.
1112

1213
### Changed
1314
- Timezones from `time.Time` are now stored in the database, before all times were stored as UTC. To convert a go `time.Time` back to UTC you can call `t.In(time.UTC)`.
1415
- Improved host selection to use `hailocab/go-hostpool` to select nodes based on recent responses and timings.
1516

17+
### Deprecated
18+
- Deprecated the option `NodeRefreshInterval` in `ConnectOpts`
19+
1620
## v1.1.4
1721
### Added
1822
- Added root table terms (`r.TableCreate`, `r.TableList` and `r.TableDrop`)

cluster.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ type Cluster struct {
3434
// NewCluster creates a new cluster by connecting to the given hosts.
3535
func NewCluster(hosts []Host, opts *ConnectOpts) (*Cluster, error) {
3636
c := &Cluster{
37-
// TODO: Make this configurable
38-
hp: hostpool.NewEpsilonGreedy([]string{}, 0, &hostpool.LinearEpsilonValueCalculator{}),
37+
hp: hostpool.NewEpsilonGreedy([]string{}, opts.HostDecayDuration, &hostpool.LinearEpsilonValueCalculator{}),
3938
seeds: hosts,
4039
opts: opts,
4140
}
@@ -358,7 +357,6 @@ func (c *Cluster) GetNextNode() (*Node, hostpool.HostPoolResponse, error) {
358357
defer c.mu.RUnlock()
359358

360359
nodes := c.nodes
361-
362360
hpr := c.hp.Get()
363361
if n, ok := nodes[hpr.Host()]; ok {
364362
if !n.Closed() {

cluster_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (s *RethinkSuite) TestClusterRecoverAfterNoNodes(c *test.C) {
6363

6464
func (s *RethinkSuite) TestClusterNodeHealth(c *test.C) {
6565
session, err := Connect(ConnectOpts{
66-
Addresses: []string{url, url2, url3},
66+
Addresses: []string{url1, url2, url3},
6767
DiscoverHosts: true,
6868
NodeRefreshInterval: time.Second,
6969
MaxIdle: 50,
@@ -75,7 +75,7 @@ func (s *RethinkSuite) TestClusterNodeHealth(c *test.C) {
7575
failed := 0
7676
seconds := 0
7777

78-
t := time.NewTimer(time.Second * 10)
78+
t := time.NewTimer(time.Second * 30)
7979
tick := time.NewTicker(time.Second)
8080
for {
8181
select {

gorethink_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func init() {
2929
url = "localhost:28015"
3030
}
3131

32-
url2 = os.Getenv("RETHINKDB_URL_1")
33-
if url2 == "" {
34-
url2 = "localhost:28016"
32+
url1 = os.Getenv("RETHINKDB_URL_1")
33+
if url1 == "" {
34+
url1 = "localhost:28016"
3535
}
3636

3737
url2 = os.Getenv("RETHINKDB_URL_2")

ql2/ql2.pb.go

Lines changed: 29 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

query_table.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ func (t Term) IndexWait(args ...interface{}) Term {
145145

146146
// ChangesOpts contains the optional arguments for the Changes term
147147
type ChangesOpts struct {
148-
Squash interface{} `gorethink:"squash,omitempty"`
149-
IncludeInitial interface{} `gorethink:"include_initial,omitempty"`
150-
IncludeStates interface{} `gorethink:"include_states,omitempty"`
148+
Squash interface{} `gorethink:"squash,omitempty"`
149+
IncludeInitial interface{} `gorethink:"include_initial,omitempty"`
150+
IncludeStates interface{} `gorethink:"include_states,omitempty"`
151+
ChangefeedQueueSize interface{} `gorethink:"changefeed_queue_size,omitempty"`
151152
}
152153

153154
// ChangesOpts contains the optional arguments for the Changes term

session.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ type ConnectOpts struct {
4242
DiscoverHosts bool `gorethink:"discover_hosts,omitempty"`
4343
// NodeRefreshInterval is used to determine how often the driver should
4444
// refresh the status of a node.
45+
//
46+
// Deprecated: This function is no longer used due to changes in the
47+
// way hosts are selected.
4548
NodeRefreshInterval time.Duration `gorethink:"node_refresh_interval,omitempty"`
49+
// HostDecayDuration is used by the go-hostpool package to calculate a weighted
50+
// score when selecting a host. By default a value of 5 minutes is used.
51+
HostDecayDuration time.Duration
4652

4753
// Indicates whether the cursors running in this session should use json.Number instead of float64 while
4854
// unmarshaling documents with interface{}. The default is `false`.

0 commit comments

Comments
 (0)