Skip to content

Commit

Permalink
Fix error with non-existent table for nodetool tablehistograms
Browse files Browse the repository at this point in the history
Patch by Hannu Kroger; reviewed by Chris Lohfink for CASSANDRA-14410
  • Loading branch information
hkroger authored and clohfink committed Aug 8, 2019
1 parent bf41319 commit d6c049f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
50 changes: 29 additions & 21 deletions src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
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")
Expand All @@ -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");
Expand Down

0 comments on commit d6c049f

Please sign in to comment.