Skip to content

Commit

Permalink
remove transportSeq
Browse files Browse the repository at this point in the history
  • Loading branch information
iamqizhao committed Sep 22, 2015
1 parent 66a18cf commit dd992b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
3 changes: 1 addition & 2 deletions call.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
Delay: false,
}
var (
ts int // track the transport sequence number
lastErr error // record the error that happened
)
for {
Expand All @@ -155,7 +154,7 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
if lastErr != nil && c.failFast {
return toRPCErr(lastErr)
}
t, ts, err = cc.wait(ctx, ts)
t, err = cc.wait(ctx)
if err != nil {
if lastErr != nil {
// This was a retry; return the error from the last attempt.
Expand Down
16 changes: 7 additions & 9 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,17 @@ func (cc *ClientConn) transportMonitor() {
}

// When wait returns, either the new transport is up or ClientConn is
// closing. Used to avoid working on a dying transport. It updates and
// returns the transport and its version when there is no error.
func (cc *ClientConn) wait(ctx context.Context, ts int) (transport.ClientTransport, int, error) {
// closing.
func (cc *ClientConn) wait(ctx context.Context) (transport.ClientTransport, error) {
for {
cc.mu.Lock()
switch {
case cc.state == Shutdown:
cc.mu.Unlock()
return nil, 0, ErrClientConnClosing
case ts < cc.transportSeq:
// Worked on a dying transport. Try the new one immediately.
defer cc.mu.Unlock()
return cc.transport, cc.transportSeq, nil
return nil, ErrClientConnClosing
case cc.state == Ready:
cc.mu.Unlock()
return cc.transport, nil
default:
ready := cc.ready
if ready == nil {
Expand All @@ -425,7 +423,7 @@ func (cc *ClientConn) wait(ctx context.Context, ts int) (transport.ClientTranspo
cc.mu.Unlock()
select {
case <-ctx.Done():
return nil, 0, transport.ContextErr(ctx.Err())
return nil, transport.ContextErr(ctx.Err())
// Wait until the new transport is ready or failed.
case <-ready:
}
Expand Down
2 changes: 1 addition & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
}
cs.traceInfo.tr.LazyLog(&cs.traceInfo.firstLine, false)
}
t, _, err := cc.wait(ctx, 0)
t, err := cc.wait(ctx)
if err != nil {
return nil, toRPCErr(err)
}
Expand Down

0 comments on commit dd992b3

Please sign in to comment.