Scott Baker | eee8dd8 | 2019-09-24 12:52:34 -0700 | [diff] [blame^] | 1 | // Copyright 2017 The etcd Authors |
| 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 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package clientv3 |
| 16 | |
| 17 | import ( |
| 18 | "math" |
| 19 | "time" |
| 20 | |
| 21 | "google.golang.org/grpc" |
| 22 | ) |
| 23 | |
| 24 | var ( |
| 25 | // client-side handling retrying of request failures where data was not written to the wire or |
| 26 | // where server indicates it did not process the data. gRPC default is default is "FailFast(true)" |
| 27 | // but for etcd we default to "FailFast(false)" to minimize client request error responses due to |
| 28 | // transient failures. |
| 29 | defaultFailFast = grpc.FailFast(false) |
| 30 | |
| 31 | // client-side request send limit, gRPC default is math.MaxInt32 |
| 32 | // Make sure that "client-side send limit < server-side default send/recv limit" |
| 33 | // Same value as "embed.DefaultMaxRequestBytes" plus gRPC overhead bytes |
| 34 | defaultMaxCallSendMsgSize = grpc.MaxCallSendMsgSize(2 * 1024 * 1024) |
| 35 | |
| 36 | // client-side response receive limit, gRPC default is 4MB |
| 37 | // Make sure that "client-side receive limit >= server-side default send/recv limit" |
| 38 | // because range response can easily exceed request send limits |
| 39 | // Default to math.MaxInt32; writes exceeding server-side send limit fails anyway |
| 40 | defaultMaxCallRecvMsgSize = grpc.MaxCallRecvMsgSize(math.MaxInt32) |
| 41 | |
| 42 | // client-side non-streaming retry limit, only applied to requests where server responds with |
| 43 | // a error code clearly indicating it was unable to process the request such as codes.Unavailable. |
| 44 | // If set to 0, retry is disabled. |
| 45 | defaultUnaryMaxRetries uint = 100 |
| 46 | |
| 47 | // client-side streaming retry limit, only applied to requests where server responds with |
| 48 | // a error code clearly indicating it was unable to process the request such as codes.Unavailable. |
| 49 | // If set to 0, retry is disabled. |
| 50 | defaultStreamMaxRetries = uint(^uint(0)) // max uint |
| 51 | |
| 52 | // client-side retry backoff wait between requests. |
| 53 | defaultBackoffWaitBetween = 25 * time.Millisecond |
| 54 | |
| 55 | // client-side retry backoff default jitter fraction. |
| 56 | defaultBackoffJitterFraction = 0.10 |
| 57 | ) |
| 58 | |
| 59 | // defaultCallOpts defines a list of default "gRPC.CallOption". |
| 60 | // Some options are exposed to "clientv3.Config". |
| 61 | // Defaults will be overridden by the settings in "clientv3.Config". |
| 62 | var defaultCallOpts = []grpc.CallOption{defaultFailFast, defaultMaxCallSendMsgSize, defaultMaxCallRecvMsgSize} |
| 63 | |
| 64 | // MaxLeaseTTL is the maximum lease TTL value |
| 65 | const MaxLeaseTTL = 9000000000 |