38
38
)
39
39
40
40
var (
41
- tikvTxnCmdCountWithGet = metrics .TiKVTxnCmdCounter .WithLabelValues ("get" )
42
- tikvTxnCmdHistogramWithGet = metrics .TiKVTxnCmdHistogram .WithLabelValues ("get" )
43
- tikvTxnCmdCountWithSeek = metrics .TiKVTxnCmdCounter .WithLabelValues ("seek" )
44
- tikvTxnCmdHistogramWithSeek = metrics .TiKVTxnCmdHistogram .WithLabelValues ("seek" )
45
- tikvTxnCmdCountWithSeekReverse = metrics .TiKVTxnCmdCounter .WithLabelValues ("seek_reverse" )
46
- tikvTxnCmdHistogramWithSeekReverse = metrics .TiKVTxnCmdHistogram .WithLabelValues ("seek_reverse" )
47
- tikvTxnCmdCountWithDelete = metrics .TiKVTxnCmdCounter .WithLabelValues ("delete" )
48
- tikvTxnCmdCountWithSet = metrics .TiKVTxnCmdCounter .WithLabelValues ("set" )
49
- tikvTxnCmdCountWithCommit = metrics .TiKVTxnCmdCounter .WithLabelValues ("commit" )
50
- tikvTxnCmdHistogramWithCommit = metrics .TiKVTxnCmdHistogram .WithLabelValues ("commit" )
51
- tikvTxnCmdCountWithRollback = metrics .TiKVTxnCmdCounter .WithLabelValues ("rollback" )
52
- tikvTxnCmdHistogramWithLockKeys = metrics .TiKVTxnCmdCounter .WithLabelValues ("lock_keys" )
41
+ tikvTxnCmdHistogramWithCommit = metrics .TiKVTxnCmdHistogram .WithLabelValues (metrics .LblCommit )
42
+ tikvTxnCmdHistogramWithRollback = metrics .TiKVTxnCmdHistogram .WithLabelValues (metrics .LblRollback )
53
43
)
54
44
55
45
// tikvTxn implements kv.Transaction.
@@ -129,10 +119,6 @@ func (txn *tikvTxn) Reset() {
129
119
130
120
// Get implements transaction interface.
131
121
func (txn * tikvTxn ) Get (ctx context.Context , k kv.Key ) ([]byte , error ) {
132
- tikvTxnCmdCountWithGet .Inc ()
133
- start := time .Now ()
134
- defer func () { tikvTxnCmdHistogramWithGet .Observe (time .Since (start ).Seconds ()) }()
135
-
136
122
ret , err := txn .us .Get (ctx , k )
137
123
if kv .IsErrNotFound (err ) {
138
124
return nil , err
@@ -199,27 +185,15 @@ func (txn *tikvTxn) String() string {
199
185
}
200
186
201
187
func (txn * tikvTxn ) Iter (k kv.Key , upperBound kv.Key ) (kv.Iterator , error ) {
202
- tikvTxnCmdCountWithSeek .Inc ()
203
- start := time .Now ()
204
- defer func () { tikvTxnCmdHistogramWithSeek .Observe (time .Since (start ).Seconds ()) }()
205
-
206
188
return txn .us .Iter (k , upperBound )
207
189
}
208
190
209
191
// IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.
210
192
func (txn * tikvTxn ) IterReverse (k kv.Key ) (kv.Iterator , error ) {
211
- tikvTxnCmdCountWithSeekReverse .Inc ()
212
- start := time .Now ()
213
- defer func () {
214
- tikvTxnCmdHistogramWithSeekReverse .Observe (time .Since (start ).Seconds ())
215
- }()
216
-
217
193
return txn .us .IterReverse (k )
218
194
}
219
195
220
196
func (txn * tikvTxn ) Delete (k kv.Key ) error {
221
- tikvTxnCmdCountWithDelete .Inc ()
222
-
223
197
txn .dirty = true
224
198
return txn .us .Delete (k )
225
199
}
@@ -267,8 +241,6 @@ func (txn *tikvTxn) Commit(ctx context.Context) error {
267
241
}
268
242
})
269
243
270
- tikvTxnCmdCountWithSet .Add (float64 (txn .setCnt ))
271
- tikvTxnCmdCountWithCommit .Inc ()
272
244
start := time .Now ()
273
245
defer func () { tikvTxnCmdHistogramWithCommit .Observe (time .Since (start ).Seconds ()) }()
274
246
@@ -344,6 +316,7 @@ func (txn *tikvTxn) Rollback() error {
344
316
if ! txn .valid {
345
317
return kv .ErrInvalidTxn
346
318
}
319
+ start := time .Now ()
347
320
// Clean up pessimistic lock.
348
321
if txn .IsPessimistic () && txn .committer != nil {
349
322
err := txn .rollbackPessimisticLocks ()
@@ -354,8 +327,7 @@ func (txn *tikvTxn) Rollback() error {
354
327
}
355
328
txn .close ()
356
329
logutil .BgLogger ().Debug ("[kv] rollback txn" , zap .Uint64 ("txnStartTS" , txn .StartTS ()))
357
- tikvTxnCmdCountWithRollback .Inc ()
358
-
330
+ tikvTxnCmdHistogramWithRollback .Observe (time .Since (start ).Seconds ())
359
331
return nil
360
332
}
361
333
@@ -392,7 +364,6 @@ func (txn *tikvTxn) LockKeys(ctx context.Context, lockCtx *kv.LockCtx, keysInput
392
364
if len (keys ) == 0 {
393
365
return nil
394
366
}
395
- tikvTxnCmdHistogramWithLockKeys .Inc ()
396
367
if txn .IsPessimistic () && lockCtx .ForUpdateTS > 0 {
397
368
if txn .committer == nil {
398
369
// connID is used for log.
0 commit comments