You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "dosubot[bot] (via GitHub)" <gi...@apache.org> on 2024/09/09 06:27:41 UTC
Re: [I] [Question] PDClient newLeaderStub method question [incubator-hugegraph]
dosubot[bot] commented on issue #2663:
URL: https://github.com/apache/incubator-hugegraph/issues/2663#issuecomment-2337232163
<!-- Answer -->
The `StubProxy.set()` method uses the channel obtained based on the host instead of creating a new channel based on the `leaderIp` in the `PDClient.newLeaderStub` method because the `newLeaderStub` method already handles the logic of setting the appropriate stub based on the `leaderIp`. Specifically, if the `leaderIp` is different from the current host, it sets a new stub with the `leaderIp` by creating a new channel for the `leaderIp`:
```java
private String resetStub() {
String leaderHost = "";
for (int i = 0; i < stubProxy.getHostCount(); i++) {
String host = stubProxy.nextHost();
channel = ManagedChannelBuilder.forTarget(host).usePlaintext().build();
PDBlockingStub blockingStub = PDGrpc.newBlockingStub(channel)
.withDeadlineAfter(config.getGrpcTimeOut(),
TimeUnit.MILLISECONDS);
try {
GetMembersRequest request = Pdpb.GetMembersRequest.newBuilder()
.setHeader(header).build();
GetMembersResponse members = blockingStub.getMembers(request);
Metapb.Member leader = members.getLeader();
leaderHost = leader.getGrpcUrl();
close();
channel = ManagedChannelBuilder.forTarget(leaderHost).usePlaintext().build();
stubProxy.setBlockingStub(createBlockingStub());
stubProxy.setStub(createStub());
log.info("PDClient connect to host = {} success", leaderHost);
break;
} catch (Exception e) {
log.error("PDClient connect to {} exception {}, {}", host, e.getMessage(),
e.getCause() != null ? e.getCause().getMessage() : "");
}
}
return leaderHost;
}
```
In this method, if the `leaderIp` is different from the `host`, it sets a new stub with the `leaderIp` by creating a new channel for the `leaderIp`. Therefore, there is no need to create a new channel based on the `leaderIp` again in the `StubProxy.set()` method <sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/AbstractClient.java)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org