Skip to content

Commit

Permalink
txnkv: decrease some max and base backoff time (#388)
Browse files Browse the repository at this point in the history
Signed-off-by: youjiali1995 <[email protected]>
  • Loading branch information
youjiali1995 authored Dec 6, 2021
1 parent 3a76757 commit c0e8766
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
14 changes: 7 additions & 7 deletions integration_tests/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ func (s *testSnapshotSuite) TestSnapshotRuntimeStats() {
snapshot.MergeRegionRequestStats(reqStats.Stats)
snapshot.MergeRegionRequestStats(reqStats.Stats)
bo := tikv.NewBackofferWithVars(context.Background(), 2000, nil)
err := bo.BackoffWithMaxSleepTxnLockFast(30, errors.New("test"))
err := bo.BackoffWithMaxSleepTxnLockFast(5, errors.New("test"))
s.Nil(err)
snapshot.RecordBackoffInfo(bo)
snapshot.RecordBackoffInfo(bo)
expect := "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:60ms}"
s.Equal(snapshot.FormatStats(), expect)
expect := "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}"
s.Equal(expect, snapshot.FormatStats())
detail := &kvrpcpb.ExecDetailsV2{
TimeDetail: &kvrpcpb.TimeDetail{
WaitWallTimeMs: 100,
Expand All @@ -316,23 +316,23 @@ func (s *testSnapshotSuite) TestSnapshotRuntimeStats() {
},
}
snapshot.MergeExecDetail(detail)
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:60ms}, " +
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " +
"total_process_time: 100ms, total_wait_time: 100ms, " +
"scan_detail: {total_process_keys: 10, " +
"total_process_keys_size: 10, " +
"total_keys: 15, " +
"rocksdb: {delete_skipped_count: 5, " +
"key_skipped_count: 1, " +
"block: {cache_hit_count: 10, read_count: 20, read_byte: 15 Bytes}}}"
s.Equal(snapshot.FormatStats(), expect)
s.Equal(expect, snapshot.FormatStats())
snapshot.MergeExecDetail(detail)
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:60ms}, " +
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " +
"total_process_time: 200ms, total_wait_time: 200ms, " +
"scan_detail: {total_process_keys: 20, " +
"total_process_keys_size: 20, " +
"total_keys: 30, " +
"rocksdb: {delete_skipped_count: 10, " +
"key_skipped_count: 2, " +
"block: {cache_hit_count: 20, read_count: 40, read_byte: 30 Bytes}}}"
s.Equal(snapshot.FormatStats(), expect)
s.Equal(expect, snapshot.FormatStats())
}
4 changes: 2 additions & 2 deletions internal/retry/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import (

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

assert.Nil(t, err)
assert.Equal(t, 30, b.totalSleep)
assert.Equal(t, 5, b.totalSleep)
}
2 changes: 1 addition & 1 deletion internal/retry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var (
// TODO: distinguish tikv and tiflash in metrics
BoTiKVRPC = NewConfig("tikvRPC", &metrics.BackoffHistogramRPC, NewBackoffFnCfg(100, 2000, EqualJitter), tikverr.ErrTiKVServerTimeout)
BoTiFlashRPC = NewConfig("tiflashRPC", &metrics.BackoffHistogramRPC, NewBackoffFnCfg(100, 2000, EqualJitter), tikverr.ErrTiFlashServerTimeout)
BoTxnLock = NewConfig("txnLock", &metrics.BackoffHistogramLock, NewBackoffFnCfg(200, 3000, EqualJitter), tikverr.ErrResolveLockTimeout)
BoTxnLock = NewConfig("txnLock", &metrics.BackoffHistogramLock, NewBackoffFnCfg(100, 3000, EqualJitter), tikverr.ErrResolveLockTimeout)
BoPDRPC = NewConfig("pdRPC", &metrics.BackoffHistogramPD, NewBackoffFnCfg(500, 3000, EqualJitter), tikverr.NewErrPDServerTimeout(""))
// change base time to 2ms, because it may recover soon.
BoRegionMiss = NewConfig("regionMiss", &metrics.BackoffHistogramRegionMiss, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrRegionUnavailable)
Expand Down
2 changes: 1 addition & 1 deletion kv/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ var DefaultVars = NewVariables(&ignoreKill)

// Default values
const (
DefBackoffLockFast = 100
DefBackoffLockFast = 10
DefBackOffWeight = 2
)
4 changes: 2 additions & 2 deletions txnkv/transaction/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,8 @@ func (tm *ttlManager) reset() {
close(tm.ch)
}

const keepAliveMaxBackoff = 20000 // 20 seconds
const pessimisticLockMaxBackoff = 600000 // 10 minutes
const keepAliveMaxBackoff = 20000
const pessimisticLockMaxBackoff = 20000
const maxConsecutiveFailure = 10

func keepAlive(c *twoPhaseCommitter, closeCh chan struct{}, primaryKey []byte, lockCtx *kv.LockCtx) {
Expand Down
1 change: 1 addition & 0 deletions txnkv/txnlock/lock_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ func (lr *LockResolver) getTxnStatusFromLock(bo *retry.Backoffer, l *Lock, calle
// For pessimistic lock resolving, if the primary lock does not exist and rollbackIfNotExist is true,
// The Action_LockNotExistDoNothing will be returned as the status.
rollbackIfNotExist = true
continue
} else {
// For the Rollback statement from user, the pessimistic locks will be rollbacked and the primary key in store
// has no related information. There are possibilities that some other transactions do checkTxnStatus on these
Expand Down
2 changes: 1 addition & 1 deletion txnkv/txnsnapshot/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *Scanner) Value() []byte {
return nil
}

const scannerNextMaxBackoff = 600000 // 10 minutes
const scannerNextMaxBackoff = 20000

// Next return next element.
func (s *Scanner) Next() error {
Expand Down
4 changes: 2 additions & 2 deletions txnkv/txnsnapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func NewTiKVSnapshot(store kvstore, ts uint64, replicaReadSeed uint32) *KVSnapsh
}
}

const batchGetMaxBackoff = 600000 // 10 minutes
const batchGetMaxBackoff = 20000

// SetSnapshotTS resets the timestamp for reads.
func (s *KVSnapshot) SetSnapshotTS(ts uint64) {
Expand Down Expand Up @@ -458,7 +458,7 @@ func (s *KVSnapshot) batchGetSingleRegion(bo *retry.Backoffer, batch batchKeys,
}
}

const getMaxBackoff = 600000 // 10 minutes
const getMaxBackoff = 20000

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

0 comments on commit c0e8766

Please sign in to comment.