(grpc-client) Fix warmup crash

The warmup would sometimes crash during a cold start-up, because it could not get an API.  Changed the warmup to just create a GrpcSingleNodeChannelPool for the node.
This commit is contained in:
Viktor Lofgren 2024-02-20 18:03:57 +01:00
parent 6c764bceeb
commit a69c0b2718

View File

@ -43,22 +43,25 @@ public class GrpcMultiNodeChannelPool<STUB> {
// Warm up the pool to reduce latency for the initial request
for (var node : nodeConfigurationWatcher.getQueryNodes()) {
apiForNode(node);
getPoolForNode(node);
}
}
private GrpcSingleNodeChannelPool<STUB> getPoolForNode(int node) {
return pools.computeIfAbsent(node, _ ->
new GrpcSingleNodeChannelPool<>(
serviceRegistryIf,
serviceId,
new NodeSelectionStrategy.Just(node),
channelConstructor,
stubConstructor));
}
/** Get an API stub for the given node */
public STUB apiForNode(int node) {
return pools.computeIfAbsent(node, _ ->
new GrpcSingleNodeChannelPool<>(
serviceRegistryIf,
serviceId,
new NodeSelectionStrategy.Just(node),
channelConstructor,
stubConstructor)
).api();
return pools.computeIfAbsent(node, this::getPoolForNode).api();
}