Skip to content

Commit 38cd482

Browse files
committed
fix
1 parent 1c42b47 commit 38cd482

File tree

7 files changed

+512
-99
lines changed

7 files changed

+512
-99
lines changed

internal/pool/pool.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,26 @@ func (p *Pool[PT, T]) changeState(changeState func() Stats) {
380380
}
381381
}
382382

383+
func (p *Pool[PT, T]) checkItemAndError(item PT, err error) error {
384+
if !item.IsAlive() {
385+
return errItemIsNotAlive
386+
}
387+
388+
if err == nil {
389+
return nil
390+
}
391+
392+
if p.config.mustDeleteItemFunc(item, err) {
393+
return err
394+
}
395+
396+
if !xerrors.IsValid(err, item) {
397+
return err
398+
}
399+
400+
return nil
401+
}
402+
383403
func (p *Pool[PT, T]) try(ctx context.Context, f func(ctx context.Context, item PT) error) (finalErr error) {
384404
if onTry := p.config.trace.OnTry; onTry != nil {
385405
onDone := onTry(&ctx,
@@ -417,7 +437,7 @@ func (p *Pool[PT, T]) try(ctx context.Context, f func(ctx context.Context, item
417437
}
418438

419439
defer func() {
420-
if !item.IsAlive() || (finalErr != nil && p.config.mustDeleteItemFunc(item, finalErr)) {
440+
if err := p.checkItemAndError(item, finalErr); err != nil {
421441
p.closeItem(ctx, item,
422442
closeItemWithLock(),
423443
closeItemNotifyStats(),

internal/query/transaction.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,13 @@ func commitTx(ctx context.Context, client Ydb_Query_V1.QueryServiceClient, sessi
322322
}
323323

324324
func (tx *Transaction) CommitTx(ctx context.Context) (finalErr error) {
325+
onDone := trace.QueryOnTxCommit(tx.s.trace, &ctx,
326+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Transaction).CommitTx"), tx.s, tx)
325327
defer func() {
326328
if finalErr != nil {
327329
applyStatusByError(tx.s, finalErr)
328330
}
331+
onDone(finalErr)
329332
}()
330333

331334
if tx.ID() == baseTx.LazyTxID {
@@ -367,12 +370,6 @@ func rollback(ctx context.Context, client Ydb_Query_V1.QueryServiceClient, sessi
367370
}
368371

369372
func (tx *Transaction) Rollback(ctx context.Context) (finalErr error) {
370-
defer func() {
371-
if finalErr != nil {
372-
applyStatusByError(tx.s, finalErr)
373-
}
374-
}()
375-
376373
if tx.ID() == baseTx.LazyTxID {
377374
// https://github.com/ydb-platform/ydb-go-sdk/issues/1456
378375
return tx.s.Close(ctx)
@@ -382,6 +379,15 @@ func (tx *Transaction) Rollback(ctx context.Context) (finalErr error) {
382379
return nil
383380
}
384381

382+
onDone := trace.QueryOnTxRollback(tx.s.trace, &ctx,
383+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.(*Transaction).Rollback"), tx.s, tx)
384+
defer func() {
385+
if finalErr != nil {
386+
applyStatusByError(tx.s, finalErr)
387+
}
388+
onDone(finalErr)
389+
}()
390+
385391
tx.completed = true
386392

387393
tx.notifyOnCompleted(ErrTransactionRollingBack)

internal/table/transaction.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,21 @@ func (tx *transaction) CommitTx(
192192

193193
// Rollback performs a rollback of the specified active transaction.
194194
func (tx *transaction) Rollback(ctx context.Context) (err error) {
195-
onDone := trace.TableOnTxRollback(
196-
tx.s.config.Trace(), &ctx,
197-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/table.(*transaction).Rollback"),
198-
tx.s, tx,
199-
)
200-
defer func() {
201-
onDone(err)
202-
}()
203-
204195
switch tx.state.Load() {
205196
case txStateCommitted:
206197
return nil // nop for committed tx
207198
case txStateRollbacked:
208199
return xerrors.WithStackTrace(errTxRollbackedEarly)
209200
default:
201+
onDone := trace.TableOnTxRollback(
202+
tx.s.config.Trace(), &ctx,
203+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/table.(*transaction).Rollback"),
204+
tx.s, tx,
205+
)
206+
defer func() {
207+
onDone(err)
208+
}()
209+
210210
_, err = tx.s.client.RollbackTransaction(ctx,
211211
&Ydb_Table.RollbackTransactionRequest{
212212
SessionId: tx.s.id,

tests/integration/database_sql_retryable_error_test.go

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)