forked from grpc/grpc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server should send 2 goaway messages to gracefully shutdown the connection. (grpc#1403) * First commit. * Basic implementation * Server should send two GoAways to gracefully shutdown the connection. * mend * Post-review updates * Fixed issue after rebase * Fixing typo Add balancer, resolver and connectivity package. add balancer_v1_wrapper.go and remove grpclb.go all test passed, how? end2end passed, nil pointer failure, ac.wait return nil transport fix ac.wait return nil transport, races not fixed (accessing cc.balancer) end2end passed, TODO grpclb all test passed add grpclb back move building balancer out from a goroutine to avoid race Otherwise, Dial() and Close() may race. Mark new APIs experimental split resetAddrConn into newAddrConn and connect add acBalancerWrapper rename file to balancer_conn_wrappers.go remove grpclog.Print make TODO(bar) remove Print comments fixes add missing license fix build failure after merge fix race in grpclb Update comments for balancer and resolver, and rename SubConnection to SubConn Add balancer, resolver and connectivity package. all test passed, how?
- Loading branch information
Showing
3 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package grpc | ||
|
||
import ( | ||
"google.golang.org/grpc/balancer" | ||
"google.golang.org/grpc/connectivity" | ||
"google.golang.org/grpc/grpclog" | ||
"google.golang.org/grpc/resolver" | ||
) | ||
|
||
////////////////////////////////////////////////////////////////////////////// | ||
////////////////////// To b or not to b. ///////////////////////// | ||
////////////////////////////////////////////////////////////////////////////// | ||
|
||
// newSubConnection adds a new addrConn to clientconn, and returns a wrapper | ||
// subConn for balancer. | ||
func (cc *ClientConn) newSubConnection(addrs []resolver.Address, opts balancer.NewSubConnectionOptions) (*addrConn, error) { | ||
grpclog.Printf("creating new subconn, addrs[0]: %v\n", addrs[0]) | ||
ac, err := cc.resetAddrConn(addrs[0], false, nil) | ||
if err != nil { | ||
// TODO what to do? | ||
grpclog.Printf("neverrrrrrrr got err when resetting addrconn %v", err) | ||
return nil, err | ||
} | ||
return ac, nil | ||
} | ||
|
||
// removeSubConnection removes the addrConn in the subConn from clientConn. | ||
// It also tears down the ac with the given error. | ||
func (cc *ClientConn) removeSubConnection(ac *addrConn, err error) { | ||
grpclog.Printf("removing new subconn") | ||
cc.mu.Lock() | ||
delete(cc.conns, ac) | ||
cc.mu.Unlock() | ||
ac.tearDown(err) | ||
} | ||
|
||
func (cc *ClientConn) updatePicker(p balancer.Picker) { | ||
grpclog.Printf("cc.updatePicker: %p", p) | ||
// TODO add a goroutine and sync it. | ||
cc.pmu.Lock() | ||
cc.picker = p | ||
cc.pmu.Unlock() | ||
} | ||
|
||
// ccBalancerWrapper is a wrapper on top of cc for balancers. | ||
// It implements balancer.ClientConnection interface. | ||
type ccBalancerWrapper struct { | ||
cc *ClientConn | ||
} | ||
|
||
func (ccb *ccBalancerWrapper) NewSubConnection(addrs []resolver.Address, opts balancer.NewSubConnectionOptions) (balancer.SubConnection, error) { | ||
return ccb.cc.newSubConnection(addrs, opts) | ||
} | ||
|
||
func (ccb *ccBalancerWrapper) RemoveSubConnection(sc balancer.SubConnection) { | ||
ac, ok := sc.(*addrConn) | ||
if !ok { | ||
// TODO log or error? | ||
return | ||
} | ||
ccb.cc.removeSubConnection(ac, errConnClosing) | ||
} | ||
|
||
func (ccb *ccBalancerWrapper) UpdateBalancerState(s connectivity.State, p balancer.Picker) { | ||
ccb.cc.updatePicker(p) | ||
} | ||
|
||
func (ccb *ccBalancerWrapper) Target() string { | ||
return ccb.cc.target | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////////// | ||
////////////////////// To a or not to a. ///////////////////////// | ||
////////////////////////////////////////////////////////////////////////////// | ||
|
||
func (ac *addrConn) UpdateAddresses([]resolver.Address) {} | ||
|
||
func (ac *addrConn) Connect() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters