mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3: configure gRPC message limits in Config
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
4cebdd274c
commit
e82f0557ac
@ -56,7 +56,7 @@ type Client struct {
|
|||||||
cfg Config
|
cfg Config
|
||||||
creds *credentials.TransportCredentials
|
creds *credentials.TransportCredentials
|
||||||
balancer *healthBalancer
|
balancer *healthBalancer
|
||||||
mu sync.Mutex
|
mu *sync.Mutex
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@ -67,6 +67,8 @@ type Client struct {
|
|||||||
Password string
|
Password string
|
||||||
// tokenCred is an instance of WithPerRPCCredentials()'s argument
|
// tokenCred is an instance of WithPerRPCCredentials()'s argument
|
||||||
tokenCred *authTokenCredential
|
tokenCred *authTokenCredential
|
||||||
|
|
||||||
|
callOpts []grpc.CallOption
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new etcdv3 client from a given configuration.
|
// New creates a new etcdv3 client from a given configuration.
|
||||||
@ -385,11 +387,30 @@ func newClient(cfg *Config) (*Client, error) {
|
|||||||
creds: creds,
|
creds: creds,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
|
mu: new(sync.Mutex),
|
||||||
|
callOpts: defaultCallOpts,
|
||||||
}
|
}
|
||||||
if cfg.Username != "" && cfg.Password != "" {
|
if cfg.Username != "" && cfg.Password != "" {
|
||||||
client.Username = cfg.Username
|
client.Username = cfg.Username
|
||||||
client.Password = cfg.Password
|
client.Password = cfg.Password
|
||||||
}
|
}
|
||||||
|
if cfg.MaxCallSendMsgSize > 0 || cfg.MaxCallRecvMsgSize > 0 {
|
||||||
|
if cfg.MaxCallRecvMsgSize > 0 && cfg.MaxCallSendMsgSize > cfg.MaxCallRecvMsgSize {
|
||||||
|
return nil, fmt.Errorf("gRPC message recv limit (%d bytes) must be greater than send limit (%d bytes)", cfg.MaxCallRecvMsgSize, cfg.MaxCallSendMsgSize)
|
||||||
|
}
|
||||||
|
callOpts := []grpc.CallOption{
|
||||||
|
defaultFailFast,
|
||||||
|
defaultMaxCallSendMsgSize,
|
||||||
|
defaultMaxCallRecvMsgSize,
|
||||||
|
}
|
||||||
|
if cfg.MaxCallSendMsgSize > 0 {
|
||||||
|
callOpts[1] = grpc.MaxCallSendMsgSize(cfg.MaxCallSendMsgSize)
|
||||||
|
}
|
||||||
|
if cfg.MaxCallRecvMsgSize > 0 {
|
||||||
|
callOpts[2] = grpc.MaxCallRecvMsgSize(cfg.MaxCallRecvMsgSize)
|
||||||
|
}
|
||||||
|
client.callOpts = callOpts
|
||||||
|
}
|
||||||
|
|
||||||
client.balancer = newHealthBalancer(cfg.Endpoints, cfg.DialTimeout, func(ep string) (bool, error) {
|
client.balancer = newHealthBalancer(cfg.Endpoints, cfg.DialTimeout, func(ep string) (bool, error) {
|
||||||
return grpcHealthCheck(client, ep)
|
return grpcHealthCheck(client, ep)
|
||||||
|
@ -41,6 +41,19 @@ type Config struct {
|
|||||||
// keep-alive probe. If the response is not received in this time, the connection is closed.
|
// keep-alive probe. If the response is not received in this time, the connection is closed.
|
||||||
DialKeepAliveTimeout time.Duration `json:"dial-keep-alive-timeout"`
|
DialKeepAliveTimeout time.Duration `json:"dial-keep-alive-timeout"`
|
||||||
|
|
||||||
|
// MaxCallSendMsgSize is the client-side request send limit in bytes.
|
||||||
|
// If 0, it defaults to 2.0 MiB (2 * 1024 * 1024).
|
||||||
|
// Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit.
|
||||||
|
// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
|
||||||
|
MaxCallSendMsgSize int
|
||||||
|
|
||||||
|
// MaxCallRecvMsgSize is the client-side response receive limit.
|
||||||
|
// If 0, it defaults to "math.MaxInt32", because range response can
|
||||||
|
// easily exceed request send limits.
|
||||||
|
// Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit.
|
||||||
|
// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
|
||||||
|
MaxCallRecvMsgSize int
|
||||||
|
|
||||||
// TLS holds the client secure credentials, if any.
|
// TLS holds the client secure credentials, if any.
|
||||||
TLS *tls.Config
|
TLS *tls.Config
|
||||||
|
|
||||||
|
46
clientv3/grpc_options.go
Normal file
46
clientv3/grpc_options.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2017 The etcd Authors
|
||||||
|
//
|
||||||
|
// 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,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package clientv3
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Disable gRPC internal retrial logic
|
||||||
|
// TODO: enable when gRPC retry is stable (FailFast=false)
|
||||||
|
// Reference:
|
||||||
|
// - https://github.com/grpc/grpc-go/issues/1532
|
||||||
|
// - https://github.com/grpc/proposal/blob/master/A6-client-retries.md
|
||||||
|
defaultFailFast = grpc.FailFast(true)
|
||||||
|
|
||||||
|
// client-side request send limit, gRPC default is math.MaxInt32
|
||||||
|
// Make sure that "client-side send limit < server-side default send/recv limit"
|
||||||
|
// Same value as "embed.DefaultMaxRequestBytes" plus gRPC overhead bytes
|
||||||
|
defaultMaxCallSendMsgSize = grpc.MaxCallSendMsgSize(2 * 1024 * 1024)
|
||||||
|
|
||||||
|
// client-side response receive limit, gRPC default is 4MB
|
||||||
|
// Make sure that "client-side receive limit >= server-side default send/recv limit"
|
||||||
|
// because range response can easily exceed request send limits
|
||||||
|
// Default to math.MaxInt32; writes exceeding server-side send limit fails anyway
|
||||||
|
defaultMaxCallRecvMsgSize = grpc.MaxCallRecvMsgSize(math.MaxInt32)
|
||||||
|
)
|
||||||
|
|
||||||
|
// defaultCallOpts defines a list of default "gRPC.CallOption".
|
||||||
|
// Some options are exposed to "clientv3.Config".
|
||||||
|
// Defaults will be overridden by the settings in "clientv3.Config".
|
||||||
|
var defaultCallOpts = []grpc.CallOption{defaultFailFast, defaultMaxCallSendMsgSize, defaultMaxCallRecvMsgSize}
|
Loading…
x
Reference in New Issue
Block a user