From 16348e61db40b0652788217cad3c1b4f2312737b Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 14 Mar 2025 18:40:38 +0800 Subject: [PATCH] sqldb: add trace logs in `ExecuteSQLTransactionWithRetry` --- sqldb/interfaces.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sqldb/interfaces.go b/sqldb/interfaces.go index 3197d7f09..6f3278c78 100644 --- a/sqldb/interfaces.go +++ b/sqldb/interfaces.go @@ -247,6 +247,9 @@ func ExecuteSQLTransactionWithRetry(ctx context.Context, makeTx MakeTx, tx, err := makeTx() if err != nil { dbErr := MapSQLError(err) + log.Tracef("Failed to makeTx: err=%v, dbErr=%v", err, + dbErr) + if IsSerializationError(dbErr) { // Nothing to roll back here, since we haven't // even get a transaction yet. We'll just wait @@ -266,6 +269,8 @@ func ExecuteSQLTransactionWithRetry(ctx context.Context, makeTx MakeTx, }() if bodyErr := txBody(tx); bodyErr != nil { + log.Tracef("Error in txBody: %v", bodyErr) + // Roll back the transaction, then attempt a random // backoff and try again if the error was a // serialization error. @@ -285,6 +290,8 @@ func ExecuteSQLTransactionWithRetry(ctx context.Context, makeTx MakeTx, // Commit transaction. if commitErr := tx.Commit(); commitErr != nil { + log.Tracef("Failed to commit tx: %v", commitErr) + // Roll back the transaction, then attempt a random // backoff and try again if the error was a // serialization error.