bitflicker64 commented on code in PR #3130:
URL: https://github.com/apache/hugegraph/pull/3130#discussion_r3752893028


##########
hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/AbstractGrpcClient.java:
##########
@@ -91,31 +100,44 @@ public ManagedChannel[] getChannels(String target) {
     public abstract AbstractBlockingStub getBlockingStub(ManagedChannel 
channel);
 
     public AbstractBlockingStub getBlockingStub(String target) {
-        ManagedChannel[] channels = getChannels(target);
-        HgPair<ManagedChannel, AbstractBlockingStub>[] pairs = 
blockingStubs.get(target);
-        long l = counter.getAndIncrement();
-        if (l >= limit) {
-            counter.set(0);
-        }
-        int index = (int) (l & (concurrency - 1));
-        if (pairs == null) {
-            synchronized (blockingStubs) {
-                pairs = blockingStubs.get(target);
-                if (pairs == null) {
-                    HgPair<ManagedChannel, AbstractBlockingStub>[] value = new 
HgPair[concurrency];
-                    IntStream.range(0, concurrency).forEach(i -> {
-                        ManagedChannel channel = channels[index];
-                        AbstractBlockingStub stub = getBlockingStub(channel);
-                        value[i] = new HgPair<>(channel, stub);
-                        // log.info("create channel for {}",target);
-                    });
-                    blockingStubs.put(target, value);
-                    AbstractBlockingStub stub = value[index].getValue();
-                    return (AbstractBlockingStub) setBlockingStubOption(stub);
+        while (true) {
+            ManagedChannel[] targetChannels = getChannels(target);
+            HgPair<ManagedChannel, AbstractBlockingStub>[] pairs = 
blockingStubs.get(target);
+            long l = counter.getAndIncrement();
+            if (l >= limit) {
+                counter.set(0);
+            }
+            int index = (int) (l & (concurrency - 1));
+            if (!usesChannels(pairs, targetChannels)) {
+                synchronized (blockingStubs) {
+                    pairs = blockingStubs.get(target);
+                    if (!usesChannels(pairs, targetChannels)) {
+                        HgPair<ManagedChannel, AbstractBlockingStub>[] value =
+                                new HgPair[concurrency];
+                        IntStream.range(0, concurrency).forEach(i -> {
+                            ManagedChannel channel = targetChannels[index];
+                            AbstractBlockingStub stub = 
getBlockingStub(channel);
+                            value[i] = new HgPair<>(channel, stub);
+                            // log.info("create channel for {}",target);
+                        });

Review Comment:
   Revalidated on final head `5afea3b2`. This finding was valid: the shared 
acquisition path now binds every blocking and async cache slot with 
`targetChannels[i]`, while `usesChannels()` enforces one-to-one slot identity 
and the final pool check retries if refresh replaced the pool during 
configured-stub construction. `testStubPoolsCoverEveryChannelOnFirstBuild()` 
and `testAddressChangeReplacesChannelAndStubPools()` verify complete channel 
spread before and after replacement. The final Java 11 run passes 24/24 with no 
failures, errors, or skips.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to