@@ -236,13 +236,12 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
236236
237237// Insert inserts new connection into the cluster.
238238func (c * cluster ) Insert (ctx context.Context , e endpoint.Endpoint , opts ... crudOption ) (cc conn.Conn ) {
239- onDone := trace .DriverOnClusterInsert (c .config .Trace (), & ctx , e .Copy ())
239+ var (
240+ onDone = trace .DriverOnClusterInsert (c .config .Trace (), & ctx , e .Copy ())
241+ inserted = false
242+ )
240243 defer func () {
241- if cc != nil {
242- onDone (cc .GetState ())
243- } else {
244- onDone (conn .Unknown )
245- }
244+ onDone (inserted , cc .GetState ())
246245 }()
247246
248247 options := parseOptions (opts ... )
@@ -266,7 +265,7 @@ func (c *cluster) Insert(ctx context.Context, e endpoint.Endpoint, opts ...crudO
266265
267266 entry := entry.Entry {Conn : cc }
268267
269- entry .InsertInto (c .balancer )
268+ inserted = entry .InsertInto (c .balancer )
270269
271270 c .index [e .Address ()] = entry
272271
@@ -325,13 +324,12 @@ func (c *cluster) Update(ctx context.Context, e endpoint.Endpoint, opts ...crudO
325324
326325// Remove removes and closes previously inserted connection.
327326func (c * cluster ) Remove (ctx context.Context , e endpoint.Endpoint , opts ... crudOption ) (cc conn.Conn ) {
328- onDone := trace .DriverOnClusterRemove (c .config .Trace (), & ctx , e .Copy ())
327+ var (
328+ onDone = trace .DriverOnClusterRemove (c .config .Trace (), & ctx , e .Copy ())
329+ removed = false
330+ )
329331 defer func () {
330- if cc != nil {
331- onDone (cc .GetState ())
332- } else {
333- onDone (conn .Unknown )
334- }
332+ onDone (cc .GetState (), removed )
335333 }()
336334
337335 options := parseOptions (opts ... )
@@ -352,7 +350,8 @@ func (c *cluster) Remove(ctx context.Context, e endpoint.Endpoint, opts ...crudO
352350 panic ("ydb: can't remove not-existing endpoint" )
353351 }
354352
355- entry .RemoveFrom (c .balancer )
353+ removed = entry .RemoveFrom (c .balancer )
354+
356355 delete (c .index , e .Address ())
357356 delete (c .endpoints , e .NodeID ())
358357
0 commit comments