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

Use a longer driver timeout for drain #454

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changelog for Management API, new PRs should update the `main / unreleased` sect
```

## unreleased
* [FEATURE] [$453](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/453) Use a longer driver timeout for drain

## v0.1.73 (2024-02-20)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,35 @@ public ResultSet executePreparedStatement(
throw e;
}
}

/**
* Used for NodeOpsProvider implementations that are synchronous and may take a while to complete.
* (example node drain). The implementation here uses the Java driver's execution profile
* mechanism with the bundled application.conf that sets the request timeout to 0 seconds, which
* effectively disables the driver request timeout. Use this method with caution!. See
* application.conf in the resources folder.
*/
public ResultSet executeSlowCql(File dbUnixSocketFile, String query)
throws ConnectionClosedException {
CqlSession session = UnixSocketCQLAccess.get(dbUnixSocketFile).orElse(null);

if (session == null || session.isClosed()) {
throw new ConnectionClosedException("Internal connection to Cassandra closed");
}

// build a statement and use the "slow" driver execution profile
SimpleStatementBuilder ssb = new SimpleStatementBuilder(query).setExecutionProfileName("slow");

try {
return session.execute(ssb.build());
} catch (NoNodeAvailableException e) {
try {
session.close();
} catch (Throwable t) {
// close quietly
}

throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public Response drain() {
return handle(
() -> {
try {
app.cqlService.executeCql(app.dbUnixSocketFile, "CALL NodeOps.drain()");
app.cqlService.executeSlowCql(app.dbUnixSocketFile, "CALL NodeOps.drain()");

return Response.ok("OK").build();
} catch (com.datastax.oss.driver.api.core.connection.ClosedConnectionException cce) {
Expand Down
10 changes: 10 additions & 0 deletions management-api-server/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
datastax-java-driver {
profiles {
## The slow profile below sets the driver timeout to 0 seconds
## to effectively disable the query timeout all together. This
## is not something you would normally want to do with the driver.
slow {
basic.request.timeout = 0 seconds
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ public void testSetLoggingLevel_MissingRawLevel() throws Exception {
public void testDrain() throws Exception {
Context context = setup();
MockHttpRequest request = MockHttpRequest.post(ROOT_PATH + "/ops/node/drain");
when(context.cqlService.executeCql(any(), anyString())).thenReturn(null);
when(context.cqlService.executeSlowCql(any(), anyString())).thenReturn(null);

MockHttpResponse response = context.invoke(request);

Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
Assert.assertTrue(response.getContentAsString().contains("OK"));

verify(context.cqlService).executeCql(any(), eq("CALL NodeOps.drain()"));
verify(context.cqlService).executeSlowCql(any(), eq("CALL NodeOps.drain()"));
}

@Test
Expand Down
Loading