Skip to content

Commit 0f1dc2e

Browse files
author
Eduard Tudenhoefner
committed
Make sure replication factor overrides are applied to system_auth / system_distributed / system_traces keyspaces
1 parent e26ca4a commit 0f1dc2e

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

management-api-agent/src/main/java/com/datastax/mgmtapi/Agent.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,14 @@
55
*/
66
package com.datastax.mgmtapi;
77

8-
import com.datastax.mgmtapi.interceptors.AuthSchemaInterceptor;
8+
import com.datastax.mgmtapi.interceptors.SystemDistributedReplicationInterceptor;
99
import com.datastax.mgmtapi.interceptors.CassandraDaemonInterceptor;
1010
import com.datastax.mgmtapi.interceptors.CassandraRoleManagerInterceptor;
1111
import com.datastax.mgmtapi.interceptors.QueryHandlerInterceptor;
1212
import net.bytebuddy.agent.builder.AgentBuilder;
13-
import net.bytebuddy.description.type.TypeDescription;
14-
import net.bytebuddy.dynamic.ClassFileLocator;
15-
import net.bytebuddy.dynamic.loading.ClassInjector;
1613
import org.apache.cassandra.gms.GossiperInterceptor;
1714

18-
import java.io.File;
1915
import java.lang.instrument.Instrumentation;
20-
import java.nio.file.Files;
21-
import java.util.HashMap;
22-
import java.util.Map;
2316

2417
import static net.bytebuddy.matcher.ElementMatchers.any;
2518
import static net.bytebuddy.matcher.ElementMatchers.isSynthetic;
@@ -45,8 +38,8 @@ public static void premain(String arg, Instrumentation inst) throws Exception {
4538
//Auth Setup
4639
.type(CassandraRoleManagerInterceptor.type())
4740
.transform(CassandraRoleManagerInterceptor.transformer())
48-
.type(AuthSchemaInterceptor.type())
49-
.transform(AuthSchemaInterceptor.transformer())
41+
.type(SystemDistributedReplicationInterceptor.type())
42+
.transform(SystemDistributedReplicationInterceptor.transformer())
5043
.installOn(inst);
5144
}
5245
}

management-api-agent/src/main/java/com/datastax/mgmtapi/interceptors/AuthSchemaInterceptor.java management-api-agent/src/main/java/com/datastax/mgmtapi/interceptors/SystemDistributedReplicationInterceptor.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import org.apache.cassandra.schema.KeyspaceParams;
3131
import org.apache.cassandra.schema.ReplicationParams;
3232

33-
public class AuthSchemaInterceptor
33+
import static net.bytebuddy.matcher.ElementMatchers.nameEndsWith;
34+
35+
public class SystemDistributedReplicationInterceptor
3436
{
3537
private static final String SYSTEM_DISTRIBUTED_NTS_DC_OVERRIDE_PROPERTY = "cassandra.system_distributed_replication_dc_names";
3638
private static final String SYSTEM_DISTRIBUTED_NTS_RF_OVERRIDE_PROPERTY = "cassandra.system_distributed_replication_per_dc";
@@ -53,22 +55,22 @@ public class AuthSchemaInterceptor
5355
}
5456
catch (Throwable t)
5557
{
56-
LoggerFactory.getLogger(AuthSchemaInterceptor.class).error("Error parsing system distributed replication override properties", t);
58+
LoggerFactory.getLogger(SystemDistributedReplicationInterceptor.class).error("Error parsing system distributed replication override properties", t);
5759
}
5860

5961
if (rfOverride != null && !dcOverride.isEmpty())
6062
{
6163
//Validate reasonable defaults
6264
if (rfOverride <= 0 || rfOverride > 5)
6365
{
64-
LoggerFactory.getLogger(AuthSchemaInterceptor.class).error("Invalid value for {}", SYSTEM_DISTRIBUTED_NTS_RF_OVERRIDE_PROPERTY);
66+
LoggerFactory.getLogger(SystemDistributedReplicationInterceptor.class).error("Invalid value for {}", SYSTEM_DISTRIBUTED_NTS_RF_OVERRIDE_PROPERTY);
6567
}
6668
else
6769
{
6870
for (String dc : dcOverride)
6971
ntsOverride.put(dc, String.valueOf(rfOverride));
7072

71-
LoggerFactory.getLogger(AuthSchemaInterceptor.class).info("Using override for distributed system keyspaces: {}", ntsOverride);
73+
LoggerFactory.getLogger(SystemDistributedReplicationInterceptor.class).info("Using override for distributed system keyspaces: {}", ntsOverride);
7274
}
7375
}
7476

@@ -78,7 +80,9 @@ public class AuthSchemaInterceptor
7880

7981
public static ElementMatcher<? super TypeDescription> type()
8082
{
81-
return ElementMatchers.nameEndsWith(".AuthKeyspace");
83+
return nameEndsWith(".AuthKeyspace")
84+
.or(nameEndsWith(".TraceKeyspace"))
85+
.or(nameEndsWith(".SystemDistributedKeyspace"));
8286
}
8387

8488
public static AgentBuilder.Transformer transformer()
@@ -88,7 +92,7 @@ public static AgentBuilder.Transformer transformer()
8892
@Override
8993
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule javaModule)
9094
{
91-
return builder.method(ElementMatchers.named("metadata")).intercept(MethodDelegation.to(AuthSchemaInterceptor.class));
95+
return builder.method(ElementMatchers.named("metadata")).intercept(MethodDelegation.to(SystemDistributedReplicationInterceptor.class));
9296
}
9397
};
9498
}

0 commit comments

Comments
 (0)