diff --git a/go.mod b/go.mod index a61f2e3d36347..db0ded3f91475 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/pingcap/kvproto v0.0.0-20191113105027-4f292e1801d8 github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd github.com/pingcap/parser v0.0.0-20191205054626-288fe5207ce6 - github.com/pingcap/pd v1.1.0-beta.0.20191115131715-6b7dc037010e + github.com/pingcap/pd v1.1.0-beta.0.20191224030110-529de4852735 github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible github.com/pingcap/tipb v0.0.0-20191126033718-169898888b24 github.com/prometheus/client_golang v1.0.0 diff --git a/go.sum b/go.sum index 03ae6ab1d53d8..e81c5cc618f46 100644 --- a/go.sum +++ b/go.sum @@ -171,8 +171,8 @@ github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd h1:hWDol43WY5PGhsh3+87 github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw= github.com/pingcap/parser v0.0.0-20191205054626-288fe5207ce6 h1:KrJorS9gGYMhsQjENNWAeB5ho28xbowZ74pfJWkOmFc= github.com/pingcap/parser v0.0.0-20191205054626-288fe5207ce6/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= -github.com/pingcap/pd v1.1.0-beta.0.20191115131715-6b7dc037010e h1:6En0+9KDJ6CjkuzbGwHgo+P1YjEt22jn+nujl6cSAXA= -github.com/pingcap/pd v1.1.0-beta.0.20191115131715-6b7dc037010e/go.mod h1:ribyi6AyFNOElWgb6VnUsky4JFciEoGApSUzIcJxGSI= +github.com/pingcap/pd v1.1.0-beta.0.20191224030110-529de4852735 h1:8794qEbQIEbTtK6ALO67130KUuE0QrX3yWaotJm25nM= +github.com/pingcap/pd v1.1.0-beta.0.20191224030110-529de4852735/go.mod h1:ribyi6AyFNOElWgb6VnUsky4JFciEoGApSUzIcJxGSI= github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible h1:I8HirWsu1MZp6t9G/g8yKCEjJJxtHooKakEgccvdJ4M= github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM= github.com/pingcap/tipb v0.0.0-20191126033718-169898888b24 h1:9cdSUluc+Q4yGzGg8AeG46/e8Rw7pJ5jJz9Y4QRNvKE= diff --git a/store/mockstore/mocktikv/pd.go b/store/mockstore/mocktikv/pd.go index f0b37669c6212..550e04accbf4f 100644 --- a/store/mockstore/mocktikv/pd.go +++ b/store/mockstore/mocktikv/pd.go @@ -121,3 +121,5 @@ func (c *pdClient) ScatterRegion(ctx context.Context, regionID uint64) error { func (c *pdClient) GetOperator(ctx context.Context, regionID uint64) (*pdpb.GetOperatorResponse, error) { return &pdpb.GetOperatorResponse{Status: pdpb.OperatorStatus_SUCCESS}, nil } + +func (c *pdClient) GetLeaderAddr() string { return "mockpd" } diff --git a/store/tikv/kv.go b/store/tikv/kv.go index 45b18885da39c..26c37eafe796b 100755 --- a/store/tikv/kv.go +++ b/store/tikv/kv.go @@ -37,6 +37,8 @@ import ( "github.com/pingcap/tidb/util/logutil" "go.etcd.io/etcd/clientv3" "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/keepalive" ) type storeCache struct { @@ -70,6 +72,7 @@ func (d Driver) Open(path string) (kv.Storage, error) { defer mc.Unlock() security := config.GetGlobalConfig().Security + tikvConfig := config.GetGlobalConfig().TiKVClient txnLocalLatches := config.GetGlobalConfig().TxnLocalLatches etcdAddrs, disableGC, err := parsePath(path) if err != nil { @@ -80,7 +83,13 @@ func (d Driver) Open(path string) (kv.Storage, error) { CAPath: security.ClusterSSLCA, CertPath: security.ClusterSSLCert, KeyPath: security.ClusterSSLKey, - }) + }, pd.WithGRPCDialOptions( + grpc.WithKeepaliveParams(keepalive.ClientParameters{ + Time: time.Duration(tikvConfig.GrpcKeepAliveTime) * time.Second, + Timeout: time.Duration(tikvConfig.GrpcKeepAliveTimeout) * time.Second, + PermitWithoutStream: true, + }), + )) if err != nil { return nil, errors.Trace(err) diff --git a/store/tikv/lock_resolver.go b/store/tikv/lock_resolver.go index 1945b814bb40e..a7e5f2d43351a 100644 --- a/store/tikv/lock_resolver.go +++ b/store/tikv/lock_resolver.go @@ -23,7 +23,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" - "github.com/pingcap/pd/client" + pd "github.com/pingcap/pd/client" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/store/tikv/tikvrpc" @@ -76,12 +76,12 @@ var _ = NewLockResolver // NewLockResolver creates a LockResolver. // It is exported for other pkg to use. For instance, binlog service needs // to determine a transaction's commit state. -func NewLockResolver(etcdAddrs []string, security config.Security) (*LockResolver, error) { +func NewLockResolver(etcdAddrs []string, security config.Security, opts ...pd.ClientOption) (*LockResolver, error) { pdCli, err := pd.NewClient(etcdAddrs, pd.SecurityOption{ CAPath: security.ClusterSSLCA, CertPath: security.ClusterSSLCert, KeyPath: security.ClusterSSLKey, - }) + }, opts...) if err != nil { return nil, errors.Trace(err) } diff --git a/store/tikv/rawkv.go b/store/tikv/rawkv.go index b3fbfaf064026..892fe597a7a9d 100644 --- a/store/tikv/rawkv.go +++ b/store/tikv/rawkv.go @@ -63,12 +63,12 @@ type RawKVClient struct { } // NewRawKVClient creates a client with PD cluster addrs. -func NewRawKVClient(pdAddrs []string, security config.Security) (*RawKVClient, error) { +func NewRawKVClient(pdAddrs []string, security config.Security, opts ...pd.ClientOption) (*RawKVClient, error) { pdCli, err := pd.NewClient(pdAddrs, pd.SecurityOption{ CAPath: security.ClusterSSLCA, CertPath: security.ClusterSSLCert, KeyPath: security.ClusterSSLKey, - }) + }, opts...) if err != nil { return nil, errors.Trace(err) }