*:update dependencies

release-3.0
Xiang Li 2016-04-13 10:42:25 -07:00
parent 35d2d7b23e
commit 7c5ec417c3
7 changed files with 146 additions and 51 deletions

22
cmd/Godeps/Godeps.json generated
View File

@ -3,7 +3,7 @@
"GoVersion": "go1.6",
"GodepVersion": "v60",
"Packages": [
"./cmd/..."
"./..."
],
"Deps": [
{
@ -109,7 +109,7 @@
},
{
"ImportPath": "github.com/mattn/go-runewidth",
"Comment": "v0.0.1",
"Comment": "travisish-46-gd6bea18",
"Rev": "d6bea18f789704b5f83375793155289da36a3c7f"
},
{
@ -209,39 +209,39 @@
},
{
"ImportPath": "google.golang.org/grpc",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "google.golang.org/grpc/codes",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "google.golang.org/grpc/credentials",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "google.golang.org/grpc/grpclog",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "google.golang.org/grpc/internal",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "google.golang.org/grpc/metadata",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "google.golang.org/grpc/naming",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "google.golang.org/grpc/peer",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "google.golang.org/grpc/transport",
"Rev": "e3d8dfd9076c03272c6e3c7a0ac8671a0e0b374e"
"Rev": "9ac074585f926c8506b6351bfdc396d2b19b1cb1"
},
{
"ImportPath": "gopkg.in/cheggaaa/pb.v1",

68
cmd/vendor/google.golang.org/grpc/backoff.go generated vendored Normal file
View File

@ -0,0 +1,68 @@
package grpc
import (
"math/rand"
"time"
)
// DefaultBackoffConfig uses values specified for backoff in
// https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md.
var (
DefaultBackoffConfig = &BackoffConfig{
MaxDelay: 120 * time.Second,
baseDelay: 1.0 * time.Second,
factor: 1.6,
jitter: 0.2,
}
)
// backoffStrategy defines the methodology for backing off after a grpc
// connection failure.
//
// This is unexported until the GRPC project decides whether or not to allow
// alternative backoff strategies. Once a decision is made, this type and its
// method may be exported.
type backoffStrategy interface {
// backoff returns the amount of time to wait before the next retry given
// the number of consecutive failures.
backoff(retries int) time.Duration
}
// BackoffConfig defines the parameters for the default GRPC backoff strategy.
type BackoffConfig struct {
// MaxDelay is the upper bound of backoff delay.
MaxDelay time.Duration
// TODO(stevvooe): The following fields are not exported, as allowing changes
// baseDelay is the amount of time to wait before retrying after the first
// failure.
baseDelay time.Duration
// factor is applied to the backoff after each retry.
factor float64
// jitter provides a range to randomize backoff delays.
jitter float64
}
func (bc *BackoffConfig) backoff(retries int) (t time.Duration) {
if retries == 0 {
return bc.baseDelay
}
backoff, max := float64(bc.baseDelay), float64(bc.MaxDelay)
for backoff < max && retries > 0 {
backoff *= bc.factor
retries--
}
if backoff > max {
backoff = max
}
// Randomize backoff delays so that if a cluster of requests start at
// the same time, they won't operate in lockstep.
backoff *= 1 + bc.jitter*(rand.Float64()*2-1)
if backoff < 0 {
return 0
}
return time.Duration(backoff)
}

View File

@ -75,6 +75,7 @@ type dialOptions struct {
codec Codec
cp Compressor
dc Decompressor
bs backoffStrategy
picker Picker
block bool
insecure bool
@ -114,6 +115,22 @@ func WithPicker(p Picker) DialOption {
}
}
// WithBackoffConfig configures the dialer to use the provided backoff
// parameters after connection failures.
func WithBackoffConfig(b *BackoffConfig) DialOption {
return withBackoff(b)
}
// withBackoff sets the backoff strategy used for retries after a
// failed connection attempt.
//
// This can be exported if arbitrary backoff strategies are allowed by GRPC.
func withBackoff(bs backoffStrategy) DialOption {
return func(o *dialOptions) {
o.bs = bs
}
}
// WithBlock returns a DialOption which makes caller of Dial blocks until the underlying
// connection is up. Without this, Dial returns immediately and connecting the server
// happens in background.
@ -180,6 +197,11 @@ func Dial(target string, opts ...DialOption) (*ClientConn, error) {
// Set the default codec.
cc.dopts.codec = protoCodec{}
}
if cc.dopts.bs == nil {
cc.dopts.bs = DefaultBackoffConfig
}
if cc.dopts.picker == nil {
cc.dopts.picker = &unicastPicker{
target: target,
@ -415,7 +437,7 @@ func (cc *Conn) resetTransport(closeTransport bool) error {
return ErrClientConnTimeout
}
}
sleepTime := backoff(retries)
sleepTime := cc.dopts.bs.backoff(retries)
timeout := sleepTime
if timeout < minConnectTimeout {
timeout = minConnectTimeout

View File

@ -41,9 +41,7 @@ import (
"io"
"io/ioutil"
"math"
"math/rand"
"os"
"time"
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
@ -411,38 +409,6 @@ func convertCode(err error) codes.Code {
return codes.Unknown
}
const (
// how long to wait after the first failure before retrying
baseDelay = 1.0 * time.Second
// upper bound of backoff delay
maxDelay = 120 * time.Second
// backoff increases by this factor on each retry
backoffFactor = 1.6
// backoff is randomized downwards by this factor
backoffJitter = 0.2
)
func backoff(retries int) (t time.Duration) {
if retries == 0 {
return baseDelay
}
backoff, max := float64(baseDelay), float64(maxDelay)
for backoff < max && retries > 0 {
backoff *= backoffFactor
retries--
}
if backoff > max {
backoff = max
}
// Randomize backoff delays so that if a cluster of requests start at
// the same time, they won't operate in lockstep.
backoff *= 1 + backoffJitter*(rand.Float64()*2-1)
if backoff < 0 {
return 0
}
return time.Duration(backoff)
}
// SupportPackageIsVersion1 is referenced from generated protocol buffer files
// to assert that that code is compatible with this version of the grpc package.
//

View File

@ -196,6 +196,28 @@ func (f *inFlow) onData(n uint32) error {
return nil
}
// adjustConnPendingUpdate increments the connection level pending updates by n.
// This is called to make the proper connection level window updates when
// receiving data frame targeting the canceled RPCs.
func (f *inFlow) adjustConnPendingUpdate(n uint32) (uint32, error) {
if n == 0 || f.conn != nil {
return 0, nil
}
f.mu.Lock()
defer f.mu.Unlock()
if f.pendingData+f.pendingUpdate+n > f.limit {
return 0, ConnectionErrorf("received %d-bytes data exceeding the limit %d bytes", f.pendingData+f.pendingUpdate+n, f.limit)
}
f.pendingUpdate += n
if f.pendingUpdate >= f.limit/4 {
ret := f.pendingUpdate
f.pendingUpdate = 0
return ret, nil
}
return 0, nil
}
// connOnRead updates the connection level states when the application consumes data.
func (f *inFlow) connOnRead(n uint32) uint32 {
if n == 0 || f.conn != nil {

View File

@ -236,9 +236,9 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
var timeout time.Duration
if dl, ok := ctx.Deadline(); ok {
timeout = dl.Sub(time.Now())
if timeout <= 0 {
return nil, ContextErr(context.DeadlineExceeded)
}
}
if err := ctx.Err(); err != nil {
return nil, ContextErr(err)
}
pr := &peer.Peer{
Addr: t.conn.RemoteAddr(),
@ -571,11 +571,19 @@ func (t *http2Client) updateWindow(s *Stream, n uint32) {
func (t *http2Client) handleData(f *http2.DataFrame) {
// Select the right stream to dispatch.
size := len(f.Data())
s, ok := t.getStream(f)
if !ok {
cwu, err := t.fc.adjustConnPendingUpdate(uint32(size))
if err != nil {
t.notifyError(err)
return
}
if cwu > 0 {
t.controlBuf.put(&windowUpdate{0, cwu})
}
return
}
size := len(f.Data())
if size > 0 {
if err := s.fc.onData(uint32(size)); err != nil {
if _, ok := err.(ConnectionError); ok {

View File

@ -318,11 +318,20 @@ func (t *http2Server) updateWindow(s *Stream, n uint32) {
func (t *http2Server) handleData(f *http2.DataFrame) {
// Select the right stream to dispatch.
size := len(f.Data())
s, ok := t.getStream(f)
if !ok {
cwu, err := t.fc.adjustConnPendingUpdate(uint32(size))
if err != nil {
grpclog.Printf("transport: http2Server %v", err)
t.Close()
return
}
if cwu > 0 {
t.controlBuf.put(&windowUpdate{0, cwu})
}
return
}
size := len(f.Data())
if size > 0 {
if err := s.fc.onData(uint32(size)); err != nil {
if _, ok := err.(ConnectionError); ok {