Skip to content

Commit c0e8766

Browse files
authored
txnkv: decrease some max and base backoff time (#388)
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
1 parent 3a76757 commit c0e8766

File tree

8 files changed

+17
-16
lines changed

8 files changed

+17
-16
lines changed

integration_tests/snapshot_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ func (s *testSnapshotSuite) TestSnapshotRuntimeStats() {
293293
snapshot.MergeRegionRequestStats(reqStats.Stats)
294294
snapshot.MergeRegionRequestStats(reqStats.Stats)
295295
bo := tikv.NewBackofferWithVars(context.Background(), 2000, nil)
296-
err := bo.BackoffWithMaxSleepTxnLockFast(30, errors.New("test"))
296+
err := bo.BackoffWithMaxSleepTxnLockFast(5, errors.New("test"))
297297
s.Nil(err)
298298
snapshot.RecordBackoffInfo(bo)
299299
snapshot.RecordBackoffInfo(bo)
300-
expect := "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:60ms}"
301-
s.Equal(snapshot.FormatStats(), expect)
300+
expect := "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}"
301+
s.Equal(expect, snapshot.FormatStats())
302302
detail := &kvrpcpb.ExecDetailsV2{
303303
TimeDetail: &kvrpcpb.TimeDetail{
304304
WaitWallTimeMs: 100,
@@ -316,23 +316,23 @@ func (s *testSnapshotSuite) TestSnapshotRuntimeStats() {
316316
},
317317
}
318318
snapshot.MergeExecDetail(detail)
319-
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:60ms}, " +
319+
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " +
320320
"total_process_time: 100ms, total_wait_time: 100ms, " +
321321
"scan_detail: {total_process_keys: 10, " +
322322
"total_process_keys_size: 10, " +
323323
"total_keys: 15, " +
324324
"rocksdb: {delete_skipped_count: 5, " +
325325
"key_skipped_count: 1, " +
326326
"block: {cache_hit_count: 10, read_count: 20, read_byte: 15 Bytes}}}"
327-
s.Equal(snapshot.FormatStats(), expect)
327+
s.Equal(expect, snapshot.FormatStats())
328328
snapshot.MergeExecDetail(detail)
329-
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:60ms}, " +
329+
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " +
330330
"total_process_time: 200ms, total_wait_time: 200ms, " +
331331
"scan_detail: {total_process_keys: 20, " +
332332
"total_process_keys_size: 20, " +
333333
"total_keys: 30, " +
334334
"rocksdb: {delete_skipped_count: 10, " +
335335
"key_skipped_count: 2, " +
336336
"block: {cache_hit_count: 20, read_count: 40, read_byte: 30 Bytes}}}"
337-
s.Equal(snapshot.FormatStats(), expect)
337+
s.Equal(expect, snapshot.FormatStats())
338338
}

internal/retry/backoff_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ import (
4444

4545
func TestBackoffWithMax(t *testing.T) {
4646
b := NewBackofferWithVars(context.TODO(), 2000, nil)
47-
err := b.BackoffWithMaxSleepTxnLockFast(30, errors.New("test"))
47+
err := b.BackoffWithMaxSleepTxnLockFast(5, errors.New("test"))
4848

4949
assert.Nil(t, err)
50-
assert.Equal(t, 30, b.totalSleep)
50+
assert.Equal(t, 5, b.totalSleep)
5151
}

internal/retry/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ var (
111111
// TODO: distinguish tikv and tiflash in metrics
112112
BoTiKVRPC = NewConfig("tikvRPC", &metrics.BackoffHistogramRPC, NewBackoffFnCfg(100, 2000, EqualJitter), tikverr.ErrTiKVServerTimeout)
113113
BoTiFlashRPC = NewConfig("tiflashRPC", &metrics.BackoffHistogramRPC, NewBackoffFnCfg(100, 2000, EqualJitter), tikverr.ErrTiFlashServerTimeout)
114-
BoTxnLock = NewConfig("txnLock", &metrics.BackoffHistogramLock, NewBackoffFnCfg(200, 3000, EqualJitter), tikverr.ErrResolveLockTimeout)
114+
BoTxnLock = NewConfig("txnLock", &metrics.BackoffHistogramLock, NewBackoffFnCfg(100, 3000, EqualJitter), tikverr.ErrResolveLockTimeout)
115115
BoPDRPC = NewConfig("pdRPC", &metrics.BackoffHistogramPD, NewBackoffFnCfg(500, 3000, EqualJitter), tikverr.NewErrPDServerTimeout(""))
116116
// change base time to 2ms, because it may recover soon.
117117
BoRegionMiss = NewConfig("regionMiss", &metrics.BackoffHistogramRegionMiss, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrRegionUnavailable)

kv/variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ var DefaultVars = NewVariables(&ignoreKill)
6363

6464
// Default values
6565
const (
66-
DefBackoffLockFast = 100
66+
DefBackoffLockFast = 10
6767
DefBackOffWeight = 2
6868
)

txnkv/transaction/2pc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,8 @@ func (tm *ttlManager) reset() {
900900
close(tm.ch)
901901
}
902902

903-
const keepAliveMaxBackoff = 20000 // 20 seconds
904-
const pessimisticLockMaxBackoff = 600000 // 10 minutes
903+
const keepAliveMaxBackoff = 20000
904+
const pessimisticLockMaxBackoff = 20000
905905
const maxConsecutiveFailure = 10
906906

907907
func keepAlive(c *twoPhaseCommitter, closeCh chan struct{}, primaryKey []byte, lockCtx *kv.LockCtx) {

txnkv/txnlock/lock_resolver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ func (lr *LockResolver) getTxnStatusFromLock(bo *retry.Backoffer, l *Lock, calle
515515
// For pessimistic lock resolving, if the primary lock does not exist and rollbackIfNotExist is true,
516516
// The Action_LockNotExistDoNothing will be returned as the status.
517517
rollbackIfNotExist = true
518+
continue
518519
} else {
519520
// For the Rollback statement from user, the pessimistic locks will be rollbacked and the primary key in store
520521
// has no related information. There are possibilities that some other transactions do checkTxnStatus on these

txnkv/txnsnapshot/scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (s *Scanner) Value() []byte {
110110
return nil
111111
}
112112

113-
const scannerNextMaxBackoff = 600000 // 10 minutes
113+
const scannerNextMaxBackoff = 20000
114114

115115
// Next return next element.
116116
func (s *Scanner) Next() error {

txnkv/txnsnapshot/snapshot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func NewTiKVSnapshot(store kvstore, ts uint64, replicaReadSeed uint32) *KVSnapsh
155155
}
156156
}
157157

158-
const batchGetMaxBackoff = 600000 // 10 minutes
158+
const batchGetMaxBackoff = 20000
159159

160160
// SetSnapshotTS resets the timestamp for reads.
161161
func (s *KVSnapshot) SetSnapshotTS(ts uint64) {
@@ -458,7 +458,7 @@ func (s *KVSnapshot) batchGetSingleRegion(bo *retry.Backoffer, batch batchKeys,
458458
}
459459
}
460460

461-
const getMaxBackoff = 600000 // 10 minutes
461+
const getMaxBackoff = 20000
462462

463463
// Get gets the value for key k from snapshot.
464464
func (s *KVSnapshot) Get(ctx context.Context, k []byte) ([]byte, error) {

0 commit comments

Comments
 (0)