Skip to content

Commit

Permalink
pool: add Instance info to connection ConnectionInfo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maksim.konovalov committed Feb 4, 2025
1 parent d8e2284 commit 453357f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
### Added

- Extend box with replication information (#427).
- The Instance info has been added to ConnectionInfo for GetInfo response (#429).

### Changed

Expand Down
21 changes: 18 additions & 3 deletions pool/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ConnectionInfo structure for information about connection statuses:
type ConnectionInfo struct {
ConnectedNow bool
ConnRole Role
Instance Instance
}

/*
Expand Down Expand Up @@ -393,12 +394,26 @@ func (p *ConnectionPool) GetInfo() map[string]ConnectionInfo {
return info
}

for name := range p.ends {
for name, end := range p.ends {
conn, role := p.getConnectionFromPool(name)
if conn != nil {
info[name] = ConnectionInfo{ConnectedNow: conn.ConnectedNow(), ConnRole: role}
info[name] = ConnectionInfo{
ConnectedNow: conn.ConnectedNow(),
ConnRole: role,
Instance: Instance{
Name: name,
Dialer: end.dialer,
Opts: end.opts,
}}
} else {
info[name] = ConnectionInfo{ConnectedNow: false, ConnRole: UnknownRole}
info[name] = ConnectionInfo{
ConnectedNow: false,
ConnRole: UnknownRole,
Instance: Instance{
Name: name,
Dialer: end.dialer,
Opts: end.opts,
}}
}
}

Expand Down
33 changes: 33 additions & 0 deletions pool/connection_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3495,6 +3495,39 @@ func runTestMain(m *testing.M) int {
return m.Run()
}

func TestConnectionPool_GetInfo(t *testing.T) {
t.Run("equal instance info", func(t *testing.T) {
var tCases [][]pool.Instance

tCases = append(tCases, makeInstances([]string{servers[0], servers[1]}, connOpts))
tCases = append(tCases, makeInstances([]string{
servers[0],
servers[1],
servers[3]},
connOpts))
tCases = append(tCases, makeInstances([]string{servers[0]}, connOpts))

for _, tc := range tCases {
ctx, cancel := test_helpers.GetPoolConnectContext()
connPool, err := pool.Connect(ctx, tc)
cancel()
require.Nilf(t, err, "failed to connect")
require.NotNilf(t, connPool, "conn is nil after Connect")

info := connPool.GetInfo()

var infoInstances []pool.Instance

for _, infoInst := range info {
infoInstances = append(infoInstances, infoInst.Instance)
}

require.ElementsMatch(t, tc, infoInstances)
connPool.Close()
}
})
}

func TestMain(m *testing.M) {
code := runTestMain(m)
os.Exit(code)
Expand Down

0 comments on commit 453357f

Please sign in to comment.