cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clohf...@apache.org
Subject [cassandra] branch trunk updated: Fix error with non-existent table for nodetool tablehistograms
Date Thu, 08 Aug 2019 18:05:52 GMT
This is an automated email from the ASF dual-hosted git repository.

clohfink pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d6c049f  Fix error with non-existent table for nodetool tablehistograms
d6c049f is described below

commit d6c049f0835f137fc07711ec5cf9adc323347c65
Author: Hannu Kroger <hkroger@gmail.com>
AuthorDate: Thu Aug 8 11:02:15 2019 -0700

    Fix error with non-existent table for nodetool tablehistograms
    
    Patch by Hannu Kroger; reviewed by Chris Lohfink for CASSANDRA-14410
---
 CHANGES.txt                                        |  1 +
 .../cassandra/tools/nodetool/TableHistograms.java  | 50 +++++++++++++---------
 2 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index c9adf59..1d0e11d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0
+ * Fix error with non-existent table for nodetool tablehistograms (CASSANDRA-14410)
  * Catch non-IOException in FileUtils.close to make sure that all resources are closed (CASSANDRA-15225)
  * Align load column in nodetool status output (CASSANDRA-14787)
  * CassandraNetworkAuthorizer uses cached roles info (CASSANDRA-15089)
diff --git a/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java b/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java
index f24c8a3..cb3b946 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java
@@ -23,17 +23,19 @@ import io.airlift.airline.Arguments;
 import io.airlift.airline.Command;
 
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
 import org.apache.cassandra.db.ColumnFamilyStoreMBean;
 import org.apache.cassandra.metrics.CassandraMetricsRegistry;
 import org.apache.cassandra.tools.NodeProbe;
 import org.apache.cassandra.tools.NodeTool.NodeToolCmd;
 import org.apache.cassandra.utils.EstimatedHistogram;
+
 import org.apache.commons.lang3.ArrayUtils;
 
 @Command(name = "tablehistograms", description = "Print statistic histograms for a given
table")
@@ -45,40 +47,46 @@ public class TableHistograms extends NodeToolCmd
     @Override
     public void execute(NodeProbe probe)
     {
-        Map<String, List<String>> tablesList = new HashMap<>();
+        Multimap<String, String> tablesList = HashMultimap.create();
+
+        // a <keyspace, set<table>> mapping for verification or as reference
if none provided
+        Multimap<String, String> allTables = HashMultimap.create();
+        Iterator<Map.Entry<String, ColumnFamilyStoreMBean>> tableMBeans = probe.getColumnFamilyStoreMBeanProxies();
+        while (tableMBeans.hasNext())
+        {
+            Map.Entry<String, ColumnFamilyStoreMBean> entry = tableMBeans.next();
+            allTables.put(entry.getKey(), entry.getValue().getTableName());
+        }
+
         if (args.size() == 2)
         {
-            tablesList.put(args.get(0), new ArrayList<String>(Arrays.asList(args.get(1))));
+            tablesList.put(args.get(0), args.get(1));
         }
         else if (args.size() == 1)
         {
             String[] input = args.get(0).split("\\.");
             checkArgument(input.length == 2, "tablehistograms requires keyspace and table
name arguments");
-            tablesList.put(input[0], new ArrayList<String>(Arrays.asList(input[1])));
+            tablesList.put(input[0], input[1]);
         }
         else
         {
-            // get a list of table stores
-            Iterator<Map.Entry<String, ColumnFamilyStoreMBean>> tableMBeans =
probe.getColumnFamilyStoreMBeanProxies();
-            while (tableMBeans.hasNext())
+            // use all tables
+            tablesList = allTables;
+        }
+
+        // verify that all tables to list exist
+        for (String keyspace : tablesList.keys())
+        {
+            for (String table : tablesList.get(keyspace))
             {
-                Map.Entry<String, ColumnFamilyStoreMBean> entry = tableMBeans.next();
-                String keyspaceName = entry.getKey();
-                ColumnFamilyStoreMBean tableProxy = entry.getValue();
-                if (!tablesList.containsKey(keyspaceName))
-                {
-                    tablesList.put(keyspaceName, new ArrayList<String>());
-                }
-                tablesList.get(keyspaceName).add(tableProxy.getTableName());
+                if (!allTables.containsEntry(keyspace, table))
+                    throw new IllegalArgumentException("Unknown table " + keyspace + '.'
+ table);
             }
         }
 
-        Iterator<Map.Entry<String, List<String>>> iter = tablesList.entrySet().iterator();
-        while(iter.hasNext())
+        for (String keyspace : tablesList.keys())
         {
-            Map.Entry<String, List<String>> entry = iter.next();
-            String keyspace = entry.getKey();
-            for (String table : entry.getValue())
+            for (String table : tablesList.get(keyspace))
             {
                 // calculate percentile of row size and column count
                 long[] estimatedPartitionSize = (long[]) probe.getColumnFamilyMetric(keyspace,
table, "EstimatedPartitionSizeHistogram");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message