Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce datadir backend's eventual consistency overhead on non REST API requests #546

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading