Skip to content

Commit 36347d1

Browse files
committed
fixes
1 parent 73bf22c commit 36347d1

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Objects;
1515
import java.util.concurrent.atomic.AtomicBoolean;
1616
import java.util.concurrent.atomic.AtomicLong;
17+
import java.util.concurrent.atomic.AtomicReference;
1718

1819
import org.eclipse.rdf4j.repository.RepositoryConnection;
1920
import org.slf4j.Logger;
@@ -39,14 +40,12 @@ public enum Source {
3940
private final long startTimeMillis;
4041
private final Runnable remoteCancel;
4142
private final AtomicBoolean active = new AtomicBoolean(true);
42-
private final AtomicBoolean cancelRequested = new AtomicBoolean(false);
43+
private final AtomicReference<Cancellation> cancellation = new AtomicReference<>();
4344
private final AtomicLong lastHeavyCheckpointMillis = new AtomicLong(-1);
4445

4546
private volatile Thread workerThread;
4647
private volatile RepositoryConnection repositoryConnection;
4748
private volatile String lastHeavyOperator;
48-
private volatile QueryPressureState cancellationState = QueryPressureState.NORMAL;
49-
private volatile String cancellationReason;
5049

5150
QueryCircuitBreakerHandle(String executionId, Source source, String repositoryId, String queryHash,
5251
long startTimeMillis, Runnable remoteCancel) {
@@ -83,7 +82,7 @@ public boolean isActive() {
8382
}
8483

8584
public boolean isCancelRequested() {
86-
return cancelRequested.get();
85+
return cancellation.get() != null;
8786
}
8887

8988
public long getLastHeavyCheckpointMillis() {
@@ -95,11 +94,13 @@ public String getLastHeavyOperator() {
9594
}
9695

9796
public QueryPressureState getCancellationState() {
98-
return cancellationState;
97+
Cancellation current = cancellation.get();
98+
return current != null ? current.state : QueryPressureState.NORMAL;
9999
}
100100

101101
public String getCancellationReason() {
102-
return cancellationReason;
102+
Cancellation current = cancellation.get();
103+
return current != null ? current.reason : null;
103104
}
104105

105106
public boolean hasHeavyCheckpoint() {
@@ -125,13 +126,10 @@ void markHeavy(String operator, long checkpointTimeMillis) {
125126
}
126127

127128
boolean requestCancel(QueryPressureState state, String reason) {
128-
if (!active.get() || !cancelRequested.compareAndSet(false, true)) {
129+
if (!active.get() || !cancellation.compareAndSet(null, new Cancellation(state, reason))) {
129130
return false;
130131
}
131132

132-
cancellationState = state;
133-
cancellationReason = reason;
134-
135133
Thread activeWorker = workerThread;
136134
if (activeWorker != null && activeWorker != Thread.currentThread()) {
137135
activeWorker.interrupt();
@@ -168,4 +166,15 @@ private void runRemoteCancel() {
168166
LOGGER.debug("Error while forwarding breaker-triggered cancellation", e);
169167
}
170168
}
169+
170+
private static final class Cancellation {
171+
172+
private final QueryPressureState state;
173+
private final String reason;
174+
175+
private Cancellation(QueryPressureState state, String reason) {
176+
this.state = state;
177+
this.reason = reason;
178+
}
179+
}
171180
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ void shouldNotLeaveCurrentThreadInterruptedWhenSelfCancelling() {
133133
}
134134
}
135135

136+
@Test
137+
void shouldPublishCancellationDetailsAndCancelRequestAsSingleState() {
138+
assertThrows(NoSuchFieldException.class,
139+
() -> QueryCircuitBreakerHandle.class.getDeclaredField("cancelRequested"));
140+
}
141+
136142
@Test
137143
void shouldIgnoreCheckpointStrideOnlyAtHighOrAbove() throws Exception {
138144
PropertiesScope properties = new PropertiesScope()

tools/server-spring/src/test/java/org/eclipse/rdf4j/common/webapp/system/QueryCircuitBreakerStatusControllerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class QueryCircuitBreakerStatusControllerTest {
3030
void shouldMapSystemBreakerStatusEndpoint() throws Exception {
3131
String servletConfig = Files.readString(
3232
Path.of("..", "server", "src", "main", "webapp", "WEB-INF", "common-webapp-system-servlet.xml"));
33+
String webXml = Files.readString(Path.of("..", "server", "src", "main", "webapp", "WEB-INF", "web.xml"));
3334

34-
assertThat(servletConfig).contains("/system/breaker/status");
35+
assertThat(servletConfig).contains("/system/breaker/status.view");
36+
assertThat(webXml).contains("<url-pattern>*.view</url-pattern>");
3537
}
3638

3739
@Test

tools/server/src/main/webapp/WEB-INF/common-webapp-system-servlet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<prop key="/system/overview.view">commonWebappSystemOverviewController</prop>
3636
<prop key="/system/info/overview.view">commonWebappSystemInfoController</prop>
3737
<prop key="/system/info/debug.view">filenameViewController</prop>
38-
<prop key="/system/breaker/status">commonWebappQueryCircuitBreakerStatusController</prop>
38+
<prop key="/system/breaker/status.view">commonWebappQueryCircuitBreakerStatusController</prop>
3939
<prop key="/system/logging/overview.view">commonWebappLoggingOverviewController</prop>
4040
</props>
4141
</property>

0 commit comments

Comments
 (0)