(index-client) Clean up index client code

Improve error handling.  This should be a relatively rare case, but we don't want one bad index partition to blow up the entire query.
This commit is contained in:
Viktor Lofgren 2025-01-10 15:17:07 +01:00
parent bc2c2061f2
commit f2567677e8

View File

@ -21,6 +21,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
@Singleton
public class IndexClient {
@ -65,7 +66,13 @@ public class IndexClient {
totalNumResults.addAndGet(ret.size());
return ret;
}))
.map(CompletableFuture::join)
.mapMulti((CompletableFuture<List<RpcDecoratedResultItem>> fut, Consumer<List<RpcDecoratedResultItem>> c) ->{
try {
c.accept(fut.join());
} catch (Exception e) {
logger.error("Error while fetching results", e);
}
})
.flatMap(List::stream)
.filter(item -> !isBlacklisted(item))
.sorted(comparator)