VOL-2112 move to voltha-lib-go
Change-Id: Ic1af08003c1d2c698c0cce371e64f47b47b8d875
diff --git a/vendor/google.golang.org/grpc/resolver_conn_wrapper.go b/vendor/google.golang.org/grpc/resolver_conn_wrapper.go
index 50991ea..6934905 100644
--- a/vendor/google.golang.org/grpc/resolver_conn_wrapper.go
+++ b/vendor/google.golang.org/grpc/resolver_conn_wrapper.go
@@ -21,6 +21,7 @@
import (
"fmt"
"strings"
+ "sync/atomic"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/channelz"
@@ -30,12 +31,12 @@
// ccResolverWrapper is a wrapper on top of cc for resolvers.
// It implements resolver.ClientConnection interface.
type ccResolverWrapper struct {
- cc *ClientConn
- resolver resolver.Resolver
- addrCh chan []resolver.Address
- scCh chan string
- done chan struct{}
- lastAddressesCount int
+ cc *ClientConn
+ resolver resolver.Resolver
+ addrCh chan []resolver.Address
+ scCh chan string
+ done uint32 // accessed atomically; set to 1 when closed.
+ curState resolver.State
}
// split2 returns the values from strings.SplitN(s, sep, 2).
@@ -82,7 +83,6 @@
cc: cc,
addrCh: make(chan []resolver.Address, 1),
scCh: make(chan string, 1),
- done: make(chan struct{}),
}
var err error
@@ -99,57 +99,70 @@
func (ccr *ccResolverWrapper) close() {
ccr.resolver.Close()
- close(ccr.done)
+ atomic.StoreUint32(&ccr.done, 1)
}
-// NewAddress is called by the resolver implemenetion to send addresses to gRPC.
-func (ccr *ccResolverWrapper) NewAddress(addrs []resolver.Address) {
- select {
- case <-ccr.done:
+func (ccr *ccResolverWrapper) isDone() bool {
+ return atomic.LoadUint32(&ccr.done) == 1
+}
+
+func (ccr *ccResolverWrapper) UpdateState(s resolver.State) {
+ if ccr.isDone() {
return
- default:
+ }
+ grpclog.Infof("ccResolverWrapper: sending update to cc: %v", s)
+ if channelz.IsOn() {
+ ccr.addChannelzTraceEvent(s)
+ }
+ ccr.cc.updateResolverState(s)
+ ccr.curState = s
+}
+
+// NewAddress is called by the resolver implementation to send addresses to gRPC.
+func (ccr *ccResolverWrapper) NewAddress(addrs []resolver.Address) {
+ if ccr.isDone() {
+ return
}
grpclog.Infof("ccResolverWrapper: sending new addresses to cc: %v", addrs)
if channelz.IsOn() {
- ccr.addChannelzTraceEvent(addrs)
+ ccr.addChannelzTraceEvent(resolver.State{Addresses: addrs, ServiceConfig: ccr.curState.ServiceConfig})
}
- ccr.cc.handleResolvedAddrs(addrs, nil)
+ ccr.curState.Addresses = addrs
+ ccr.cc.updateResolverState(ccr.curState)
}
-// NewServiceConfig is called by the resolver implemenetion to send service
+// NewServiceConfig is called by the resolver implementation to send service
// configs to gRPC.
func (ccr *ccResolverWrapper) NewServiceConfig(sc string) {
- select {
- case <-ccr.done:
+ if ccr.isDone() {
return
- default:
}
grpclog.Infof("ccResolverWrapper: got new service config: %v", sc)
- ccr.cc.handleServiceConfig(sc)
+ c, err := parseServiceConfig(sc)
+ if err != nil {
+ return
+ }
+ if channelz.IsOn() {
+ ccr.addChannelzTraceEvent(resolver.State{Addresses: ccr.curState.Addresses, ServiceConfig: c})
+ }
+ ccr.curState.ServiceConfig = c
+ ccr.cc.updateResolverState(ccr.curState)
}
-func (ccr *ccResolverWrapper) addChannelzTraceEvent(addrs []resolver.Address) {
- if len(addrs) == 0 && ccr.lastAddressesCount != 0 {
- channelz.AddTraceEvent(ccr.cc.channelzID, &channelz.TraceEventDesc{
- Desc: "Resolver returns an empty address list",
- Severity: channelz.CtWarning,
- })
- } else if len(addrs) != 0 && ccr.lastAddressesCount == 0 {
- var s string
- for i, a := range addrs {
- if a.ServerName != "" {
- s += a.Addr + "(" + a.ServerName + ")"
- } else {
- s += a.Addr
- }
- if i != len(addrs)-1 {
- s += " "
- }
- }
- channelz.AddTraceEvent(ccr.cc.channelzID, &channelz.TraceEventDesc{
- Desc: fmt.Sprintf("Resolver returns a non-empty address list (previous one was empty) %q", s),
- Severity: channelz.CtINFO,
- })
+func (ccr *ccResolverWrapper) addChannelzTraceEvent(s resolver.State) {
+ var updates []string
+ oldSC, oldOK := ccr.curState.ServiceConfig.(*ServiceConfig)
+ newSC, newOK := s.ServiceConfig.(*ServiceConfig)
+ if oldOK != newOK || (oldOK && newOK && oldSC.rawJSONString != newSC.rawJSONString) {
+ updates = append(updates, "service config updated")
}
- ccr.lastAddressesCount = len(addrs)
+ if len(ccr.curState.Addresses) > 0 && len(s.Addresses) == 0 {
+ updates = append(updates, "resolver returned an empty address list")
+ } else if len(ccr.curState.Addresses) == 0 && len(s.Addresses) > 0 {
+ updates = append(updates, "resolver returned new addresses")
+ }
+ channelz.AddTraceEvent(ccr.cc.channelzID, &channelz.TraceEventDesc{
+ Desc: fmt.Sprintf("Resolver state updated: %+v (%v)", s, strings.Join(updates, "; ")),
+ Severity: channelz.CtINFO,
+ })
}