Skip to content

Commit d3f92f8

Browse files
authored
config: cleanup and pass config as parameter (tikv#14)
* config: cleanup and pass config as parameter Signed-off-by: disksing <[email protected]> * fix review comments Signed-off-by: disksing <[email protected]> * fix conflicts Signed-off-by: disksing <[email protected]> * address comment Signed-off-by: disksing <[email protected]>
1 parent 9e0bad6 commit d3f92f8

36 files changed

+611
-369
lines changed

config/config.go

+13-184
Original file line numberDiff line numberDiff line change
@@ -13,191 +13,20 @@
1313

1414
package config
1515

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
3022
}
3123

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(),
6231
}
63-
64-
return tlsConfig, nil
6532
}
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-
)

config/raw.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2019 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package config
15+
16+
// Raw is rawkv configurations.
17+
type Raw struct {
18+
// MaxScanLimit is the maximum scan limit for rawkv Scan.
19+
MaxScanLimit int
20+
21+
// MaxBatchPutSize is the maximum size limit for rawkv each batch put request.
22+
MaxBatchPutSize int
23+
24+
// BatchPairCount is the maximum limit for rawkv each batch get/delete request.
25+
BatchPairCount int
26+
}
27+
28+
// DefaultRaw returns default rawkv configuration.
29+
func DefaultRaw() Raw {
30+
return Raw{
31+
MaxScanLimit: 10240,
32+
MaxBatchPutSize: 16 * 1024,
33+
BatchPairCount: 512,
34+
}
35+
}

config/regioncache.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2019 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package config
15+
16+
import "time"
17+
18+
// RegionCache contains the configurations for region cache.
19+
type RegionCache struct {
20+
BTreeDegree int
21+
CacheTTL time.Duration
22+
}
23+
24+
// DefaultRegionCache returns the default region cache config.
25+
func DefaultRegionCache() RegionCache {
26+
return RegionCache{
27+
BTreeDegree: 32,
28+
CacheTTL: 10 * time.Minute,
29+
}
30+
}

0 commit comments

Comments
 (0)