|
13 | 13 |
|
14 | 14 | package config
|
15 | 15 |
|
16 |
| -import ( |
17 |
| - "crypto/tls" |
18 |
| - "crypto/x509" |
19 |
| - "io/ioutil" |
20 |
| - "time" |
21 |
| - |
22 |
| - "github.com/pkg/errors" |
23 |
| -) |
24 |
| - |
25 |
| -// Security is SSL configuration. |
26 |
| -type Security struct { |
27 |
| - SSLCA string `toml:"ssl-ca" json:"ssl-ca"` |
28 |
| - SSLCert string `toml:"ssl-cert" json:"ssl-cert"` |
29 |
| - SSLKey string `toml:"ssl-key" json:"ssl-key"` |
| 16 | +// Config contains configurations for tikv client. |
| 17 | +type Config struct { |
| 18 | + RPC RPC |
| 19 | + Raw Raw |
| 20 | + Txn Txn |
| 21 | + RegionCache RegionCache |
30 | 22 | }
|
31 | 23 |
|
32 |
| -// ToTLSConfig generates tls's config based on security section of the config. |
33 |
| -func (s *Security) ToTLSConfig() (*tls.Config, error) { |
34 |
| - var tlsConfig *tls.Config |
35 |
| - if len(s.SSLCA) != 0 { |
36 |
| - var certificates = make([]tls.Certificate, 0) |
37 |
| - if len(s.SSLCert) != 0 && len(s.SSLKey) != 0 { |
38 |
| - // Load the client certificates from disk |
39 |
| - certificate, err := tls.LoadX509KeyPair(s.SSLCert, s.SSLKey) |
40 |
| - if err != nil { |
41 |
| - return nil, errors.Errorf("could not load client key pair: %s", err) |
42 |
| - } |
43 |
| - certificates = append(certificates, certificate) |
44 |
| - } |
45 |
| - |
46 |
| - // Create a certificate pool from the certificate authority |
47 |
| - certPool := x509.NewCertPool() |
48 |
| - ca, err := ioutil.ReadFile(s.SSLCA) |
49 |
| - if err != nil { |
50 |
| - return nil, errors.Errorf("could not read ca certificate: %s", err) |
51 |
| - } |
52 |
| - |
53 |
| - // Append the certificates from the CA |
54 |
| - if !certPool.AppendCertsFromPEM(ca) { |
55 |
| - return nil, errors.New("failed to append ca certs") |
56 |
| - } |
57 |
| - |
58 |
| - tlsConfig = &tls.Config{ |
59 |
| - Certificates: certificates, |
60 |
| - RootCAs: certPool, |
61 |
| - } |
| 24 | +// Default returns the default config. |
| 25 | +func Default() Config { |
| 26 | + return Config{ |
| 27 | + RPC: DefaultRPC(), |
| 28 | + Raw: DefaultRaw(), |
| 29 | + Txn: DefaultTxn(), |
| 30 | + RegionCache: DefaultRegionCache(), |
62 | 31 | }
|
63 |
| - |
64 |
| - return tlsConfig, nil |
65 | 32 | }
|
66 |
| - |
67 |
| -// EnableOpenTracing is the flag to enable open tracing. |
68 |
| -var EnableOpenTracing = false |
69 |
| - |
70 |
| -var ( |
71 |
| - // OverloadThreshold is a threshold of TiKV load. |
72 |
| - // If TiKV load is greater than this, TiDB will wait for a while to avoid little batch. |
73 |
| - OverloadThreshold uint = 200 |
74 |
| - // BatchWaitSize is the max wait size for batch. |
75 |
| - BatchWaitSize uint = 8 |
76 |
| - // MaxBatchSize is the max batch size when calling batch commands API. |
77 |
| - MaxBatchSize uint = 128 |
78 |
| - // MaxBatchWaitTime in nanosecond is the max wait time for batch. |
79 |
| - MaxBatchWaitTime time.Duration |
80 |
| -) |
81 |
| - |
82 |
| -// Those limits are enforced to make sure the transaction can be well handled by TiKV. |
83 |
| -var ( |
84 |
| - // TxnEntrySizeLimit is limit of single entry size (len(key) + len(value)). |
85 |
| - TxnEntrySizeLimit = 6 * 1024 * 1024 |
86 |
| - // TxnEntryCountLimit is a limit of the number of entries in the MemBuffer. |
87 |
| - TxnEntryCountLimit uint64 = 300 * 1000 |
88 |
| - // TxnTotalSizeLimit is limit of the sum of all entry size. |
89 |
| - TxnTotalSizeLimit = 100 * 1024 * 1024 |
90 |
| - // MaxTxnTimeUse is the max time a transaction can run. |
91 |
| - MaxTxnTimeUse = 590 |
92 |
| -) |
93 |
| - |
94 |
| -// Local latches for transactions. Enable it when |
95 |
| -// there are lots of conflicts between transactions. |
96 |
| -var ( |
97 |
| - EnableTxnLocalLatch = false |
98 |
| - TxnLocalLatchCapacity uint = 2048000 |
99 |
| -) |
100 |
| - |
101 |
| -// RegionCache configurations. |
102 |
| -var ( |
103 |
| - RegionCacheBTreeDegree = 32 |
104 |
| - RegionCacheTTL = time.Minute * 10 |
105 |
| -) |
106 |
| - |
107 |
| -// RawKV configurations. |
108 |
| -var ( |
109 |
| - // MaxRawKVScanLimit is the maximum scan limit for rawkv Scan. |
110 |
| - MaxRawKVScanLimit = 10240 |
111 |
| - // RawBatchPutSize is the maximum size limit for rawkv each batch put request. |
112 |
| - RawBatchPutSize = 16 * 1024 |
113 |
| - // RawBatchPairCount is the maximum limit for rawkv each batch get/delete request. |
114 |
| - RawBatchPairCount = 512 |
115 |
| -) |
116 |
| - |
117 |
| -// RPC configurations. |
118 |
| -var ( |
119 |
| - // MaxConnectionCount is the max gRPC connections that will be established with |
120 |
| - // each tikv-server. |
121 |
| - MaxConnectionCount uint = 16 |
122 |
| - |
123 |
| - // GrpcKeepAliveTime is the duration of time after which if the client doesn't see |
124 |
| - // any activity it pings the server to see if the transport is still alive. |
125 |
| - GrpcKeepAliveTime = time.Duration(10) * time.Second |
126 |
| - |
127 |
| - // GrpcKeepAliveTimeout is the duration of time for which the client waits after having |
128 |
| - // pinged for keepalive check and if no activity is seen even after that the connection |
129 |
| - // is closed. |
130 |
| - GrpcKeepAliveTimeout = time.Duration(3) * time.Second |
131 |
| - |
132 |
| - // MaxSendMsgSize set max gRPC request message size sent to server. If any request message size is larger than |
133 |
| - // current value, an error will be reported from gRPC. |
134 |
| - MaxSendMsgSize = 1<<31 - 1 |
135 |
| - |
136 |
| - // MaxCallMsgSize set max gRPC receive message size received from server. If any message size is larger than |
137 |
| - // current value, an error will be reported from gRPC. |
138 |
| - MaxCallMsgSize = 1<<31 - 1 |
139 |
| - |
140 |
| - DialTimeout = 5 * time.Second |
141 |
| - ReadTimeoutShort = 20 * time.Second // For requests that read/write several key-values. |
142 |
| - ReadTimeoutMedium = 60 * time.Second // For requests that may need scan region. |
143 |
| - ReadTimeoutLong = 150 * time.Second // For requests that may need scan region multiple times. |
144 |
| - GCTimeout = 5 * time.Minute |
145 |
| - UnsafeDestroyRangeTimeout = 5 * time.Minute |
146 |
| - |
147 |
| - GrpcInitialWindowSize = 1 << 30 |
148 |
| - GrpcInitialConnWindowSize = 1 << 30 |
149 |
| -) |
150 |
| - |
151 |
| -// KV configurations. |
152 |
| -var ( |
153 |
| - // DefaultTxnMembufCap is the default transaction membuf capability. |
154 |
| - DefaultTxnMembufCap = 4 * 1024 |
155 |
| -) |
156 |
| - |
157 |
| -// Latch configurations. |
158 |
| -var ( |
159 |
| - LatchExpireDuration = 2 * time.Minute |
160 |
| - LatchCheckInterval = 1 * time.Minute |
161 |
| - LatchCheckCounter = 50000 |
162 |
| - LatchListCount = 5 |
163 |
| - LatchLockChanSize = 100 |
164 |
| -) |
165 |
| - |
166 |
| -// Oracle configurations. |
167 |
| -var ( |
168 |
| - TsoSlowThreshold = 30 * time.Millisecond |
169 |
| - // update oracle's lastTS every 2000ms. |
170 |
| - OracleUpdateInterval = 2000 |
171 |
| -) |
172 |
| - |
173 |
| -// Txn configurations. |
174 |
| -var ( |
175 |
| - // TiKV recommends each RPC packet should be less than ~1MB. We keep each packet's |
176 |
| - // Key+Value size below 16KB. |
177 |
| - TxnCommitBatchSize = 16 * 1024 |
178 |
| - |
179 |
| - // By default, locks after 3000ms is considered unusual (the client created the |
180 |
| - // lock might be dead). Other client may cleanup this kind of lock. |
181 |
| - // For locks created recently, we will do backoff and retry. |
182 |
| - TxnDefaultLockTTL uint64 = 3000 |
183 |
| - // TODO: Consider if it's appropriate. |
184 |
| - TxnMaxLockTTL uint64 = 120000 |
185 |
| - // ttl = ttlFactor * sqrt(writeSizeInMiB) |
186 |
| - TxnTTLFactor = 6000 |
187 |
| - // TxnResolvedCacheSize is max number of cached txn status. |
188 |
| - TxnResolvedCacheSize = 2048 |
189 |
| - |
190 |
| - // SafePoint. |
191 |
| - // This is almost the same as 'tikv_gc_safe_point' in the table 'mysql.tidb', |
192 |
| - // save this to pd instead of tikv, because we can't use interface of table |
193 |
| - // if the safepoint on tidb is expired. |
194 |
| - GcSavedSafePoint = "/tidb/store/gcworker/saved_safe_point" |
195 |
| - |
196 |
| - GcSafePointCacheInterval = time.Second * 100 |
197 |
| - GcCPUTimeInaccuracyBound = time.Second |
198 |
| - GcSafePointUpdateInterval = time.Second * 10 |
199 |
| - GcSafePointQuickRepeatInterval = time.Second |
200 |
| - |
201 |
| - TxnScanBatchSize = 256 |
202 |
| - TxnBatchGetSize = 5120 |
203 |
| -) |
0 commit comments