Skip to content

Commit

Permalink
Make sure replication factor overrides are applied to system_auth / s…
Browse files Browse the repository at this point in the history
…ystem_distributed / system_traces keyspaces
  • Loading branch information
Eduard Tudenhoefner committed Jul 6, 2020
1 parent e26ca4a commit 0f1dc2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
13 changes: 3 additions & 10 deletions management-api-agent/src/main/java/com/datastax/mgmtapi/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
*/
package com.datastax.mgmtapi;

import com.datastax.mgmtapi.interceptors.AuthSchemaInterceptor;
import com.datastax.mgmtapi.interceptors.SystemDistributedReplicationInterceptor;
import com.datastax.mgmtapi.interceptors.CassandraDaemonInterceptor;
import com.datastax.mgmtapi.interceptors.CassandraRoleManagerInterceptor;
import com.datastax.mgmtapi.interceptors.QueryHandlerInterceptor;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.loading.ClassInjector;
import org.apache.cassandra.gms.GossiperInterceptor;

import java.io.File;
import java.lang.instrument.Instrumentation;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;

import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.isSynthetic;
Expand All @@ -45,8 +38,8 @@ public static void premain(String arg, Instrumentation inst) throws Exception {
//Auth Setup
.type(CassandraRoleManagerInterceptor.type())
.transform(CassandraRoleManagerInterceptor.transformer())
.type(AuthSchemaInterceptor.type())
.transform(AuthSchemaInterceptor.transformer())
.type(SystemDistributedReplicationInterceptor.type())
.transform(SystemDistributedReplicationInterceptor.transformer())
.installOn(inst);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import org.apache.cassandra.schema.KeyspaceParams;
import org.apache.cassandra.schema.ReplicationParams;

public class AuthSchemaInterceptor
import static net.bytebuddy.matcher.ElementMatchers.nameEndsWith;

public class SystemDistributedReplicationInterceptor
{
private static final String SYSTEM_DISTRIBUTED_NTS_DC_OVERRIDE_PROPERTY = "cassandra.system_distributed_replication_dc_names";
private static final String SYSTEM_DISTRIBUTED_NTS_RF_OVERRIDE_PROPERTY = "cassandra.system_distributed_replication_per_dc";
Expand All @@ -53,22 +55,22 @@ public class AuthSchemaInterceptor
}
catch (Throwable t)
{
LoggerFactory.getLogger(AuthSchemaInterceptor.class).error("Error parsing system distributed replication override properties", t);
LoggerFactory.getLogger(SystemDistributedReplicationInterceptor.class).error("Error parsing system distributed replication override properties", t);
}

if (rfOverride != null && !dcOverride.isEmpty())
{
//Validate reasonable defaults
if (rfOverride <= 0 || rfOverride > 5)
{
LoggerFactory.getLogger(AuthSchemaInterceptor.class).error("Invalid value for {}", SYSTEM_DISTRIBUTED_NTS_RF_OVERRIDE_PROPERTY);
LoggerFactory.getLogger(SystemDistributedReplicationInterceptor.class).error("Invalid value for {}", SYSTEM_DISTRIBUTED_NTS_RF_OVERRIDE_PROPERTY);
}
else
{
for (String dc : dcOverride)
ntsOverride.put(dc, String.valueOf(rfOverride));

LoggerFactory.getLogger(AuthSchemaInterceptor.class).info("Using override for distributed system keyspaces: {}", ntsOverride);
LoggerFactory.getLogger(SystemDistributedReplicationInterceptor.class).info("Using override for distributed system keyspaces: {}", ntsOverride);
}
}

Expand All @@ -78,7 +80,9 @@ public class AuthSchemaInterceptor

public static ElementMatcher<? super TypeDescription> type()
{
return ElementMatchers.nameEndsWith(".AuthKeyspace");
return nameEndsWith(".AuthKeyspace")
.or(nameEndsWith(".TraceKeyspace"))
.or(nameEndsWith(".SystemDistributedKeyspace"));
}

public static AgentBuilder.Transformer transformer()
Expand All @@ -88,7 +92,7 @@ public static AgentBuilder.Transformer transformer()
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule javaModule)
{
return builder.method(ElementMatchers.named("metadata")).intercept(MethodDelegation.to(AuthSchemaInterceptor.class));
return builder.method(ElementMatchers.named("metadata")).intercept(MethodDelegation.to(SystemDistributedReplicationInterceptor.class));
}
};
}
Expand Down

0 comments on commit 0f1dc2e

Please sign in to comment.