This PR splits out grpclb from grpc. I have made the PR in several commits so you can see more clearly the steps that happened.
There are a few possibly contentious points that I would like to make clear up front:
* grpclb will no longer autoload as a load balancer. I think this is okay, as service config is not widely (at all?) used, and I believe this is the only way to access it.
* `internal` is used more, as a way of having code shared between packages without exposing types
* ConnectivityStateEvaluator, as used by grpclb, is no longer thread safe. I believe there is an outer mutex that guards access, but I want to point out this subtle change up here.
All but one tests pass with this, due to another cyclic dependency. I can fix this, but it is a little more widely scoped (such as exposing grpc.server and grpc.errorDesc in the internal package). This PR is a nearly-passing sample of that last step to get this working.
PTAL @menghanl @dfawley
WithBalancerName dial option specifies the name of the balancer to be used by the ClientConn. Service config updates can NOT override the balancer option.
* initial dns resolver impl
* add srv lookup
* more srv
* change from string to Update
* added port handling
* a complete draft for dns resovler except the polling mechanism
* added sleep to infrequently poll the DNS server
* commented out test case since they are not portable
* remove duplicate declaration/definition in grpclb
* change namespace for grpclb structures
* goimports gofmt
* fix sorting issue
* implement sort.Interface
* different sort implementation for different go version
* add missing files
* fix missing comments
* handle err
* fix comments: unexport dnsResolver and dnsWatcher, add chan to exit Next(), add freq to control polling frequency
* enhance target string handling, add static IPWatcher, add mock test
* debug travis
* disable real address resolver test, since travis return 3 resolved IPs, 2 of them are duplicates
* shorten test time by reduce sleep time in TestIPWatcher, since it doesn't really do the DNS round trip
* resolve data race
* resolve data race using waitgroup
* reimplement setHostPort, compileUpdate, unexport ipWatcher
* delete sort related stuff, fix close bug for Next(), fix compileUpdate bug(change to map[Update]bool, plus fix minor review comments
* fix minor test case
* minor change to Next()
* use net.DefaultResolver with context as input
* add different build rules for lookupHost and lookupSRV
* minor fix
* go1.6 shall fail, but 1.7, 1.8 should pass
* go1.6 is expected to pass
* all go version should pass, added pre17 and 17 for replaceNetFunc to handle context problem
* rename test helper file name. should fix build problem
* goimports
* fix 1.7 context problem
* reformat dns_resolver_test structures
* change Next() behavior to have equal stalling interval between each lookup. Restructure dns_resolver_test.
* gofmt
* update go17_test.go, go18_test.go to reuse code. dns_resolver_test: check result and behavior correctness separately.
* update Next() logic
grpclb needs to connect the second resolved balancer address when the first balancer disconnects.
If grpclb gets 2 resolved addresses: balancer1 and balancer2. When balancer1 disconnects, grpclb should automatically start to use balancer2.
This will prevent the incoming RPCs' metadata from appearing in outgoing RPCs
unless it is explicitly copied, e.g.:
incomingMD, ok := metadata.FromContext(ctx)
if ok {
ctx = metadata.NewContext(ctx, incomingMD)
}
Fixes#1148
This modifies the WithBlock behavior somewhat to block until there is at least
one valid connection. Previously, each connection would be made serially until
all had completed successfully, with any errors returned to the caller. Errors
are now only returned due to connecting to a backend if a balancer is not used,
or if there is an error starting the balancer itself.
Fixes#976