Commit Graph

219 Commits

Author SHA1 Message Date
ZHANG Dapeng 1086ee89c1
grpclb,xds: fix code lint 2020-04-02 18:18:32 -07:00
Eric Anderson 103c33e821 services,grpclb: Filter internal files from javadoc/jacoco 2020-04-02 08:57:31 -07:00
Jihun Cho 6dbdfcdbbc
grpclb: CachedSubchannelPool use new create subchannel (#6831) 2020-03-31 13:31:04 -07:00
Chengyuan Zhang ec25beb660
grpclb: clean up usage of raw load balancing config attributes in tests (#6798) 2020-03-03 09:52:12 -08:00
Chengyuan Zhang afc1f2e567
core, grpclb: clean up grpclb specific attributes in core (#6790)
Move ATTR_LB_ADDR_AUTHORITY and ATTR_LB_PROVIDED_BACKEND attributes definition in GrpcAttributes to GrpclbConstants. grpc-alts will have a compile dependency on grpc-grpclb.
2020-03-02 10:27:57 -08:00
Chengyuan Zhang 6a7e47b8a5
core, grpclb: change policy selection strategy for Grpclb policy (take two: move logic of querying SRV into Grpclb's own resolver) (#6723)
Eliminated the code path of resolving Grpclb balancer addresses in grpc-core and moved it into GrpclbNameResolver, which is a subclass of DnsNameResolver. Main changes:

- Slightly changed ResourceResolver and its JNDI implementation. ResourceResolver#resolveSrv(String) returns a list of SrvRecord so that it only parse SRV records and does nothing more. It's gRPC's name resolver's logic to use information parsed from SRV records.

- Created a GrpclbNameResolver class that extends DnsNameResolver. Logic of using information from SRV records to set balancer addresses as ResolutionResult attributes is implemented in GrpclbNameResolver only.

- Refactored DnsNameResolver, mainly the resolveAll(...) method. Logics for resolving backend addresses and service config are modularized into resolveAddresses() and resolveServiceConfig() methods respectively. They are shared implementation for subclasses (i.e., GrpclbNameResolver).
2020-03-02 01:03:25 -08:00
Jihun Cho 4b201267c6
grpclb: add description to lb sends no backends status (#6751) 2020-02-25 11:05:36 -08:00
Jihun Cho abed707385
grpclb: handles empty address from LB (#6734) 2020-02-21 10:55:57 -08:00
Jihun Cho 774f2763c9
grpclb: add serviceName config to grpclb policy config (#6563) 2020-02-11 10:27:47 -08:00
Eric Anderson 255e5feb24 Sync grpc-proto to 1ff78907
This noticed that load_balancer.proto had local changes introduced
in #6549. This was not noticed by Bazel because grpclb was not using
the io_grpc_grpc_proto repository. These issues have been fixed.
2020-02-10 12:32:39 -08:00
Chengyuan Zhang e0ee52cc22
grpclb: fix lint warnings (#6670) 2020-02-03 10:34:30 -08:00
Chengyuan Zhang 295b64b5ff
grpclb: expose balancer address related attributes in internal accessor (#6669) 2020-01-31 17:50:04 -08:00
Chengyuan Zhang 26bff62ff3
grpclb: internal accessor for balancer address related attribute keys (#6667)
Creates an internal accessor for attribute keys in grpclb package that is used by name resolver implementations to set balancer addresses as name resolution result attributes.
2020-01-31 15:44:30 -08:00
Jihun Cho 307f7d0e09
grpclb,xds: fix lint warnings (#6666) 2020-01-31 11:32:26 -08:00
Chengyuan Zhang c0f37e59ab
core, grpclb: change policy selection strategy for Grpclb policy (take one: eliminate special logic for deciding grpclb policy in core) (#6637)
First take for grpclb selection stabilization: 

1. Changed DnsNameResolver to return balancer addresses as a GrpcAttributes.ATTR_LB_ADDRS attribute in ResolutionResult, instead of among the addresses.

2. AutoConfiguredLoadBalancerFactory decides LB policy solely based on parsed service config without looking at resolved addresses. Behavior changes:
  - If no LB policy is specified in service config, default to pick_first, even if there exist balancer addresses (in attributes).
  - If grpclb specified but not available and no other specified policies available, it will fail without fallback to round_robin.

3. GrpclbLoadBalancer populates balancer addresses from ResolvedAddresses's attribute (GrpclbConstants.ATTR_LB_ADDRS) instead of sieving from addresses.
2020-01-31 10:41:43 -08:00
Jihun Cho 2acca6ea3b
all: fix lint warnings (#6658) 2020-01-30 10:00:39 -08:00
ZHANG Dapeng 64e827d996
grpclb,xds: fix parseLoadBalancingConfigPolicy error message format 2020-01-28 13:08:05 -08:00
ZHANG Dapeng 1ed538f253
all: log picker when updating balancing state
Let `ManagedChannelImpl` log picker update when updating balancing state.
2020-01-28 09:55:04 -08:00
Jihun Cho 641d74f34f
grpclb: support explicit fallback from LB (#6549) 2020-01-10 13:54:43 -08:00
Jihun Cho 90969b3471
core: make service config error handling optional implementation (#6564) 2019-12-26 15:07:20 -08:00
Eric Anderson 1f64ac94a8 Revert "grpclb: shuffle pick first index"
This reverts commit 1949ebd7ef.

The shuffling should be handled by the grpclb server instead.
2019-12-13 13:20:51 -08:00
Tomo Suzuki 29638780ae build: Replaced outdated comments (#6492) 2019-12-05 13:53:51 -08:00
Jihun Cho 7db873f1f6
Roll-forward of stub,compiler: generated stub extends Abstract{Async,Future,Blocking}Stub #6196 (#6458)
This reverts commit 2eb3f8c34e (#6317).
2019-11-25 09:41:16 -08:00
ZHANG Dapeng 38952b0b38
grpclb: cancel stream instead of halfClose when balancer shutdown
Previously, if the remote balancer doesn't close the stream after receiving the half-close, the OOB channel will hang there forever. It's safer to always cancel on the client-side so that the OOB channel can be cleaned up timely, regardless of what the remote balancer does.
2019-10-23 12:05:24 -07:00
ZHANG Dapeng b009e92156
xds: Bump perfmark to 0.19.0
Resolves #6217
2019-10-22 16:55:39 -07:00
Jihun Cho 2eb3f8c34e
stub,compiler: Rollback Abstract{Future,Blocking,Async}Stub (#6317)
rollback of #6304 & #6196
2019-10-22 13:27:30 -07:00
Jihun Cho eef47b26b8
core,grpclb: DnsNameResolver will use srv record by default if grpclb (#6298) 2019-10-18 13:00:47 -07:00
Jihun Cho 45d49a56cc
stub,compiler: generated stub extends Abstract{Async,Future,Blocking}Stub (#6196) 2019-10-17 14:49:24 -07:00
Eric Anderson 024a46bd11
bazel: Support --incompatible_load_proto_rules_from_bzl
This flag will be enabled by default in Bazel 1.0

Since I changed the grpc-proto repo version for Bazel, I also synced the
protos.
2019-10-09 14:46:17 -07:00
Eric Anderson 4215b80b81 Apply java plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson e13221b503 Apply japicmp plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson 5b838e5284 Apply maven-publish plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson 3c3a823a81 Swap to Gradle's Plugin DSL for much of build
Examples and android projects were left unchanged. They can be changed
later.

No plugin versions were changed, to make this as non-functional of a
change as possible. Upgrading Gradle to 5.6 was necessary for
pluginManagement in settings.gradle.
2019-09-13 09:42:17 -07:00
Kun Zhang 2c0b2de862
grpclb: fix pick_first mode shutdown without subchannels. (#6072) 2019-08-16 10:21:25 -07:00
ZHANG Dapeng 1949ebd7ef
grpclb: shuffle pick first index
Each new instance of GrpcLbBalancer will have a different pick first index.
2019-08-12 17:07:23 -07:00
liym 47b11ab7a1 compiler: Use 'SERVICE_NAME' instead of duplicated '$Package$$service… (#5943)
* compiler: Use 'SERVICE_NAME' instead of duplicated '$Package$$service_name$'

* compiler: Align indentation

* Fix typo

* Add modified golden files and all re-generated code to meet Travis CI and Windows build requirements

See PR #5943

* Polishing
2019-07-24 10:37:13 -07:00
Kun Zhang af2c16d301
api: deprecate Helper.updateSubchannelAddresses() and add equivalent on Subchannel (#5802)
Resolves #5676
2019-05-30 09:16:38 -07:00
Tim van der Lippe ad0893737e Migrate org.mockito.Matchers#any* to org.mockito.ArgumentMatchers
The former is deprecated and replaced by the latter in Mockito 2.
However, there is a functional difference: ArgumentMatchers will reject
`null` and check the type if the matcher specified a type (e.g.
`any(Class)` or `anyInt()`). `any()` will remain to accept anything.
2019-05-29 16:53:01 -07:00
Kun Zhang a2595d9e7d
api/core/grpclb: add warning about calling Subchannel.requestConnection() outside of sync-context (#5757)
The pick_first policies in core and grpclb previously would call
Subchannel.requestConnection() from data-path.  They now will schedule
that call in the sync-context to avoid the warning.  They will only
call it for the first pick of each picker, to prevent storming the
sync-context.
2019-05-20 11:39:02 -07:00
Kun Zhang 7934594dfe
api: pass Subchannel state updates to SubchannelStateListener rather than LoadBalancer (take 2) (#5722)
This is a revised version of #5503 (62b03fd), which was rolled back in f8d0868. The newer version passes SubchannelStateListener to Subchannel.start() instead of SubchannelCreationArgs, which allows us to remove the Subchannel argument from the listener, which works as a solution for #5676.

LoadBalancers that call the old createSubchannel() will get start() implicitly called with a listener that passes updates to the deprecated LoadBalancer.handleSubchannelState(). Those who call the new createSubchannel() will have to call start() explicitly.

GRPCLB code is still using the old API, because it's a pain to migrate the SubchannelPool to the new API.  Since CachedSubchannelHelper is on the way, it's easier to switch to it when it's ready. Keeping
GRPCLB with the old API would also confirm the backward compatibility.
2019-05-17 16:37:41 -07:00
Kun Zhang cec9ee368d
api: move SubchannelPicker.requestConnection() to LoadBalancer. (#5751)
We will require Subchannel.requestConnection() to be called from
sync-context (#5722), but SubchannelPicker.requestConnection() is
currently calling it with the assumption of thread-safety.  Actually
SubchannelPicker.requestConnection() is called already from
sync-context by ChannelImpl, it makes more sense to move this method
to LoadBalancer where all other methods are sync-context'ed, rather than
making SubchannelPicker.requestConnection() sync-context'ed and fragmenting
the SubchannelPicker API because pickSubchannel() is thread-safe.

C++ also has the requestConnection() equivalent on their LoadBalancer
interface.
2019-05-16 09:50:23 -07:00
Kun Zhang f8d0868e1d
Revert "core: pass Subchannel state updates to SubchannelStateListener rather than LoadBalancer (#5503)" (#5684)
This reverts commit 62b03fd7e6.

Effectively reverts its follow-up commits:
dc218b6d4d
405d8c3865
44840fe813
2019-05-08 09:01:45 -07:00
Eric Anderson ab2e048f13 Lint fixes for unused and Truth and Queue 2019-04-30 22:44:00 -07:00
Kun Zhang 973885457f
core: change ClientStreamTracer.StreamInfo to a final class with a builder (#5648)
As we are now endorsing the wrapping of ClientStreamTracers by
providing ForwardingClientStreamTracer, there is a need for altering
StreamInfo, especially CallOptions before it's passed onto the
delegate.  A Builder class and a toBuilder() provides a robust way
to copy the rest of the fields.

This is a breaking change for anybody who creates StreamInfo, which is
unlikely in non-test code, because StreamInfo was added as late as
1.20.0.
2019-04-30 09:10:56 -07:00
Carl Mastrangelo 04e07034f3
all: update to truth 0.44 2019-04-23 10:50:49 -07:00
Kun Zhang 39e66fa22b
core: delete ManagedChannelBuilder.loadBalancerFactory() and all deprecated factories (#5480)
This has been deprecated since 1.18.0
2019-04-17 14:46:19 -07:00
Carl Mastrangelo a395eec4a3
core: update LB and NR API names
Updates #1770
2019-04-17 12:45:29 -07:00
Eric Anderson 80c3c992a6 core: Move io.grpc to grpc-api
io.grpc has fewer dependencies than io.grpc.internal. Moving it to a
separate artifact lets users use the API without bringing in the deps.
If the library has an optional dependency on grpc, that can be quite
convenient.

We now version-pin both grpc-api and grpc-core, since both contain
internal APIs.

I had to change a few tests in grpc-api to avoid FakeClock. Moving
FakeClock to grpc-api was difficult because it uses
io.grpc.internal.TimeProvider, which can't be moved since it is a
production class. Having grpc-api's tests depend on grpc-core's test
classes would be weird and cause a circular dependincy. Having
grpc-api's tests depend on grpc-core is likely possible, but weird and
fairly unnecessary at this point. So instead I rewrote the tests to
avoid FakeClock.

Fixes #1447
2019-04-16 21:45:40 -07:00
Kun Zhang 62b03fd7e6
core: pass Subchannel state updates to SubchannelStateListener rather than LoadBalancer (#5503)
Resolves #5497

## Motivation

In hierarchical `LoadBalancer`s (e.g., `XdsLoadBalancer`) or wrapped `LoadBalancer`s (e.g., `HealthCheckingLoadBalancerFactory`, the top-level `LoadBalancer` receives `Subchannel` state updates from the Channel impl, and they almost always pass it down to its children `LoadBalancer`s.

Sometimes the children `LoadBalancer`s are not directly created by the parent, thus requires whatever API in the middle to also pass Subchannel state updates, complicating that API. For example, the proposed [`RequestDirector`](https://github.com/grpc/grpc-java/issues/5496#issuecomment-476008051) includes `handleSubchannelState()` solely to plumb state updates to where they are used. We also see this pattern in `HealthCheckingLoadBalancerFactory`, `GrpclbState` and `SubchannelPool`.

Another minor issue is, the parent `LoadBalancer` would need to intercept the `Helper` passed to its children to map Subchannels to the children `LoadBalancer`s, so that it pass updates about relevant Subchannels to the children.  Otherwise, a child `LoadBalancer` may be surprised by seeing Subchannel not created by it, and it's not efficient to broadcast Subchannel updates to all children.

## API Proposal
We will pass a `SubchannelStateListener` when creating a `Subchannel` to accept state updates, those updates could be directly passed to where the `Subchannel` is created, skipping the explicit chaining in the middle.

Also define a first-class object `CreateSubchannelArgs` to pass arguments for the reasons below:
1. It may avoid breakages when we add new arguments to `createSubchannel()`.  For example, a `LoadBalancer` may wrap `Helper` and intercept `createSubchannel()` in a hierarchical case. It may not be interested in all arguments. Passing a single `CreateSubchannelArgs` will not break the parent `LoadBalancer` if we add new fields later.
2. This also reduces the eventual size of Helper interface, as the convenience `createSubchannel()` that accepts one EAG instead of a List is no longer necessary, since that convenience is moved into `CreateSubchannelArgs`.

```java
interface SubchannelStateListener {
  void onSubchannelState(Subchannel subchannel, ConnectivityStateInfo newState);
}

abstract class LoadBalancer.Helper {
  abstract Subchannel createSubchannel(CreateSubchannelArgs args);
}

final class CreateSubchannelArgs {
  final List<EquivalentAddressGroup> getAddresses();
  final Attributes getAttributes();
  final SubchannelStateListener getStateListener();
  final class Builder () {
    ...
  }
}
```

The new `createSubchannel()` must be called from synchronization context, as a step towards #5015.

## How the new API helps

Most hierarchical `LoadBalancer`s would just let the listener from the child `LoadBalancer`s directly pass through to gRPC core, which is less boilerplate than before.

Without any effort by the parent, each child will only see updates for the Subchannels it has created, which is clearer and more efficient.

If a parent `LoadBalancer` does want to look at or alter the Subchannel state updates for its delegate (like in `HealthCheckingLoadBalancerFactory`), it can still do so in the wrapping `LoadBalancer.Helper` passed to the delegate by intercepting the `SubchannelStateListener`.

## Migration implications
Existing `LoadBalancer` implementations will continue to work, while they will see deprecation warnings when compiled:
 - The old `LoadBalancer.Helper#createSubchannel` variants are now deprecated, but will work until they are deleted. They create a `SubchannelStateListener` that delegates to `LoadBalancer#handleSubchannelState`.
 - `LoadBalancer#handleSubchannelState` is now deprecated, and will throw if called and the implementation doesn't override it. It will be deleted in a future release.

The migration for most `LoadBalancer` implementation would be moving the logic from `LoadBalancer#handleSubchannelState` into a `SubchannelStateListener`.
2019-04-12 10:58:09 -07:00
Kun Zhang 0244418d2d
core: Move ConfigOrError up level up. (#5578)
This class is used in other places than just NameResolver.Helper.  It
should not be an inner class of Helper.

Strictly speaking this is an API-breaking change.  However, this is
part of the service config error handling API that hasn't been done
yet.  Nobody has a legitimate reason to use it.
2019-04-10 16:28:23 -07:00