This is an automated email from the ASF dual-hosted git repository.

ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new d8b296c932d IGNITE-27309 .NET: Improve tx logging (#7204)
d8b296c932d is described below

commit d8b296c932dfa42c9bebbee6d44e4eb228c93e8a
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Wed Dec 10 14:53:59 2025 +0200

    IGNITE-27309 .NET: Improve tx logging (#7204)
    
    Log all tx states with observableTs and id.
---
 .../Apache.Ignite.Tests/PartitionAwarenessTests.cs |  5 +++-
 .../dotnet/Apache.Ignite/Internal/LogMessages.cs   | 27 +++++++++++++++++++
 .../Internal/Transactions/LazyTransaction.cs       | 30 ++++++++++++++++++----
 .../Internal/Transactions/Transactions.cs          | 11 ++++++--
 4 files changed, 65 insertions(+), 8 deletions(-)

diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Tests/PartitionAwarenessTests.cs 
b/modules/platforms/dotnet/Apache.Ignite.Tests/PartitionAwarenessTests.cs
index 516016f2cd1..ae7d446220d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/PartitionAwarenessTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/PartitionAwarenessTests.cs
@@ -27,6 +27,7 @@ using Ignite.Table;
 using Ignite.Transactions;
 using Internal.Proto;
 using Internal.Transactions;
+using Microsoft.Extensions.Logging;
 using NUnit.Framework;
 
 /// <summary>
@@ -447,7 +448,9 @@ public class PartitionAwarenessTests
         node.ClearOps();
         node2?.ClearOps();
 
-        ITransaction? tx = withTx ? new LazyTransaction(default, 0) : null;
+        ITransaction? tx = withTx
+            ? new LazyTransaction(default, 0, 
TestUtils.GetConsoleLoggerFactory(LogLevel.None).CreateLogger<LazyTransaction>())
+            : null;
 
         await action(tx);
 
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/LogMessages.cs 
b/modules/platforms/dotnet/Apache.Ignite/Internal/LogMessages.cs
index 26aa892c349..d3ce076f73c 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/LogMessages.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/LogMessages.cs
@@ -21,6 +21,7 @@ using System;
 using System.Net;
 using System.Net.Security;
 using Ignite.Sql;
+using Ignite.Transactions;
 using Microsoft.Extensions.Logging;
 using Proto;
 
@@ -240,4 +241,30 @@ internal static partial class LogMessages
         EventId = 1032)]
     internal static partial void LogObservableTsUpdatedTrace(
         this ILogger logger, long prev, long current);
+
+    [LoggerMessage(
+        Message = "Lazy tx created [options={Options}, 
readTimestamp={ReadTimestamp}]",
+        Level = LogLevel.Trace,
+        EventId = 1033)]
+    internal static partial void LogLazyTxCreatedTrace(
+        this ILogger logger, TransactionOptions options, long readTimestamp);
+
+    [LoggerMessage(
+        Message = "Tx started [options={Options}, 
readTimestamp={ReadTimestamp}, txId={TxId}]",
+        Level = LogLevel.Trace,
+        EventId = 1034)]
+    internal static partial void LogTxStartedTrace(
+        this ILogger logger, TransactionOptions options, long readTimestamp, 
long txId);
+
+    [LoggerMessage(
+        Message = "Tx committed [txId={TxId}]",
+        Level = LogLevel.Trace,
+        EventId = 1035)]
+    internal static partial void LogTxCommitTrace(this ILogger logger, long 
txId);
+
+    [LoggerMessage(
+        Message = "Tx rolled back [txId={TxId}]",
+        Level = LogLevel.Trace,
+        EventId = 1036)]
+    internal static partial void LogTxRollbackTrace(this ILogger logger, long 
txId);
 }
diff --git 
a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/LazyTransaction.cs
 
b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/LazyTransaction.cs
index 70f801c5490..993d4ea569b 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/LazyTransaction.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/LazyTransaction.cs
@@ -22,6 +22,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using Common;
 using Ignite.Transactions;
+using Microsoft.Extensions.Logging;
 using Proto;
 using Tx;
 
@@ -48,6 +49,8 @@ internal sealed class LazyTransaction : ITransaction
 
     private readonly long _observableTimestamp;
 
+    private readonly ILogger _logger;
+
     private int _state = StateOpen;
 
     private volatile Task<Transaction>? _tx;
@@ -57,10 +60,14 @@ internal sealed class LazyTransaction : ITransaction
     /// </summary>
     /// <param name="options">Options.</param>
     /// <param name="observableTimestamp">Observable timestamp.</param>
