import"github.com/coreos/etcd/clientv3"import"google.golang.org/grpc/grpclog"clientv3.SetLogger(grpclog.NewLoggerV2(os.Stderr,os.Stderr,os.Stderr))// log.New above cannot be used (not implement grpclog.LoggerV2 interface)
# limits request size to 1.5 KiBetcd --max-request-bytes 1536# client writes exceeding 1.5 KiB will be rejectedetcdctl put foo [LARGE VALUE...]# etcdserver: request is too large
或配置 embed.Config.MaxRequestBytes 字段:
import"github.com/coreos/etcd/embed"import"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"// limit requests to 5 MiBcfg:=embed.NewConfig()cfg.MaxRequestBytes=5*1024*1024// client writes exceeding 5 MiB will be rejected_,err:=cli.Put(ctx,"foo",[LARGEVALUE...])err==rpctypes.ErrRequestTooLarge
如果未指定,服务器端限制默认为 1.5 MiB。
客户端请求限制必须根据服务器端限制进行配置。
# limits request size to 1 MiBetcd --max-request-bytes 1048576
import"github.com/coreos/etcd/clientv3"cli,_:=clientv3.New(clientv3.Config{Endpoints:[]string{"127.0.0.1:2379"},MaxCallSendMsgSize:2*1024*1024,MaxCallRecvMsgSize:3*1024*1024,})// client writes exceeding "--max-request-bytes" will be rejected from etcd server_,err:=cli.Put(ctx,"foo",strings.Repeat("a",1*1024*1024+5))err==rpctypes.ErrRequestTooLarge// client writes exceeding "MaxCallSendMsgSize" will be rejected from client-side_,err=cli.Put(ctx,"foo",strings.Repeat("a",5*1024*1024))err.Error()=="rpc error: code = ResourceExhausted desc = grpc: trying to send message larger than max (5242890 vs. 2097152)"// some writes under limitsfori:=range[]int{0,1,2,3,4}{_,err=cli.Put(ctx,fmt.Sprintf("foo%d",i),strings.Repeat("a",1*1024*1024-500))iferr!=nil{panic(err)}}// client reads exceeding "MaxCallRecvMsgSize" will be rejected from client-side_,err=cli.Get(ctx,"foo",clientv3.WithPrefix())err.Error()=="rpc error: code = ResourceExhausted desc = grpc: received message larger than max (5240509 vs. 3145728)"
2017-04-27 14:13:31.491746 I | raft: c89feb932daef420 [term 3] received MsgTimeoutNow from 6d4f535bae3ab960 and starts an election to get leadership.
2017-04-27 14:13:31.491769 I | raft: c89feb932daef420 became candidate at term 4
2017-04-27 14:13:31.491788 I | raft: c89feb932daef420 received MsgVoteResp from c89feb932daef420 at term 4
2017-04-27 14:13:31.491797 I | raft: c89feb932daef420 [logterm: 3, index: 9] sent MsgVote request to 6d4f535bae3ab960 at term 4
2017-04-27 14:13:31.491805 I | raft: c89feb932daef420 [logterm: 3, index: 9] sent MsgVote request to 9eda174c7df8a033 at term 4
2017-04-27 14:13:31.491815 I | raft: raft.node: c89feb932daef420 lost leader 6d4f535bae3ab960 at term 4
2017-04-27 14:13:31.524084 I | raft: c89feb932daef420 received MsgVoteResp from 6d4f535bae3ab960 at term 4
2017-04-27 14:13:31.524108 I | raft: c89feb932daef420 [quorum:2] has received 2 MsgVoteResp votes and 0 vote rejections
2017-04-27 14:13:31.524123 I | raft: c89feb932daef420 became leader at term 4
2017-04-27 14:13:31.524136 I | raft: raft.node: c89feb932daef420 elected leader c89feb932daef420 at term 4
2017-04-27 14:13:31.592650 W | rafthttp: lost the TCP streaming connection with peer 6d4f535bae3ab960 (stream MsgApp v2 reader)
2017-04-27 14:13:31.592825 W | rafthttp: lost the TCP streaming connection with peer 6d4f535bae3ab960 (stream Message reader)
2017-04-27 14:13:31.693275 E | rafthttp: failed to dial 6d4f535bae3ab960 on stream Message (dial tcp [::1]:2380: getsockopt: connection refused)
2017-04-27 14:13:31.693289 I | rafthttp: peer 6d4f535bae3ab960 became inactive
2017-04-27 14:13:31.936678 W | rafthttp: lost the TCP streaming connection with peer 6d4f535bae3ab960 (stream Message writer)
2017-04-27 14:14:25.363225 I | etcdserver: published {Name:s1 ClientURLs:[http://localhost:2379]} to cluster a9ededbffcb1b1f1
验证每个成员,然后整个集群,使用新的 v3.2 etcd 二进制文件后是否健康:
$ ETCDCTL_API=3 /etcdctl endpoint health --endpoints=localhost:2379,localhost:22379,localhost:32379
localhost:22379 is healthy: successfully committed proposal: took = 5.540129ms
localhost:32379 is healthy: successfully committed proposal: took = 7.321771ms
localhost:2379 is healthy: successfully committed proposal: took = 10.629901ms
2017-04-27 14:15:17.071804 W | etcdserver: member c89feb932daef420 has a higher version 3.2.0
2017-04-27 14:15:21.073110 W | etcdserver: the local etcd version 3.1.7 is not up-to-date
2017-04-27 14:15:21.073142 W | etcdserver: member 6d4f535bae3ab960 has a higher version 3.2.0
2017-04-27 14:15:21.073157 W | etcdserver: the local etcd version 3.1.7 is not up-to-date
2017-04-27 14:15:21.073164 W | etcdserver: member c89feb932daef420 has a higher version 3.2.0
4. 重复第 2 步到第 3 步,对所有其他成员执行
5. 完成
所有成员升级完成后,集群将成功报告升级至 3.2:
2017-04-27 14:15:54.536901 N | etcdserver/membership: updated the cluster version from 3.1 to 3.2
2017-04-27 14:15:54.537035 I | etcdserver/api: enabled capabilities for version 3.2
$ ETCDCTL_API=3 /etcdctl endpoint health --endpoints=localhost:2379,localhost:22379,localhost:32379
localhost:2379 is healthy: successfully committed proposal: took = 2.312897ms
localhost:22379 is healthy: successfully committed proposal: took = 2.553476ms
localhost:32379 is healthy: successfully committed proposal: took = 2.517902ms