/
txn.go
125 lines (104 loc) · 3.84 KB
/
txn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import "time"
// Txn contains the configurations for transactional kv.
type Txn struct {
// EntrySizeLimit is limit of single entry size (len(key) + len(value)).
EntrySizeLimit int
// EntryCountLimit is a limit of the number of entries in the MemBuffer.
EntryCountLimit int
// TotalSizeLimit is limit of the sum of all entry size.
TotalSizeLimit int
// MaxTimeUse is the max time a transaction can run.
MaxTimeUse int
// DefaultMembufCap is the default transaction membuf capability.
DefaultMembufCap int
// TiKV recommends each RPC packet should be less than ~1MB. We keep each
// packet's Key+Value size below 16KB by default.
CommitBatchSize int
// ScanBatchSize is the limit of an iterator's scan request.
ScanBatchSize int
// BatchGetSize is the max number of keys in a BatchGet request.
BatchGetSize int
// By default, locks after 3000ms is considered unusual (the client created the
// lock might be dead). Other client may cleanup this kind of lock.
// For locks created recently, we will do backoff and retry.
DefaultLockTTL uint64
// The maximum value of a txn's lock TTL.
MaxLockTTL uint64
// ttl = ttlFactor * sqrt(writeSizeInMiB)
TTLFactor int
// ResolveCacheSize is max number of cached txn status.
ResolveCacheSize int
GcSavedSafePoint string
GcSafePointCacheInterval time.Duration
GcCPUTimeInaccuracyBound time.Duration
GcSafePointUpdateInterval time.Duration
GcSafePointQuickRepeatInterval time.Duration
GCTimeout time.Duration
UnsafeDestroyRangeTimeout time.Duration
TsoSlowThreshold time.Duration
OracleUpdateInterval time.Duration
Latch Latch
}
// DefaultTxn returns the default txn config.
func DefaultTxn() Txn {
return Txn{
EntrySizeLimit: 6 * 1024 * 1024,
EntryCountLimit: 300 * 1000,
TotalSizeLimit: 100 * 1024 * 1024,
MaxTimeUse: 590,
DefaultMembufCap: 4 * 1024,
CommitBatchSize: 16 * 1024,
ScanBatchSize: 256,
BatchGetSize: 5120,
DefaultLockTTL: 3000,
MaxLockTTL: 120000,
TTLFactor: 6000,
ResolveCacheSize: 2048,
GcSavedSafePoint: "/tidb/store/gcworker/saved_safe_point",
GcSafePointCacheInterval: time.Second * 100,
GcCPUTimeInaccuracyBound: time.Second,
GcSafePointUpdateInterval: time.Second * 10,
GcSafePointQuickRepeatInterval: time.Second,
GCTimeout: 5 * time.Minute,
UnsafeDestroyRangeTimeout: 5 * time.Minute,
TsoSlowThreshold: 30 * time.Millisecond,
OracleUpdateInterval: 2 * time.Second,
Latch: DefaultLatch(),
}
}
// Latch is the configuration for local latch.
type Latch struct {
// Enable it when there are lots of conflicts between transactions.
Enable bool
Capacity uint
ExpireDuration time.Duration
CheckInterval time.Duration
CheckCounter int
ListCount int
LockChanSize int
}
// DefaultLatch returns the default Latch config.
func DefaultLatch() Latch {
return Latch{
Enable: false,
Capacity: 2048000,
ExpireDuration: 2 * time.Minute,
CheckInterval: time.Minute,
CheckCounter: 50000,
ListCount: 5,
LockChanSize: 100,
}
}