Repository navigation
autosharding: implementation of EndpointMap, autosharding client and LB Policy - #13039
shivaspeaks wants to merge 58 commits into
Conversation
…harding-part2-picker
…harding-part3-lazy-endpoints
|
I've added the LB policy that consumes it ( Note for updates in
|
|
I will re-request for your review after I do my final review. Please wait for the re-request @sauravzg before taking a look. |
sauravzg
left a comment
There was a problem hiding this comment.
Reviewed all of source. Some comments may be outdated since this was a large PR and I have been incrementally reviewing it for quite some time.
| */ | ||
| @Internal | ||
| public final class AutoShardingLoadBalancerProvider extends LoadBalancerProvider { | ||
| private static final String POLICY_NAME = "autosharding_experimental"; |
There was a problem hiding this comment.
nit: go/java-practices/constants#when-to-use-a-constant-versus-an-inlined-literal
| /** | ||
| * Translates {@code AutoshardingLbConfig} from its JSON form, as specified by gRFC A119. | ||
| * | ||
| * <p>The configuration is a proto3 message, so an absent string field and an empty one are the |
There was a problem hiding this comment.
Why is proto3 is relevant here if our input is a map? IIRC, proto3 when converted to json has a consistent behavior that the key is ommitted.
For us , I don't think the distinction even matters. Empty and missing are both garbage for us.
| * Translates {@code AutoshardingLbConfig} from its JSON form, as specified by gRFC A119. | ||
| * | ||
| * <p>The configuration is a proto3 message, so an absent string field and an empty one are the | ||
| * same value and no field is required. What gets rejected here is therefore a judgment call |
There was a problem hiding this comment.
The grfc should actively call out valid or invalid configurations.
We should fail as early as possible. An empty address will never connect and the config should be rejected , there's no point passing it along to the channel. I assume the same for channelFactoryKey.
Go seems to treat all of them as mandatory: https://github.com/grpc/grpc-go/blob/5ff04b66ea52b067fab16c735f330f6c2528c53a/balancer/autosharding/config.go#L46-L55
| * useful message instead of an exception. The constructor here re-checks the same constraints as | ||
| * a backstop that cannot be bypassed. | ||
| */ | ||
| final class AutoShardingLoadBalancerConfig { |
There was a problem hiding this comment.
Would this benefit from autovalue ?
| * <p>These keys are set on the resolver result by whoever is driving the policy: the | ||
| * {@code cds_experimental} LB policy in xDS deployments, or the application in non-xDS ones. | ||
| * They are internal to gRPC and carry no compatibility guarantee; the supported public API for | ||
| * configuring this policy is added separately. | ||
| * | ||
| * <p>The locality substituted for {@code %s} in {@code autosharding_target} is not injected here: | ||
| * it is read from {@link io.grpc.EquivalentAddressGroup#ATTR_LOCALITY_NAME}, and used only when |
There was a problem hiding this comment.
The docs are leaky. Docs should talk about the contract of an entity i.e. how the entity is supposed to be used , not leak how the implmentation actually uses it.
| encode(startKey), encode(endKey))); | ||
| continue; | ||
| } | ||
| if (keyOrder == 0) { |
There was a problem hiding this comment.
Merge it with >0 , with a single error message.
| * @param dropped collects a description of each slice that was dropped | ||
| */ | ||
| private static List<Assignment.Slice> dropOverlaps( | ||
| List<Assignment.Slice> sorted, List<String> dropped) { |
There was a problem hiding this comment.
similar to above, sorted , dropped , kept are very generic variable names.
| int end = index + 1; | ||
| while (end < sorted.size() && reaches(runEndKey, sorted.get(end).getStartKey())) { | ||
| byte[] endKey = sorted.get(end).getEndKey(); | ||
| if (endKey == null || UNSIGNED_BYTES_COMPARATOR.compare(endKey, runEndKey) > 0) { |
There was a problem hiding this comment.
this'll throw if runEndKey is null, which'll happen if the first entry is [x, inf) and the second entry is finite. Remember to add tests for the fix.
| } | ||
|
|
||
| /** A single {@code WatchShardingAssignment} stream. */ | ||
| private final class AutoshardingStream |
There was a problem hiding this comment.
Nit: I understand that this follows precendent from other implementations like LrsStream etc , where we have stream handle all of the lifecycle and handle call as well as observing the responses.
I'd like you to explore composition here to break down responsibilities a bit where we separate the call and callobserver side of things. I haven't thought about it but this is what I'd come up with on an initial glance.
private final class AutoshardingStream {
private final List<AssignmentChunk> bufferedChunks = new ArrayList<>();
private ClientCallStreamObserver<WatchShardingAssignmentRequest> requestStream;
private boolean receivedGoodAssignment;
private boolean closed;
void start() {
// start the call using ResponseObserver
}
void close(Status status) { ... requestStream.cancel(...); }
private final class ResponseObserver
implements ClientResponseObserver<WatchShardingAssignmentRequest,
WatchShardingAssignmentResponse> {
@Override public void beforeStart(ClientCallStreamObserver<WatchShardingAssignmentRequest> rs) {
requestStream = rs;
}
@Override public void onNext(WatchShardingAssignmentResponse r) {
syncContext.execute(() -> handleResponse(r));
}
@Override public void onError(Throwable t) {
syncContext.execute(() -> handleStreamClosed(Status.fromThrowable(t)));
}
@Override public void onCompleted() { ... }
}
}| void start() { | ||
| // wait_for_ready keeps the stream pending through transient connectivity failures instead | ||
| // of failing it, which recovers faster than applying backoff around stream creation. | ||
| ClientCalls.asyncBidiStreamingCall( |
There was a problem hiding this comment.
Why are we using the generic API instead of intantiating a stub and calling the method on the stub?
gRFC A119