Skip to content

Commit 9463db2

Browse files
author
maksim.konovalov
committed
pool: add Instance info to connection ConnectionInfo
The Instance info has been added to ConnectionInfo, 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 9463db2

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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 Instance info has been added to ConnectionInfo for GetInfo response (#429).
1415

1516
### Changed
1617

pool/connection_pool.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ ConnectionInfo structure for information about connection statuses:
9393
type ConnectionInfo struct {
9494
ConnectedNow bool
9595
ConnRole Role
96+
Instance Instance
9697
}
9798

9899
/*
@@ -393,12 +394,26 @@ func (p *ConnectionPool) GetInfo() map[string]ConnectionInfo {
393394
return info
394395
}
395396

396-
for name := range p.ends {
397+
for name, end := range p.ends {
397398
conn, role := p.getConnectionFromPool(name)
398399
if conn != nil {
399-
info[name] = ConnectionInfo{ConnectedNow: conn.ConnectedNow(), ConnRole: role}
400+
info[name] = ConnectionInfo{
401+
ConnectedNow: conn.ConnectedNow(),
402+
ConnRole: role,
403+
Instance: Instance{
404+
Name: name,
405+
Dialer: end.dialer,
406+
Opts: end.opts,
407+
}}
400408
} else {
401-
info[name] = ConnectionInfo{ConnectedNow: false, ConnRole: UnknownRole}
409+
info[name] = ConnectionInfo{
410+
ConnectedNow: false,
411+
ConnRole: UnknownRole,
412+
Instance: Instance{
413+
Name: name,
414+
Dialer: end.dialer,
415+
Opts: end.opts,
416+
}}
402417
}
403418
}
404419

pool/connection_pool_test.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,15 +1156,17 @@ func TestConnectionHandlerOpenError(t *testing.T) {
11561156
}
11571157
ctx, cancel := test_helpers.GetPoolConnectContext()
11581158
defer cancel()
1159-
connPool, err := pool.ConnectWithOpts(ctx, makeInstances(poolServers, connOpts), poolOpts)
1159+
1160+
insts := makeInstances(poolServers, connOpts)
1161+
connPool, err := pool.ConnectWithOpts(ctx, insts, poolOpts)
11601162
if err == nil {
11611163
defer connPool.Close()
11621164
}
11631165
require.NoError(t, err, "failed to connect")
11641166
require.NotNil(t, connPool, "pool expected")
11651167
require.Equal(t, map[string]pool.ConnectionInfo{
1166-
servers[0]: pool.ConnectionInfo{ConnectedNow: false, ConnRole: pool.UnknownRole},
1167-
servers[1]: pool.ConnectionInfo{ConnectedNow: false, ConnRole: pool.UnknownRole},
1168+
servers[0]: pool.ConnectionInfo{ConnectedNow: false, ConnRole: pool.UnknownRole, Instance: insts[0]},
1169+
servers[1]: pool.ConnectionInfo{ConnectedNow: false, ConnRole: pool.UnknownRole, Instance: insts[1]},
11681170
}, connPool.GetInfo())
11691171
connPool.Close()
11701172

@@ -3495,6 +3497,39 @@ func runTestMain(m *testing.M) int {
34953497
return m.Run()
34963498
}
34973499

3500+
func TestConnectionPool_GetInfo(t *testing.T) {
3501+
t.Run("equal instance info", func(t *testing.T) {
3502+
var tCases [][]pool.Instance
3503+
3504+
tCases = append(tCases, makeInstances([]string{servers[0], servers[1]}, connOpts))
3505+
tCases = append(tCases, makeInstances([]string{
3506+
servers[0],
3507+
servers[1],
3508+
servers[3]},
3509+
connOpts))
3510+
tCases = append(tCases, makeInstances([]string{servers[0]}, connOpts))
3511+
3512+
for _, tc := range tCases {
3513+
ctx, cancel := test_helpers.GetPoolConnectContext()
3514+
connPool, err := pool.Connect(ctx, tc)
3515+
cancel()
3516+
require.Nilf(t, err, "failed to connect")
3517+
require.NotNilf(t, connPool, "conn is nil after Connect")
3518+
3519+
info := connPool.GetInfo()
3520+
3521+
var infoInstances []pool.Instance
3522+
3523+
for _, infoInst := range info {
3524+
infoInstances = append(infoInstances, infoInst.Instance)
3525+
}
3526+
3527+
require.ElementsMatch(t, tc, infoInstances)
3528+
connPool.Close()
3529+
}
3530+
})
3531+
}
3532+
34983533
func TestMain(m *testing.M) {
34993534
code := runTestMain(m)
35003535
os.Exit(code)

0 commit comments

Comments
 (0)