Skip to content

Commit 73bf22c

Browse files
committed
fixes
1 parent 874bef4 commit 73bf22c

5 files changed

Lines changed: 47 additions & 19 deletions

File tree

core/http/client/src/main/java/org/eclipse/rdf4j/http/client/QueryCircuitBreaker.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void beforeExecution(QueryCircuitBreakerHandle handle) throws QueryInterr
152152
}
153153

154154
if (state.rejectsNewQueries()) {
155-
System.gc();
155+
maybeRunCheckpointGc();
156156
rejectCount.incrementAndGet();
157157
if (state == QueryPressureState.CRITICAL) {
158158
cancelOneHeavyQueryIfNeeded(configuration, snapshot, "critical-admission");
@@ -270,8 +270,9 @@ private QueryPressureState refreshState(String reason, Configuration configurati
270270
LOGGER.info(
271271
"Query circuit breaker transition previous={} current={} freeMb={} rollingGcMs={} reason={}",
272272
previous, next, snapshot.getFreeMemoryMb(), snapshot.getRollingGcMs(), reason);
273-
if (!isCheckpointReason(reason) && shouldRequestTransitionGc(currentState, configuration, snapshot)) {
274-
System.gc();
273+
if (!isCheckpointReason(reason) && !isMonitorReason(reason)
274+
&& shouldRequestTransitionGc(currentState, configuration, snapshot)) {
275+
maybeRunCheckpointGc();
275276
}
276277
}
277278
if (!throttlesNewQueriesAtEntry(currentState, configuration)) {
@@ -315,6 +316,10 @@ private boolean isCheckpointReason(String reason) {
315316
return reason.startsWith("checkpoint:");
316317
}
317318

319+
private boolean isMonitorReason(String reason) {
320+
return "monitor".equals(reason);
321+
}
322+
318323
private boolean shouldRequestTransitionGc(QueryPressureState state, Configuration configuration,
319324
QueryPressureMonitor.Snapshot snapshot) {
320325
return state == QueryPressureState.HIGH

core/http/client/src/main/java/org/eclipse/rdf4j/http/client/QueryExecutionContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
*/
2121
public final class QueryExecutionContext {
2222

23-
private static boolean ignoreCheckpointStride = false;
23+
private static volatile boolean ignoreCheckpointStride = false;
2424
private static final int CHECKPOINT_STRIDE = 1024;
2525
private static final int CHECKPOINT_MASK = CHECKPOINT_STRIDE - 1;
2626
private static final ThreadLocal<State> CURRENT = new ThreadLocal<>();
27-
private static boolean heavyOperatorExecutionEnabled = true;
28-
private static int checkpointCalls;
27+
private static volatile boolean heavyOperatorExecutionEnabled = true;
28+
private static volatile int checkpointCalls;
2929

3030
private QueryExecutionContext() {
3131
}

core/http/client/src/test/java/org/eclipse/rdf4j/http/client/QueryCircuitBreakerTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,30 @@ void shouldRunMonitorGcEverySecondInCriticalMemoryMode() {
262262
assertEquals(List.of(0L, 1000L), fixture.gcInvocations);
263263
}
264264

265+
@Test
266+
void shouldThrottleGcRequestsForRejectedAdmissions() {
267+
Fixture fixture = new Fixture();
268+
QueryCircuitBreaker breaker = fixture.breaker(configuration(true, 100, 200, 300, 400, 300, 200, 25, 10, 1000,
269+
7), 1000, () -> fixture.gcInvocations.add(fixture.clock.get()));
270+
271+
fixture.freeMemoryMb.set(250);
272+
QueryCircuitBreakerHandle firstHandle = breaker.register(QueryCircuitBreakerHandle.Source.SERVER, "repo",
273+
"first-rejected-query");
274+
QueryCircuitBreakerHandle secondHandle = breaker.register(QueryCircuitBreakerHandle.Source.SERVER, "repo",
275+
"second-rejected-query");
276+
277+
try {
278+
assertThrows(QueryCircuitBreaker.CircuitBreakerException.class, () -> breaker.beforeExecution(firstHandle));
279+
assertThrows(QueryCircuitBreaker.CircuitBreakerException.class,
280+
() -> breaker.beforeExecution(secondHandle));
281+
282+
assertEquals(List.of(0L), fixture.gcInvocations);
283+
} finally {
284+
breaker.complete(firstHandle);
285+
breaker.complete(secondHandle);
286+
}
287+
}
288+
265289
@Test
266290
void shouldBackOffCheckpointGcRequestsAndResetAfterLongPause() {
267291
Fixture fixture = new Fixture();
@@ -439,6 +463,12 @@ void shouldCancelOnlyOneHeavyQueryPerCooldownWindow() {
439463
breaker.complete(thirdAdmission);
440464
}
441465

466+
@Test
467+
void shouldSafelyPublishBreakerExecutionFlagsAcrossThreads() throws Exception {
468+
assertTrue(isVolatile("heavyOperatorExecutionEnabled"));
469+
assertTrue(isVolatile("ignoreCheckpointStride"));
470+
}
471+
442472
private static QueryCircuitBreaker.Configuration configuration(boolean enabled, int warnGcMs, int highGcMs,
443473
int criticalGcMs, int warnFreeMb, int highFreeMb, int criticalFreeMb, int warnAdmissionDelayMs,
444474
int checkpointDelayMs, int cancelCooldownMs, int retryAfterSeconds) {
@@ -490,6 +520,11 @@ private static void resetCheckpointCalls() throws Exception {
490520
field.setInt(null, 0);
491521
}
492522

523+
private static boolean isVolatile(String fieldName) throws Exception {
524+
Field field = QueryExecutionContext.class.getDeclaredField(fieldName);
525+
return java.lang.reflect.Modifier.isVolatile(field.getModifiers());
526+
}
527+
493528
private static Set<Long> threadIds(String threadName) {
494529
Set<Long> ids = new HashSet<>();
495530
for (Thread thread : Thread.getAllStackTraces().keySet()) {

core/sail/lmdb/pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,6 @@
237237
</execution>
238238
</executions>
239239
</plugin>
240-
<plugin>
241-
<artifactId>maven-compiler-plugin</artifactId>
242-
<configuration>
243-
<annotationProcessorPaths>
244-
<path>
245-
<groupId>org.openjdk.jmh</groupId>
246-
<artifactId>jmh-generator-annprocess</artifactId>
247-
<version>${jmhVersion}</version>
248-
</path>
249-
</annotationProcessorPaths>
250-
</configuration>
251-
</plugin>
252240
<plugin>
253241
<artifactId>maven-assembly-plugin</artifactId>
254242
</plugin>

tools/server-boot/src/test/java/org/eclipse/rdf4j/tools/serverboot/LmdbTimedOutQueryReadHandleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.junit.jupiter.api.Test;
4949
import org.slf4j.LoggerFactory;
5050
import org.springframework.boot.test.context.SpringBootTest;
51-
import org.springframework.boot.web.server.LocalServerPort;
51+
import org.springframework.boot.test.web.server.LocalServerPort;
5252
import org.springframework.http.HttpStatus;
5353

5454
import ch.qos.logback.classic.Logger;

0 commit comments

Comments
 (0)