1- using Ydb . Table ;
1+ using Microsoft . Extensions . Logging ;
2+ using Ydb . Table ;
23
34namespace Ydb . Sdk . Services . Table ;
45
@@ -11,15 +12,36 @@ internal Transaction(string txId)
1112
1213 public string TxId { get ; }
1314
14- internal static Transaction ? FromProto ( TransactionMeta proto )
15+ internal int ? TxNum { get ; private set ; }
16+
17+ internal static Transaction ? FromProto ( TransactionMeta proto , ILogger ? logger = null )
1518 {
1619 if ( proto . Id . Length == 0 )
1720 {
1821 return null ;
1922 }
2023
21- return new Transaction (
24+ var tx = new Transaction (
2225 txId : proto . Id ) ;
26+ if ( ! string . IsNullOrEmpty ( proto . Id ) )
27+ {
28+ tx . TxNum = GetTxCounter ( ) ;
29+ logger . LogTrace ( $ "Received tx #{ tx . TxNum } ") ;
30+ }
31+
32+ return tx ;
33+ }
34+
35+ private static readonly object TxCounterLock = new ( ) ;
36+ private static int _txCounter ;
37+
38+ private static int GetTxCounter ( )
39+ {
40+ lock ( TxCounterLock )
41+ {
42+ _txCounter ++ ;
43+ return _txCounter ;
44+ }
2345 }
2446}
2547
@@ -34,9 +56,12 @@ public class TxControl
3456{
3557 private readonly TransactionControl _proto ;
3658
37- private TxControl ( TransactionControl proto )
59+ private readonly int ? _txNum ;
60+
61+ private TxControl ( TransactionControl proto , int ? txNum = null )
3862 {
3963 _proto = proto ;
64+ _txNum = txNum ;
4065 }
4166
4267 public static TxControl BeginSerializableRW ( )
@@ -80,7 +105,7 @@ public static TxControl Tx(Transaction tx)
80105 return new TxControl ( new TransactionControl
81106 {
82107 TxId = tx . TxId
83- } ) ;
108+ } , tx . TxNum ) ;
84109 }
85110
86111 public TxControl Commit ( )
@@ -89,8 +114,13 @@ public TxControl Commit()
89114 return this ;
90115 }
91116
92- internal TransactionControl ToProto ( )
117+ internal TransactionControl ToProto ( ILogger ? logger = null )
93118 {
119+ if ( _txNum != null )
120+ {
121+ logger . LogTrace ( $ "Using tx #{ _txNum } ") ;
122+ }
123+
94124 return _proto . Clone ( ) ;
95125 }
96126}
0 commit comments