@@ -15,7 +15,6 @@ import (
1515 "github.com/ydb-platform/ydb-go-sdk/v3/internal/cluster/entry"
1616 "github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
1717 "github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
18- "github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint/info"
1918 "github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
2019 "github.com/ydb-platform/ydb-go-sdk/v3/internal/repeater"
2120 "github.com/ydb-platform/ydb-go-sdk/v3/trace"
3736
3837 // ErrNilBalancerElement returned when requested on a nil Balancer element.
3938 ErrNilBalancerElement = errors .New ("nil balancer element" )
39+
4040 // ErrUnknownBalancerElement returned when requested on a unknown Balancer element.
4141 ErrUnknownBalancerElement = errors .New ("unknown balancer element" )
42+
4243 // ErrUnknownTypeOfBalancerElement returned when requested on a unknown types of Balancer element.
4344 ErrUnknownTypeOfBalancerElement = errors .New ("unknown types of balancer element" )
4445)
@@ -210,7 +211,7 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
210211 if err != nil {
211212 onDone (nil , err )
212213 } else {
213- onDone (cc .Endpoint (), nil )
214+ onDone (cc .Endpoint (). Copy () , nil )
214215 }
215216 }()
216217
@@ -235,7 +236,7 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
235236
236237// Insert inserts new connection into the cluster.
237238func (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 () )
239240 defer func () {
240241 if cc != nil {
241242 onDone (cc .GetState ())
@@ -261,16 +262,14 @@ func (c *cluster) Insert(ctx context.Context, e endpoint.Endpoint, opts ...crudO
261262 panic ("ydb: can't insert already existing endpoint" )
262263 }
263264
264- var wait chan struct {}
265- defer func () {
266- if wait != nil {
267- close (wait )
268- }
269- }()
265+ cc .Endpoint ().Touch ()
270266
271267 entry := entry.Entry {Conn : cc }
268+
272269 entry .InsertInto (c .balancer )
270+
273271 c .index [e .Address ()] = entry
272+
274273 if e .NodeID () > 0 {
275274 c .endpoints [e .NodeID ()] = cc
276275 }
@@ -280,7 +279,7 @@ func (c *cluster) Insert(ctx context.Context, e endpoint.Endpoint, opts ...crudO
280279
281280// Update updates existing connection's runtime stats such that load factor and others.
282281func (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 () )
284283 defer func () {
285284 if cc != nil {
286285 onDone (cc .GetState ())
@@ -307,6 +306,8 @@ func (c *cluster) Update(ctx context.Context, e endpoint.Endpoint, opts ...crudO
307306 panic ("ydb: cluster entry with nil conn" )
308307 }
309308
309+ entry .Conn .Endpoint ().Touch ()
310+
310311 delete (c .endpoints , e .NodeID ())
311312 c .index [e .Address ()] = entry
312313
@@ -316,15 +317,15 @@ func (c *cluster) Update(ctx context.Context, e endpoint.Endpoint, opts ...crudO
316317
317318 if entry .Handle != nil {
318319 // 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 () )
320321 }
321322
322323 return entry .Conn
323324}
324325
325326// Remove removes and closes previously inserted connection.
326327func (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 () )
328329 defer func () {
329330 if cc != nil {
330331 onDone (cc .GetState ())
0 commit comments