Skip to content

Commit 3789656

Browse files
burmanmemerkle826
andauthored
Update version to 5.0.0, bring modifications from 4.1.x to 5.x (#533)
* Update version to 5.0.0, bring modifications from 4.1.x to 5.x agent also * Support Cassandra 5.0 Server.ConnectionTracker changes (#536) * Update Changelog --------- Co-authored-by: Erik Merkle <[email protected]>
1 parent 1822715 commit 3789656

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Changelog for Management API, new PRs should update the `main / unreleased` sect
99
* [BUGFIX]
1010
```
1111

12+
## unreleased
13+
14+
* [FEATURE] [#535](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/535) Add Cassandra 5.0.0 to the build matrix
15+
1216
## v0.1.86
1317

1418
* [ENHANCEMENT] [#539](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/539) Add the ability to run DSE 6.8 and 6.9 in readOnlyRootFilesystem mode

cassandra/Dockerfile-5.0.ubi8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG UBI_MAJOR=8
22
ARG UBI_BASETAG=latest
3-
ARG CASSANDRA_VERSION=5.0-beta1
3+
ARG CASSANDRA_VERSION=5.0.0
44
FROM registry.access.redhat.com/ubi${UBI_MAJOR}/ubi-minimal:${UBI_BASETAG} AS builder
55

66
ARG URL_PREFIX=https://dlcdn.apache.org/cassandra

management-api-agent-5.0.x/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<version>${revision}</version>
1717
<artifactId>datastax-mgmtapi-agent-5.0.x</artifactId>
1818
<properties>
19-
<cassandra5.version>5.0-beta1</cassandra5.version>
19+
<cassandra5.version>5.0.0</cassandra5.version>
2020
<netty.http.codec.version>4.1.96.Final</netty.http.codec.version>
2121
</properties>
2222
<dependencies>

management-api-agent-5.0.x/src/main/java/com/datastax/mgmtapi/shim/RpcStatement50x.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.apache.cassandra.cql3.QueryOptions;
1111
import org.apache.cassandra.service.ClientState;
1212
import org.apache.cassandra.service.QueryState;
13+
import org.apache.cassandra.transport.Dispatcher;
1314
import org.apache.cassandra.transport.messages.ResultMessage;
1415

1516
public class RpcStatement50x implements RpcStatementShim {
@@ -28,7 +29,8 @@ public void authorize(ClientState clientState) {}
2829
public void validate(ClientState clientState) {}
2930

3031
@Override
31-
public ResultMessage execute(QueryState queryState, QueryOptions queryOptions, long l) {
32+
public ResultMessage execute(
33+
QueryState queryState, QueryOptions queryOptions, Dispatcher.RequestTime rt) {
3234
return new ResultMessage.Void();
3335
}
3436

management-api-agent-5.0.x/src/main/java/org/apache/cassandra/transport/UnixSocketServer50x.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ protected void channelRead0(ChannelHandlerContext ctx, Message.Request request)
8383
throws Exception {
8484
final Message.Response response;
8585
final UnixSocketConnection connection;
86-
long queryStartNanoTime = System.nanoTime();
8786

8887
try {
8988
assert request.connection() instanceof UnixSocketConnection;
@@ -97,7 +96,8 @@ protected void channelRead0(ChannelHandlerContext ctx, Message.Request request)
9796
// logger.info("Executing {} {} {}", request, connection.getVersion(),
9897
// request.getStreamId());
9998

100-
Message.Response r = request.execute(qstate, queryStartNanoTime);
99+
Message.Response r =
100+
request.execute(qstate, Dispatcher.RequestTime.forImmediateExecution());
101101

102102
// UnixSocket has no auth
103103
response = r instanceof AuthenticateMessage ? new ReadyMessage() : r;
@@ -286,7 +286,10 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> ou
286286
long approxStartTimeNanos = MonotonicClock.Global.approxTime.now();
287287
Message.Response response =
288288
Dispatcher.processRequest(
289-
ctx.channel(), startup, Overload.NONE, approxStartTimeNanos);
289+
ctx.channel(),
290+
startup,
291+
Overload.NONE,
292+
Dispatcher.RequestTime.forImmediateExecution());
290293

291294
if (response.type.equals(Message.Type.AUTHENTICATE))
292295
// bypass authentication

management-api-agent-common/src/main/java/com/datastax/mgmtapi/interceptors/CassandraDaemonInterceptor.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
import io.netty.channel.epoll.Epoll;
1616
import io.netty.channel.epoll.EpollEventLoopGroup;
1717
import java.io.File;
18+
import java.lang.reflect.Constructor;
1819
import java.nio.file.Paths;
1920
import java.util.concurrent.Callable;
21+
import java.util.concurrent.atomic.AtomicBoolean;
22+
import java.util.function.BooleanSupplier;
2023
import net.bytebuddy.agent.builder.AgentBuilder.Transformer;
2124
import net.bytebuddy.description.type.TypeDescription;
2225
import net.bytebuddy.implementation.MethodDelegation;
@@ -58,7 +61,7 @@ public static void intercept(@SuperCall Callable<Void> zuper) throws Exception {
5861
File unixSock = Paths.get(socketFileStr).toFile();
5962

6063
final EventLoopGroup group = new EpollEventLoopGroup(8);
61-
final Server.ConnectionTracker connectionTracker = new Server.ConnectionTracker();
64+
final Server.ConnectionTracker connectionTracker = getTracker();
6265

6366
IPCController controller =
6467
IPCController.newServer()
@@ -94,4 +97,29 @@ public static void intercept(@SuperCall Callable<Void> zuper) throws Exception {
9497
logger.warn("Problem starting DataStax Management API for Apache Cassandra", e);
9598
}
9699
}
100+
101+
private static Server.ConnectionTracker getTracker() throws Exception {
102+
// ConnectionTracker constructor is private in 5.0, need to use reflection
103+
for (Constructor ctor : Server.ConnectionTracker.class.getDeclaredConstructors()) {
104+
// Try to get the 5.0 constructor that takes a BooleanSupplier
105+
Class[] types = ctor.getParameterTypes();
106+
if (types.length == 1 && types[0].equals(BooleanSupplier.class)) {
107+
logger.info("BooleanSupplier constructor found!");
108+
ctor.setAccessible(true);
109+
Object[] args = new Object[1];
110+
final AtomicBoolean isRunning = new AtomicBoolean(false);
111+
final BooleanSupplier supplier = isRunning::get;
112+
args[0] = supplier;
113+
Object obj = ctor.newInstance(args);
114+
return (Server.ConnectionTracker) obj;
115+
} else if (types.length == 0) {
116+
// try to get the no arg constructor from Cassandra < 5.0
117+
logger.info("no-arg constructor found!");
118+
ctor.setAccessible(true);
119+
Object obj = ctor.newInstance();
120+
return (Server.ConnectionTracker) obj;
121+
}
122+
}
123+
throw new RuntimeException("No suitable Server.ConnectionTracker constructor found!!!");
124+
}
97125
}

0 commit comments

Comments
 (0)