Skip to content

Commit e202162

Browse files
committed
api: make RoundRobinStrategy private
Part of #158
1 parent c433683 commit e202162

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2020

2121
- multi subpackage (#240)
2222
- msgpack.v2 support (#236)
23+
- pool/RoundRobinStrategy (#158)
2324

2425
### Fixed
2526

pool/connection_pool.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ type ConnectionPool struct {
9797

9898
state state
9999
done chan struct{}
100-
roPool *RoundRobinStrategy
101-
rwPool *RoundRobinStrategy
102-
anyPool *RoundRobinStrategy
100+
roPool *roundRobinStrategy
101+
rwPool *roundRobinStrategy
102+
anyPool *roundRobinStrategy
103103
poolsMutex sync.RWMutex
104104
watcherContainer watcherContainer
105105
}
@@ -141,9 +141,9 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts Opts) (connPo
141141
}
142142

143143
size := len(addrs)
144-
rwPool := NewEmptyRoundRobin(size)
145-
roPool := NewEmptyRoundRobin(size)
146-
anyPool := NewEmptyRoundRobin(size)
144+
rwPool := newRoundRobinStrategy(size)
145+
roPool := newRoundRobinStrategy(size)
146+
anyPool := newRoundRobinStrategy(size)
147147

148148
connPool = &ConnectionPool{
149149
addrs: make(map[string]*endpoint),

pool/round_robin.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ import (
66
"github.com/tarantool/go-tarantool/v2"
77
)
88

9-
type RoundRobinStrategy struct {
9+
type roundRobinStrategy struct {
1010
conns []*tarantool.Connection
1111
indexByAddr map[string]uint
1212
mutex sync.RWMutex
1313
size uint
1414
current uint
1515
}
1616

17-
func NewEmptyRoundRobin(size int) *RoundRobinStrategy {
18-
return &RoundRobinStrategy{
17+
func newRoundRobinStrategy(size int) *roundRobinStrategy {
18+
return &roundRobinStrategy{
1919
conns: make([]*tarantool.Connection, 0, size),
2020
indexByAddr: make(map[string]uint),
2121
size: 0,
2222
current: 0,
2323
}
2424
}
2525

26-
func (r *RoundRobinStrategy) GetConnByAddr(addr string) *tarantool.Connection {
26+
func (r *roundRobinStrategy) GetConnByAddr(addr string) *tarantool.Connection {
2727
r.mutex.RLock()
2828
defer r.mutex.RUnlock()
2929

@@ -35,7 +35,7 @@ func (r *RoundRobinStrategy) GetConnByAddr(addr string) *tarantool.Connection {
3535
return r.conns[index]
3636
}
3737

38-
func (r *RoundRobinStrategy) DeleteConnByAddr(addr string) *tarantool.Connection {
38+
func (r *roundRobinStrategy) DeleteConnByAddr(addr string) *tarantool.Connection {
3939
r.mutex.Lock()
4040
defer r.mutex.Unlock()
4141

@@ -63,14 +63,14 @@ func (r *RoundRobinStrategy) DeleteConnByAddr(addr string) *tarantool.Connection
6363
return conn
6464
}
6565

66-
func (r *RoundRobinStrategy) IsEmpty() bool {
66+
func (r *roundRobinStrategy) IsEmpty() bool {
6767
r.mutex.RLock()
6868
defer r.mutex.RUnlock()
6969

7070
return r.size == 0
7171
}
7272

73-
func (r *RoundRobinStrategy) GetNextConnection() *tarantool.Connection {
73+
func (r *roundRobinStrategy) GetNextConnection() *tarantool.Connection {
7474
r.mutex.RLock()
7575
defer r.mutex.RUnlock()
7676

@@ -80,7 +80,7 @@ func (r *RoundRobinStrategy) GetNextConnection() *tarantool.Connection {
8080
return r.conns[r.nextIndex()]
8181
}
8282

83-
func (r *RoundRobinStrategy) GetConnections() []*tarantool.Connection {
83+
func (r *roundRobinStrategy) GetConnections() []*tarantool.Connection {
8484
r.mutex.RLock()
8585
defer r.mutex.RUnlock()
8686

@@ -90,7 +90,7 @@ func (r *RoundRobinStrategy) GetConnections() []*tarantool.Connection {
9090
return ret
9191
}
9292

93-
func (r *RoundRobinStrategy) AddConn(addr string, conn *tarantool.Connection) {
93+
func (r *roundRobinStrategy) AddConn(addr string, conn *tarantool.Connection) {
9494
r.mutex.Lock()
9595
defer r.mutex.Unlock()
9696

@@ -103,7 +103,7 @@ func (r *RoundRobinStrategy) AddConn(addr string, conn *tarantool.Connection) {
103103
}
104104
}
105105

106-
func (r *RoundRobinStrategy) nextIndex() uint {
106+
func (r *roundRobinStrategy) nextIndex() uint {
107107
ret := r.current % r.size
108108
r.current++
109109
return ret

pool/round_robin_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package pool_test
1+
package pool
22

33
import (
44
"testing"
55

66
"github.com/tarantool/go-tarantool/v2"
7-
. "github.com/tarantool/go-tarantool/v2/pool"
87
)
98

109
const (
@@ -13,7 +12,7 @@ const (
1312
)
1413

1514
func TestRoundRobinAddDelete(t *testing.T) {
16-
rr := NewEmptyRoundRobin(10)
15+
rr := newRoundRobinStrategy(10)
1716

1817
addrs := []string{validAddr1, validAddr2}
1918
conns := []*tarantool.Connection{&tarantool.Connection{}, &tarantool.Connection{}}
@@ -33,7 +32,7 @@ func TestRoundRobinAddDelete(t *testing.T) {
3332
}
3433

3534
func TestRoundRobinAddDuplicateDelete(t *testing.T) {
36-
rr := NewEmptyRoundRobin(10)
35+
rr := newRoundRobinStrategy(10)
3736

3837
conn1 := &tarantool.Connection{}
3938
conn2 := &tarantool.Connection{}
@@ -53,7 +52,7 @@ func TestRoundRobinAddDuplicateDelete(t *testing.T) {
5352
}
5453

5554
func TestRoundRobinGetNextConnection(t *testing.T) {
56-
rr := NewEmptyRoundRobin(10)
55+
rr := newRoundRobinStrategy(10)
5756

5857
addrs := []string{validAddr1, validAddr2}
5958
conns := []*tarantool.Connection{&tarantool.Connection{}, &tarantool.Connection{}}
@@ -71,7 +70,7 @@ func TestRoundRobinGetNextConnection(t *testing.T) {
7170
}
7271

7372
func TestRoundRobinStrategy_GetConnections(t *testing.T) {
74-
rr := NewEmptyRoundRobin(10)
73+
rr := newRoundRobinStrategy(10)
7574

7675
addrs := []string{validAddr1, validAddr2}
7776
conns := []*tarantool.Connection{&tarantool.Connection{}, &tarantool.Connection{}}

0 commit comments

Comments
 (0)