(query-client) Add support for fault-tolerant requests to single node services

Adding a method importantCall that will retry a failing request on each route until it succeeds or the routes run out.
This commit is contained in:
Viktor Lofgren 2024-02-20 14:16:05 +01:00
parent 746a865106
commit 07b625c58d
2 changed files with 19 additions and 2 deletions

View File

@ -47,10 +47,11 @@ public class QueryClient {
@CheckReturnValue @CheckReturnValue
public QueryResponse search(QueryParams params) { public QueryResponse search(QueryParams params) {
var query = QueryProtobufCodec.convertQueryParams(params);
return wmsa_qs_api_search_time.time( return wmsa_qs_api_search_time.time(
() -> QueryProtobufCodec.convertQueryResponse(queryApiPool () -> QueryProtobufCodec.convertQueryResponse(queryApiPool
.api() .importantCall((api) -> api.query(query))
.query(QueryProtobufCodec.convertQueryParams(params))
) )
); );
} }

View File

@ -98,6 +98,22 @@ public class GrpcSingleNodeChannelPool<STUB> extends ServiceChangeMonitor {
return stubConstructor.apply(getChannel()); return stubConstructor.apply(getChannel());
} }
/** Try to make the call go through. The function will cycle through
* available routes until exhaustion, and only then will it give up
*/
public <T> T importantCall(Function<STUB, T> function) {
for (int i = 0; i < channels.size(); i++) {
try {
return function.apply(api());
}
catch (Exception e) {
logger.error("API Exception", e);
}
}
throw new ServiceNotAvailableException(serviceId);
}
/** Get the channel that is most ready to use */ /** Get the channel that is most ready to use */
public ManagedChannel getChannel() { public ManagedChannel getChannel() {
return channels return channels