Use better overflow strategy

This commit is contained in:
Andrea Cavalli 2021-03-03 21:32:45 +01:00
parent b71f3dceed
commit e3fcf7f74f

View File

@ -59,6 +59,7 @@ import org.jetbrains.annotations.Nullable;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink.OverflowStrategy;
import reactor.core.publisher.GroupedFlux; import reactor.core.publisher.GroupedFlux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler; import reactor.core.scheduler.Scheduler;
@ -563,9 +564,9 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
requestsAvailable.release(); requestsAvailable.release();
}); });
try {
luceneQueryScheduler.schedule(() -> { luceneQueryScheduler.schedule(() -> {
try { try {
requestsAvailable.acquire();
if (!cancelled.get()) { if (!cancelled.get()) {
if (doDistributedPre) { if (doDistributedPre) {
allowOnlyQueryParsingCollectorStreamSearcher.search(indexSearcher, luceneQuery); allowOnlyQueryParsingCollectorStreamSearcher.search(indexSearcher, luceneQuery);
@ -581,13 +582,16 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
keyFieldName, keyFieldName,
keyScore -> { keyScore -> {
try { try {
if (requests.get() <= 0 && !cancelled.get()) {
requestsAvailable.acquire();
}
if (cancelled.get()) { if (cancelled.get()) {
return HandleResult.HALT; return HandleResult.HALT;
} }
requests.updateAndGet(n -> n > 0 ? n - 1 : 0); while (requests.get() <= 0) {
requestsAvailable.acquire();
if (cancelled.get()) {
return HandleResult.HALT;
}
}
requests.decrementAndGet();
sink.next(fixKeyScore(keyScore, scoreDivisor)); sink.next(fixKeyScore(keyScore, scoreDivisor));
return HandleResult.CONTINUE; return HandleResult.CONTINUE;
} catch (Exception ex) { } catch (Exception ex) {
@ -599,10 +603,16 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
}, },
totalHitsCount -> { totalHitsCount -> {
try { try {
if (requests.get() <= 0 && !cancelled.get()) { if (cancelled.get()) {
requestsAvailable.acquire(); return;
} }
requests.updateAndGet(n -> n > 0 ? n - 1 : 0); while (requests.get() <= 0) {
requestsAvailable.acquire();
if (cancelled.get()) {
return;
}
}
requests.decrementAndGet();
sink.next(new LLTotalHitsCount(totalHitsCount)); sink.next(new LLTotalHitsCount(totalHitsCount));
} catch (Exception ex) { } catch (Exception ex) {
sink.error(ex); sink.error(ex);
@ -618,7 +628,10 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
sink.error(ex); sink.error(ex);
} }
}); });
}).subscribeOn(Schedulers.boundedElastic())))); } catch (Exception ex) {
sink.error(ex);
}
}, OverflowStrategy.ERROR).subscribeOn(Schedulers.boundedElastic()))));
} }
@Override @Override