Skip to content

Commit 056c274

Browse files
author
Divjot Arora
committed
remove functionality to update topology from application connection handshakes
1 parent 67f4bac commit 056c274

File tree

4 files changed

+15
-31
lines changed

4 files changed

+15
-31
lines changed

x/mongo/driver/topology/connection.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ func (c *connection) connect(ctx context.Context) {
156156
return
157157
}
158158

159-
if c.config.descCallback != nil {
160-
c.config.descCallback(c.desc)
161-
}
162159
if len(c.desc.Compression) > 0 {
163160
clientMethodLoop:
164161
for _, method := range c.config.compressors {

x/mongo/driver/topology/connection_options.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"go.mongodb.org/mongo-driver/event"
1010
"go.mongodb.org/mongo-driver/x/mongo/driver"
11-
"go.mongodb.org/mongo-driver/x/mongo/driver/description"
1211
"go.mongodb.org/mongo-driver/x/mongo/driver/ocsp"
1312
)
1413

@@ -50,7 +49,6 @@ type connectionConfig struct {
5049
compressors []string
5150
zlibLevel *int
5251
zstdLevel *int
53-
descCallback func(description.Server)
5452
ocspCache ocsp.Cache
5553
disableOCSPEndpointCheck bool
5654
}
@@ -76,13 +74,6 @@ func newConnectionConfig(opts ...ConnectionOption) (*connectionConfig, error) {
7674
return cfg, nil
7775
}
7876

79-
func withServerDescriptionCallback(callback func(description.Server), opts ...ConnectionOption) []ConnectionOption {
80-
return append(opts, ConnectionOption(func(c *connectionConfig) error {
81-
c.descCallback = callback
82-
return nil
83-
}))
84-
}
85-
8677
// ConnectionOption is used to configure a connection.
8778
type ConnectionOption func(*connectionConfig) error
8879

x/mongo/driver/topology/connection_test.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,26 @@ func TestConnection(t *testing.T) {
103103
})
104104
t.Run("calls description callback", func(t *testing.T) {
105105
want := description.Server{Addr: address.Address("1.2.3.4:56789")}
106-
var got description.Server
107106
conn, err := newConnection(address.Address(""),
108-
withServerDescriptionCallback(func(desc description.Server) { got = desc },
109-
WithHandshaker(func(Handshaker) Handshaker {
110-
return &testHandshaker{
111-
getDescription: func(context.Context, address.Address, driver.Connection) (description.Server, error) {
112-
return want, nil
113-
},
114-
}
115-
}),
116-
WithDialer(func(Dialer) Dialer {
117-
return DialerFunc(func(context.Context, string, string) (net.Conn, error) {
118-
return &net.TCPConn{}, nil
119-
})
120-
}),
121-
)...,
107+
WithHandshaker(func(Handshaker) Handshaker {
108+
return &testHandshaker{
109+
getDescription: func(context.Context, address.Address, driver.Connection) (description.Server, error) {
110+
return want, nil
111+
},
112+
}
113+
}),
114+
WithDialer(func(Dialer) Dialer {
115+
return DialerFunc(func(context.Context, string, string) (net.Conn, error) {
116+
return &net.TCPConn{}, nil
117+
})
118+
}),
122119
)
123120
noerr(t, err)
124121
conn.connect(context.Background())
125122
err = conn.wait()
126123
noerr(t, err)
127-
if !cmp.Equal(got, want) {
128-
t.Errorf("Server descriptions do not match. got %v; want %v", got, want)
124+
if !cmp.Equal(conn.desc, want) {
125+
t.Errorf("Server descriptions do not match. got %v; want %v", conn.desc, want)
129126
}
130127
connState := atomic.LoadInt32(&conn.connected)
131128
assert.Equal(t, connected, connState, "expected connection state %v, got %v", connected, connState)

x/mongo/driver/topology/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ func NewServer(addr address.Address, opts ...ServerOption) (*Server, error) {
167167
}
168168
s.rttMonitor = newRttMonitor(rttCfg)
169169

170-
callback := func(desc description.Server) { s.updateDescription(desc) }
171170
pc := poolConfig{
172171
Address: addr,
173172
MinPoolSize: cfg.minConns,
@@ -176,7 +175,7 @@ func NewServer(addr address.Address, opts ...ServerOption) (*Server, error) {
176175
PoolMonitor: cfg.poolMonitor,
177176
}
178177

179-
s.pool, err = newPool(pc, withServerDescriptionCallback(callback, cfg.connectionOpts...)...)
178+
s.pool, err = newPool(pc, cfg.connectionOpts...)
180179
if err != nil {
181180
return nil, err
182181
}

0 commit comments

Comments
 (0)