@@ -15,7 +15,6 @@ import (
15
15
"github.com/ydb-platform/ydb-go-sdk/v3/internal/cluster/entry"
16
16
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
17
17
"github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
18
- "github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint/info"
19
18
"github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
20
19
"github.com/ydb-platform/ydb-go-sdk/v3/internal/repeater"
21
20
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
37
36
38
37
// ErrNilBalancerElement returned when requested on a nil Balancer element.
39
38
ErrNilBalancerElement = errors .New ("nil balancer element" )
39
+
40
40
// ErrUnknownBalancerElement returned when requested on a unknown Balancer element.
41
41
ErrUnknownBalancerElement = errors .New ("unknown balancer element" )
42
+
42
43
// ErrUnknownTypeOfBalancerElement returned when requested on a unknown types of Balancer element.
43
44
ErrUnknownTypeOfBalancerElement = errors .New ("unknown types of balancer element" )
44
45
)
@@ -210,7 +211,7 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
210
211
if err != nil {
211
212
onDone (nil , err )
212
213
} else {
213
- onDone (cc .Endpoint (), nil )
214
+ onDone (cc .Endpoint (). Copy () , nil )
214
215
}
215
216
}()
216
217
@@ -235,7 +236,7 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
235
236
236
237
// Insert inserts new connection into the cluster.
237
238
func (c * cluster ) Insert (ctx context.Context , e endpoint.Endpoint , opts ... crudOption ) (cc conn.Conn ) {
238
- onDone := trace .DriverOnClusterInsert (c .config .Trace (), & ctx , e )
239
+ onDone := trace .DriverOnClusterInsert (c .config .Trace (), & ctx , e . Copy () )
239
240
defer func () {
240
241
if cc != nil {
241
242
onDone (cc .GetState ())
@@ -261,16 +262,14 @@ func (c *cluster) Insert(ctx context.Context, e endpoint.Endpoint, opts ...crudO
261
262
panic ("ydb: can't insert already existing endpoint" )
262
263
}
263
264
264
- var wait chan struct {}
265
- defer func () {
266
- if wait != nil {
267
- close (wait )
268
- }
269
- }()
265
+ cc .Endpoint ().Touch ()
270
266
271
267
entry := entry.Entry {Conn : cc }
268
+
272
269
entry .InsertInto (c .balancer )
270
+
273
271
c .index [e .Address ()] = entry
272
+
274
273
if e .NodeID () > 0 {
275
274
c .endpoints [e .NodeID ()] = cc
276
275
}
@@ -280,7 +279,7 @@ func (c *cluster) Insert(ctx context.Context, e endpoint.Endpoint, opts ...crudO
280
279
281
280
// Update updates existing connection's runtime stats such that load factor and others.
282
281
func (c * cluster ) Update (ctx context.Context , e endpoint.Endpoint , opts ... crudOption ) (cc conn.Conn ) {
283
- onDone := trace .DriverOnClusterUpdate (c .config .Trace (), & ctx , e )
282
+ onDone := trace .DriverOnClusterUpdate (c .config .Trace (), & ctx , e . Copy () )
284
283
defer func () {
285
284
if cc != nil {
286
285
onDone (cc .GetState ())
@@ -307,6 +306,8 @@ func (c *cluster) Update(ctx context.Context, e endpoint.Endpoint, opts ...crudO
307
306
panic ("ydb: cluster entry with nil conn" )
308
307
}
309
308
309
+ entry .Conn .Endpoint ().Touch ()
310
+
310
311
delete (c .endpoints , e .NodeID ())
311
312
c .index [e .Address ()] = entry
312
313
@@ -316,15 +317,15 @@ func (c *cluster) Update(ctx context.Context, e endpoint.Endpoint, opts ...crudO
316
317
317
318
if entry .Handle != nil {
318
319
// entry.Handle may be nil when connection is being tracked.
319
- c .balancer .Update (entry .Handle , info .Info {} )
320
+ c .balancer .Update (entry .Handle , e .Info () )
320
321
}
321
322
322
323
return entry .Conn
323
324
}
324
325
325
326
// Remove removes and closes previously inserted connection.
326
327
func (c * cluster ) Remove (ctx context.Context , e endpoint.Endpoint , opts ... crudOption ) (cc conn.Conn ) {
327
- onDone := trace .DriverOnClusterRemove (c .config .Trace (), & ctx , e )
328
+ onDone := trace .DriverOnClusterRemove (c .config .Trace (), & ctx , e . Copy () )
328
329
defer func () {
329
330
if cc != nil {
330
331
onDone (cc .GetState ())
0 commit comments