You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by br...@apache.org on 2013/10/15 18:20:08 UTC
[3/6] git commit: Add ability to list specific KS/CF combinations in
nodetool cfstats Patch by Lyuben Todorov,
reviewed by brandonwilliams for CASSANDRA-4191
Add ability to list specific KS/CF combinations in nodetool cfstats
Patch by Lyuben Todorov, reviewed by brandonwilliams for CASSANDRA-4191
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/8dcdce4e
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/8dcdce4e
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/8dcdce4e
Branch: refs/heads/trunk
Commit: 8dcdce4e904d419e821aa80a9d21f61ef8803911
Parents: 6165840
Author: Brandon Williams <br...@apache.org>
Authored: Tue Oct 15 11:09:11 2013 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Tue Oct 15 11:09:11 2013 -0500
----------------------------------------------------------------------
CHANGES.txt | 3 +
.../org/apache/cassandra/tools/NodeCmd.java | 102 +++++++++++++++++--
.../apache/cassandra/tools/NodeToolHelp.yaml | 4 +-
3 files changed, 101 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/8dcdce4e/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 046ecfb..2dbadc4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,6 @@
+1.2.12
+ * Add ability to list specific KS/CF combinations in nodetool cfstats (CASSANDRA-4191)
+
1.2.11
* Limit CQL prepared statement cache by size instead of count (CASSANDRA-6107)
* Tracing should log write failure rather than raw exceptions (CASSANDRA-6133)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/8dcdce4e/src/java/org/apache/cassandra/tools/NodeCmd.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeCmd.java b/src/java/org/apache/cassandra/tools/NodeCmd.java
index 86f9eef..7e0bf67 100644
--- a/src/java/org/apache/cassandra/tools/NodeCmd.java
+++ b/src/java/org/apache/cassandra/tools/NodeCmd.java
@@ -72,6 +72,7 @@ public class NodeCmd
private static final Pair<String, String> END_TOKEN_OPT = Pair.create("et", "end-token");
private static final Pair<String, String> UPGRADE_ALL_SSTABLE_OPT = Pair.create("a", "include-all-sstables");
private static final Pair<String, String> NO_SNAPSHOT = Pair.create("ns", "no-snapshot");
+ private static final Pair<String, String> CFSTATS_IGNORE_OPT = Pair.create("i", "ignore");
private static final String DEFAULT_HOST = "127.0.0.1";
private static final int DEFAULT_PORT = 7199;
@@ -96,6 +97,7 @@ public class NodeCmd
options.addOption(END_TOKEN_OPT, true, "token at which repair range ends");
options.addOption(UPGRADE_ALL_SSTABLE_OPT, false, "includes sstables that are already on the most recent version during upgradesstables");
options.addOption(NO_SNAPSHOT, false, "disables snapshot creation for scrub");
+ options.addOption(CFSTATS_IGNORE_OPT, false, "ignore the supplied list of keyspace.columnfamiles in statistics");
}
public NodeCmd(NodeProbe probe)
@@ -803,8 +805,9 @@ public class NodeCmd
}
}
- public void printColumnFamilyStats(PrintStream outs)
+ public void printColumnFamilyStats(PrintStream outs, boolean ignoreMode, String [] filterList)
{
+ OptionFilter filter = new OptionFilter(ignoreMode, filterList);
Map <String, List <ColumnFamilyStoreMBean>> cfstoreMap = new HashMap <String, List <ColumnFamilyStoreMBean>>();
// get a list of column family stores
@@ -816,18 +819,22 @@ public class NodeCmd
String tableName = entry.getKey();
ColumnFamilyStoreMBean cfsProxy = entry.getValue();
- if (!cfstoreMap.containsKey(tableName))
+ if (!cfstoreMap.containsKey(tableName) && filter.isColumnFamilyIncluded(entry.getKey(), cfsProxy.getColumnFamilyName()))
{
List<ColumnFamilyStoreMBean> columnFamilies = new ArrayList<ColumnFamilyStoreMBean>();
columnFamilies.add(cfsProxy);
cfstoreMap.put(tableName, columnFamilies);
}
- else
+ else if (filter.isColumnFamilyIncluded(entry.getKey(), cfsProxy.getColumnFamilyName()))
{
cfstoreMap.get(tableName).add(cfsProxy);
}
}
+ // make sure all specified kss and cfs exist
+ filter.verifyKeyspaces(probe.getKeyspaces());
+ filter.verifyColumnFamilies();
+
// print out the table statistics
for (Entry<String, List<ColumnFamilyStoreMBean>> entry : cfstoreMap.entrySet())
{
@@ -1140,7 +1147,11 @@ public class NodeCmd
break;
case INFO : nodeCmd.printInfo(System.out, cmd); break;
- case CFSTATS : nodeCmd.printColumnFamilyStats(System.out); break;
+ case CFSTATS :
+ boolean ignoreMode = cmd.hasOption(CFSTATS_IGNORE_OPT.left);
+ if (arguments.length > 0) { nodeCmd.printColumnFamilyStats(System.out, ignoreMode, arguments); }
+ else { nodeCmd.printColumnFamilyStats(System.out, false, null); }
+ break;
case TPSTATS : nodeCmd.printThreadPoolStats(System.out); break;
case VERSION : nodeCmd.printReleaseVersion(System.out); break;
case COMPACTIONSTATS : nodeCmd.printCompactionStats(System.out); break;
@@ -1163,8 +1174,7 @@ public class NodeCmd
case STATUS :
- if (arguments.length > 0) nodeCmd.printClusterStatus(System.out, arguments[0]);
- else nodeCmd.printClusterStatus(System.out, null);
+ nodeCmd.printClusterStatus(System.out, arguments[0]);
break;
case DECOMMISSION :
@@ -1555,6 +1565,86 @@ public class NodeCmd
}
}
+ /**
+ * Used for filtering keyspaces and columnfamilies to be displayed using the cfstats command.
+ */
+ private static class OptionFilter
+ {
+ private Map<String, List<String>> filter = new HashMap<String, List<String>>();
+ private Map<String, List<String>> verifier = new HashMap<String, List<String>>();
+ private String [] filterList;
+ private boolean ignoreMode;
+
+ public OptionFilter(boolean ignoreMode, String... filterList)
+ {
+ this.filterList = filterList;
+ this.ignoreMode = ignoreMode;
+
+ if(filterList == null)
+ return;
+
+ for(String s : filterList)
+ {
+ String [] keyValues = s.split("\\.", 2);
+
+ // build the map that stores the ks' and cfs to use
+ if(!filter.containsKey(keyValues[0]))
+ {
+ filter.put(keyValues[0], new ArrayList<String>());
+ verifier.put(keyValues[0], new ArrayList<String>());
+
+ if(keyValues.length == 2)
+ {
+ filter.get(keyValues[0]).add(keyValues[1]);
+ verifier.get(keyValues[0]).add(keyValues[1]);
+ }
+ }
+ else
+ {
+ if(keyValues.length == 2)
+ {
+ filter.get(keyValues[0]).add(keyValues[1]);
+ verifier.get(keyValues[0]).add(keyValues[1]);
+ }
+ }
+ }
+ }
+
+ public boolean isColumnFamilyIncluded(String keyspace, String columnFamily)
+ {
+ // supplying empty params list is treated as wanting to display all kss & cfs
+ if(filterList == null)
+ return !ignoreMode;
+
+ List<String> cfs = filter.get(keyspace);
+
+ // no such keyspace is in the map
+ if (cfs == null)
+ return ignoreMode;
+ // only a keyspace with no cfs was supplied
+ // so ignore or include (based on the flag) every column family in specified keyspace
+ else if (cfs.size() == 0)
+ return !ignoreMode;
+
+ // keyspace exists, and it contains specific cfs
+ verifier.get(keyspace).remove(columnFamily);
+ return ignoreMode ^ cfs.contains(columnFamily);
+ }
+
+ public void verifyKeyspaces(List<String> keyspaces)
+ {
+ for(String ks : verifier.keySet())
+ if(!keyspaces.contains(ks))
+ throw new RuntimeException("Unknown keyspace: " + ks);
+ }
+
+ public void verifyColumnFamilies()
+ {
+ for(String ks : filter.keySet())
+ if(verifier.get(ks).size() > 0)
+ throw new RuntimeException("Unknown column families: " + verifier.get(ks).toString() + " in keyspace: " + ks);
+ }
+ }
private static class ToolOptions extends Options
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/8dcdce4e/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
----------------------------------------------------------------------
diff --git a/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml b/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
index 318aeed..8fe0519 100644
--- a/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
+++ b/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
@@ -28,9 +28,9 @@ commands:
- name: status
help: |
Print cluster information (state, load, IDs, ...)
- - name: cfstats
+ - name: cfstats [keyspace].[cfname] ...
help: |
- Print statistics on column families
+ Print statistics on column families. Use the -i flag to ignore the list of column families and display the remaining cfs.
- name: version
help: |
Print cassandra version