Skip to content

Commit bb0aea7

Browse files
author
maksim.konovalov
committed
pool: add GetInstances method, that returns current instances connections state
The GetConnections method has been added, which is necessary to monitor the current state of the pool. This should help implement dynamic tracking of tarantool topology changes.
1 parent d8e2284 commit bb0aea7

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1111
### Added
1212

1313
- Extend box with replication information (#427).
14+
- The GetConnections method has been added,
15+
which is necessary to monitor the current state of the pool (#428).
1416

1517
### Changed
1618

pool/connection_pool.go

+18
Original file line numberDiff line numberDiff line change
@@ -1506,3 +1506,21 @@ func isFeatureInSlice(expected iproto.Feature, actualSlice []iproto.Feature) boo
15061506
}
15071507
return false
15081508
}
1509+
1510+
// GetInstances retrieves a slice of Instance objects representing the connections in the pool.
1511+
func (p *ConnectionPool) GetInstances() []Instance {
1512+
p.endsMutex.Lock()
1513+
defer p.endsMutex.Unlock()
1514+
1515+
res := make([]Instance, 0, len(p.ends))
1516+
1517+
for _, end := range p.ends {
1518+
res = append(res, Instance{
1519+
Name: end.name,
1520+
Dialer: end.dialer,
1521+
Opts: end.opts,
1522+
})
1523+
}
1524+
1525+
return res
1526+
}

pool/connection_pool_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -3449,6 +3449,27 @@ func TestWatcher_Unregister_concurrent(t *testing.T) {
34493449
wg.Wait()
34503450
}
34513451

3452+
func TestConnectionPool_GetInstances(t *testing.T) {
3453+
var tCases [][]pool.Instance
3454+
3455+
tCases = append(tCases, makeInstances([]string{servers[0], servers[1]}, connOpts))
3456+
tCases = append(tCases, makeInstances([]string{servers[0], servers[1], servers[3]}, connOpts))
3457+
tCases = append(tCases, makeInstances([]string{servers[0]}, connOpts))
3458+
3459+
for _, tc := range tCases {
3460+
ctx, cancel := test_helpers.GetPoolConnectContext()
3461+
connPool, err := pool.Connect(ctx, tc)
3462+
cancel()
3463+
require.Nilf(t, err, "failed to connect")
3464+
require.NotNilf(t, connPool, "conn is nil after Connect")
3465+
3466+
poolInstns := connPool.GetInstances()
3467+
require.ElementsMatch(t, tc, poolInstns)
3468+
connPool.Close()
3469+
}
3470+
3471+
}
3472+
34523473
// runTestMain is a body of TestMain function
34533474
// (see https://pkg.go.dev/testing#hdr-Main).
34543475
// Using defer + os.Exit is not works so TestMain body

0 commit comments

Comments
 (0)