Skip to content

Commit

Permalink
Merge pull request #550 from geoserver/backport-546-to-release/1.8.x
Browse files Browse the repository at this point in the history
[Backport release/1.8.x] Reduce datadir backend's eventual consistency overhead on non REST API requests
  • Loading branch information
groldan authored Oct 16, 2024
2 parents 884b74d + 07b17e4 commit 062ad28
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import org.geoserver.catalog.plugin.Patch;
import org.geoserver.catalog.plugin.forwarding.ForwardingExtendedCatalogFacade;
import org.geoserver.ows.util.OwsUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.Objects;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -320,7 +322,25 @@ private <T> T retryOnNull(Supplier<T> supplier, Supplier<String> op) {
private <T> T retry(Supplier<T> supplier, Predicate<T> predicate, Supplier<String> op) {
T ret = supplier.get();
if (predicate.test(ret)) return ret;
if (!isWebRequest()) return ret;

// do retry if it's a REST API request or there're pending updates
if (isWebRequest() && (isRestRequest() || !enforcer.isConverged())) {
return doRetry(supplier, predicate, op, ret);
}
return ret;
}

private boolean isRestRequest() {
RequestAttributes atts = RequestContextHolder.getRequestAttributes();
if (atts instanceof ServletRequestAttributes webreq) {
String uri = webreq.getRequest().getRequestURI();
return uri.contains("/rest/");
}
return false;
}

private <T> T doRetry(
Supplier<T> supplier, Predicate<T> predicate, Supplier<String> op, T ret) {
// poor man's Retry implementation
final int maxAttempts = retryAttemptMillis.length;
final String opDesc = op.get();
Expand Down

0 comments on commit 062ad28

Please sign in to comment.