From 133b2e4728fdd895c5639de28d4fdfda4030d524 Mon Sep 17 00:00:00 2001 From: Calle Wilund Date: Wed, 24 Jul 2019 14:33:13 +0000 Subject: [PATCH] storage_service: Add "getSSTableInfo" command/attribute Fixes #76 Requires seastar patch: json: Make date formatter use RFC8601/RFC3339 format Requires scylla patch set "Sstabledesc" Forwards call to REST sstable_info and packs the data into CompositeData for JMX consumption. --- .../cassandra/service/StorageService.java | 60 +++++++++++++++---- .../service/StorageServiceMBean.java | 5 ++ 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/cassandra/service/StorageService.java b/src/main/java/org/apache/cassandra/service/StorageService.java index bda4ad9..0dd0c27 100644 --- a/src/main/java/org/apache/cassandra/service/StorageService.java +++ b/src/main/java/org/apache/cassandra/service/StorageService.java @@ -42,6 +42,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Logger; +import java.util.stream.Collectors; import javax.json.JsonArray; import javax.json.JsonObject; @@ -52,14 +53,14 @@ import javax.management.NotificationBroadcaster; import javax.management.NotificationBroadcasterSupport; import javax.management.NotificationFilter; import javax.management.NotificationListener; +import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; +import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import org.apache.cassandra.metrics.StorageMetrics; import org.apache.cassandra.repair.RepairParallelism; -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.client.ClientProperties; import com.google.common.base.Joiner; import com.scylladb.jmx.api.APIClient; @@ -492,12 +493,12 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean, @Override public void takeSnapshot(String tag, Map options, String... keyspaceNames) throws IOException { log(" takeSnapshot(String tag, String... keyspaceNames) throws IOException"); - MultivaluedMap queryParams = new MultivaluedHashMap(); + MultivaluedMap queryParams = new MultivaluedHashMap(); APIClient.set_query_param(queryParams, "tag", tag); - + if (keyspaceNames.length == 1 && keyspaceNames[0].indexOf('.') != -1) { String[] parts = keyspaceNames[0].split("\\."); - keyspaceNames = new String[] { parts[0] }; + keyspaceNames = new String[] { parts[0] }; APIClient.set_query_param(queryParams, "cf", parts[1]); } APIClient.set_query_param(queryParams, "kn", APIClient.join(keyspaceNames)); @@ -603,8 +604,9 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean, client.post("/storage_service/keyspace_compaction/" + keyspaceName, queryParams); } - @Override - public void forceKeyspaceCompactionForTokenRange(String keyspaceName, String startToken, String endToken, String... tableNames) throws IOException, ExecutionException, InterruptedException { + @Override + public void forceKeyspaceCompactionForTokenRange(String keyspaceName, String startToken, String endToken, + String... tableNames) throws IOException, ExecutionException, InterruptedException { // TODO: actually handle token ranges. forceKeyspaceCompaction(keyspaceName, tableNames); } @@ -869,7 +871,7 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean, @Deprecated public int forceRepairAsync(String keyspace, boolean isSequential, Collection dataCenters, Collection hosts, boolean primaryRange, boolean repairedAt, String... columnFamilies) - throws IOException { + throws IOException { log(" forceRepairAsync(String keyspace, boolean isSequential, Collection dataCenters, Collection hosts, boolean primaryRange, boolean repairedAt, String... columnFamilies) throws IOException"); return repairRangeAsync(null, null, keyspace, isSequential, dataCenters, hosts, primaryRange, repairedAt, columnFamilies); @@ -1298,12 +1300,19 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean, } /** - * Same as {@link #rebuild(String)}, but only for specified keyspace and ranges. + * Same as {@link #rebuild(String)}, but only for specified keyspace and + * ranges. * - * @param sourceDc Name of DC from which to select sources for streaming or null to pick any node - * @param keyspace Name of the keyspace which to rebuild or null to rebuild all keyspaces. - * @param tokens Range of tokens to rebuild or null to rebuild all token ranges. In the format of: - * "(start_token_1,end_token_1],(start_token_2,end_token_2],...(start_token_n,end_token_n]" + * @param sourceDc + * Name of DC from which to select sources for streaming or null + * to pick any node + * @param keyspace + * Name of the keyspace which to rebuild or null to rebuild all + * keyspaces. + * @param tokens + * Range of tokens to rebuild or null to rebuild all token + * ranges. In the format of: + * "(start_token_1,end_token_1],(start_token_2,end_token_2],...(start_token_n,end_token_n]" */ @Override public void rebuild(String sourceDc, String keyspace, String tokens, String specificSources) { @@ -1704,4 +1713,29 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean, log(" resumeBootstrap"); return false; } + + @Override + public List getSSTableInfo(String keyspace, String table) { + if (keyspace == null && table != null) { + throw new IllegalArgumentException("Missing keyspace name"); + } + MultivaluedMap queryParams = null; + + if (keyspace != null) { + queryParams = new MultivaluedHashMap(); + queryParams.add("keyspace", keyspace); + } + if (table != null) { + queryParams.add("cf", table); + } + + return client.get("/storage_service/sstable_info", queryParams) + .get(new GenericType>() { + }).stream().map((i) -> i.toCompositeData()).collect(Collectors.toList()); + } + + @Override + public List getSSTableInfo() { + return getSSTableInfo(null, null); + } } diff --git a/src/main/java/org/apache/cassandra/service/StorageServiceMBean.java b/src/main/java/org/apache/cassandra/service/StorageServiceMBean.java index 05f1c30..f775364 100644 --- a/src/main/java/org/apache/cassandra/service/StorageServiceMBean.java +++ b/src/main/java/org/apache/cassandra/service/StorageServiceMBean.java @@ -35,6 +35,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import javax.management.NotificationEmitter; +import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; public interface StorageServiceMBean extends NotificationEmitter { @@ -872,4 +873,8 @@ public interface StorageServiceMBean extends NotificationEmitter { * Sets the hinted handoff throttle in kb per second, per delivery thread. */ public boolean resumeBootstrap(); + + public List getSSTableInfo(String keyspace, String table); + + public List getSSTableInfo(); }