-    public LazyTransaction(TransactionOptions options, long 
observableTimestamp)
+    /// <param name="logger">Logger.</param>
+    public LazyTransaction(TransactionOptions options, long 
observableTimestamp, ILogger logger)
     {
         _options = options;
         _observableTimestamp = observableTimestamp;
+        _logger = logger;
+
+        _logger.LogLazyTxCreatedTrace(options, observableTimestamp);
     }
 
     /// <inheritdoc/>
@@ -89,7 +96,12 @@ internal sealed class LazyTransaction : ITransaction
     {
         if (TrySetState(StateCommitted))
         {
-            await DoOpAsync(_tx, ClientOp.TxCommit).ConfigureAwait(false);
+            var tx = await DoOpAsync(_tx, 
ClientOp.TxCommit).ConfigureAwait(false);
+
+            if (tx != null)
+            {
+                _logger.LogTxCommitTrace(tx.Id);
+            }
         }
     }
 
@@ -98,7 +110,12 @@ internal sealed class LazyTransaction : ITransaction
     {
         if (TrySetState(StateRolledBack))
         {
-            await DoOpAsync(_tx, ClientOp.TxRollback).ConfigureAwait(false);
+            var tx = await DoOpAsync(_tx, 
ClientOp.TxRollback).ConfigureAwait(false);
+
+            if (tx != null)
+            {
+                _logger.LogTxRollbackTrace(tx.Id);
+            }
         }
     }
 
@@ -159,12 +176,12 @@ internal sealed class LazyTransaction : ITransaction
     /// <returns>True when the underlying lazy transaction is started, false 
otherwise.</returns>
     internal static bool IsStarted(ITransaction? tx) => Get(tx)?._tx != null;
 
-    private static async Task DoOpAsync(Task<Transaction>? txTask, ClientOp op)
+    private static async Task<Transaction?> DoOpAsync(Task<Transaction>? 
txTask, ClientOp op)
     {
         if (txTask == null)
         {
             // No operations were performed, nothing to commit or roll back.
-            return;
+            return null;
         }
 
         var tx = await txTask.ConfigureAwait(false);
@@ -172,6 +189,8 @@ internal sealed class LazyTransaction : ITransaction
         using var writer = ProtoCommon.GetMessageWriter();
         writer.MessageWriter.Write(tx.Id);
         using var buffer = await tx.Socket.DoOutInOpAsync(op, 
writer).ConfigureAwait(false);
+
+        return tx;
     }
 
     private Task<Transaction> EnsureStartedAsync(ClientFailoverSocket socket, 
PreferredNode preferredNode)
@@ -204,6 +223,7 @@ internal sealed class LazyTransaction : ITransaction
         using (resBuf)
         {
             var txId = resBuf.GetReader().ReadInt64();
+            _logger.LogTxStartedTrace(_options, _observableTimestamp, txId);
 
             return new Transaction(txId, socket, failoverSocket);
         }
diff --git 
a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs 
b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
index f182e5cf3ad..431bde44f0a 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
@@ -21,6 +21,7 @@ using System.Diagnostics.CodeAnalysis;
 using System.Threading.Tasks;
 using Common;
 using Ignite.Transactions;
+using Microsoft.Extensions.Logging;
 
 /// <summary>
 /// Transactions API.
@@ -29,16 +30,22 @@ internal class Transactions : ITransactions
 {
     private readonly ClientFailoverSocket _socket;
 
+    private readonly ILogger<Transactions> _logger;
+
     /// <summary>
     /// Initializes a new instance of the <see cref="Transactions"/> class.
     /// </summary>
     /// <param name="socket">Socket.</param>
-    public Transactions(ClientFailoverSocket socket) => _socket = socket;
+    public Transactions(ClientFailoverSocket socket)
+    {
+        _socket = socket;
+        _logger = 
_socket.Configuration.Configuration.LoggerFactory.CreateLogger<Transactions>();
+    }
 
     /// <inheritdoc/>
     [SuppressMessage("Reliability", "CA2000:Dispose objects before losing 
scope", Justification = "Tx is returned.")]
     public ValueTask<ITransaction> BeginAsync(TransactionOptions options) =>
-        ValueTask.FromResult<ITransaction>(new LazyTransaction(options, 
_socket.ObservableTimestamp));
+        ValueTask.FromResult<ITransaction>(new LazyTransaction(options, 
_socket.ObservableTimestamp, _logger));
 
     /// <inheritdoc />
     public override string ToString() => 
IgniteToStringBuilder.Build(GetType());

Reply via email to