Expose index-building status in JMX + cli schema description

patch by Pavel Yaskevich; reviewed by jbellis for CASSANDRA-1871

git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1053247 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2010-12-28 03:24:41 +00:00
parent 14d0647748
commit 5995b48e82
7 changed files with 112 additions and 4 deletions

View File

@ -12,6 +12,8 @@ dev
* handle URL-specified log4j regression (CASSANDRA-1907)
* enable keepalive on intra-cluster sockets (CASSANDRA-1766)
* count timeouts towards dynamicsnitch latencies (CASSANDRA-1905)
* Expose index-building status in JMX + cli schema description
(CASSANDRA-1871)
0.7.0-rc3

View File

@ -17,6 +17,7 @@
*/
package org.apache.cassandra.cli;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.*;
@ -25,8 +26,11 @@ import com.google.common.base.Charsets;
import org.antlr.runtime.tree.Tree;
import org.apache.cassandra.auth.SimpleAuthenticator;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.db.ColumnFamilyStoreMBean;
import org.apache.cassandra.db.CompactionManagerMBean;
import org.apache.cassandra.db.marshal.*;
import org.apache.cassandra.thrift.*;
import org.apache.cassandra.tools.NodeProbe;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.UUIDGen;
@ -1206,6 +1210,11 @@ public class CliClient extends CliUserHelp
private void describeKeySpace(String keySpaceName, KsDef metadata) throws TException
{
NodeProbe probe = sessionState.getNodeProbe();
// getting compaction manager MBean to displaying index building information
CompactionManagerMBean compactionManagerMBean = (probe == null) ? null : probe.getCompactionManagerProxy();
// Describe and display
sessionState.out.println("Keyspace: " + keySpaceName + ":");
try
@ -1213,10 +1222,12 @@ public class CliClient extends CliUserHelp
KsDef ks_def;
ks_def = metadata == null ? thriftClient.describe_keyspace(keySpaceName) : metadata;
sessionState.out.println(" Replication Strategy: " + ks_def.strategy_class);
if (ks_def.strategy_class.endsWith(".NetworkTopologyStrategy"))
sessionState.out.println(" Options: " + FBUtilities.toString(ks_def.strategy_options));
else
sessionState.out.println(" Replication Factor: " + ks_def.replication_factor);
sessionState.out.println(" Column Families:");
boolean isSuper;
@ -1224,6 +1235,9 @@ public class CliClient extends CliUserHelp
Collections.sort(ks_def.cf_defs, new CfDefNamesComparator());
for (CfDef cf_def : ks_def.cf_defs)
{
// fetching bean for current column family store
ColumnFamilyStoreMBean cfMBean = (probe == null) ? null : probe.getCfsProxy(ks_def.getName(), cf_def.getName());
isSuper = cf_def.column_type.equals("Super");
sessionState.out.printf(" ColumnFamily: %s%s%n", cf_def.name, isSuper ? " (Super)" : "");
@ -1241,6 +1255,12 @@ public class CliClient extends CliUserHelp
sessionState.out.printf(" Compaction min/max thresholds: %s/%s%n", cf_def.min_compaction_threshold, cf_def.max_compaction_threshold);
sessionState.out.printf(" Read repair chance: %s%n", cf_def.read_repair_chance);
// if we have connection to the cfMBean established
if (cfMBean != null)
{
sessionState.out.printf(" Built indexes: %s%n", cfMBean.getBuiltIndexes());
}
if (cf_def.getColumn_metadataSize() != 0)
{
String leftSpace = " ";
@ -1281,6 +1301,26 @@ public class CliClient extends CliUserHelp
}
}
}
// compaction manager information
if (compactionManagerMBean != null)
{
String compactionType = compactionManagerMBean.getCompactionType();
// if ongoing compaction type is index build
if (compactionType != null && compactionType.contains("index build"))
{
String indexName = compactionManagerMBean.getColumnFamilyInProgress();
long bytesCompacted = compactionManagerMBean.getBytesCompacted();
long totalBytesToProcess = compactionManagerMBean.getBytesTotalInProgress();
sessionState.out.printf("%nCurrently building index %s, completed %d of %d bytes.%n", indexName, bytesCompacted, totalBytesToProcess);
}
}
// closing JMX connection
if (probe != null)
probe.close();
}
catch (InvalidRequestException e)
{
@ -1290,7 +1330,12 @@ public class CliClient extends CliUserHelp
{
sessionState.out.println("Keyspace " + keySpaceName + " could not be found.");
}
catch (IOException e)
{
sessionState.out.println("Error while closing JMX connection: " + e.getMessage());
}
}
// DESCRIBE KEYSPACE <keyspace_name>
private void executeDescribeKeySpace(Tree statement) throws TException, InvalidRequestException
{

View File

@ -39,7 +39,8 @@ public class CliOptions {
private static final String BATCH_OPTION = "batch";
private static final String HELP_OPTION = "help";
private static final String FILE_OPTION = "file";
private static final String JMX_PORT_OPTION = "jmxport";
// Default values for optional command line arguments
private static final int DEFAULT_THRIFT_PORT = 9160;
@ -57,12 +58,13 @@ public class CliOptions {
options.addOption(KEYSPACE_OPTION, true, "cassandra keyspace user is authenticated against");
options.addOption(BATCH_OPTION, false, "enabled batch mode (supress output; errors are fatal)");
options.addOption(FILE_OPTION, true, "load statements from the specific file.");
options.addOption(JMX_PORT_OPTION, true, "JMX service port.");
options.addOption(HELP_OPTION, false, "usage help.");
}
private static void printUsage()
{
System.err.println("Usage: cassandra-cli --host hostname [--port <portname>] [--file <filename>] [--unframed] [--debug]");
System.err.println("Usage: cassandra-cli --host hostname [--port <port>] [--jmxport <port>] [--file <filename>] [--unframed] [--debug]");
System.err.println("\t[--username username] [--password password] [--keyspace keyspace] [--batch] [--help]");
}
@ -138,6 +140,11 @@ public class CliOptions {
css.filename = cmd.getOptionValue(FILE_OPTION);
}
if (cmd.hasOption(JMX_PORT_OPTION))
{
css.jmxPort = Integer.parseInt(cmd.getOptionValue(JMX_PORT_OPTION));
}
if (cmd.hasOption(HELP_OPTION))
{
printUsage();

View File

@ -18,6 +18,8 @@
package org.apache.cassandra.cli;
import org.apache.cassandra.tools.NodeProbe;
import java.io.InputStream;
import java.io.PrintStream;
@ -36,6 +38,7 @@ public class CliSessionState
public String keyspace; // cassandra keyspace user is authenticating
public boolean batch = false; // enable/disable batch processing mode
public String filename = ""; // file to read commands from
public int jmxPort = 8080;// JMX service port
/*
* Streams to read/write from
@ -65,4 +68,19 @@ public class CliSessionState
{
return !this.filename.isEmpty();
}
public NodeProbe getNodeProbe()
{
try
{
return new NodeProbe(hostName, jmxPort);
}
catch (Exception e)
{
err.printf("WARNING: Could not connect to the JMX on %s:%d, information won't be shown.%n%n", hostName, jmxPort);
}
return null;
}
}

View File

@ -318,7 +318,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
return;
// if we're just linking in the index to indexedColumns on an already-built index post-restart, we're done
if (SystemTable.isIndexBuilt(table.name, indexedCfMetadata.cfName))
if (indexedCfs.isIndexBuilt())
return;
// build it asynchronously; addIndex gets called by CFS open and schema update, neither of which
@ -1929,4 +1929,33 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
return histogram;
}
/**
* Check if index is already built for current store
* @return true if built, false otherwise
*/
public boolean isIndexBuilt()
{
return SystemTable.isIndexBuilt(table.name, columnFamily);
}
/**
* Returns a list of the names of the built column indexes for current store
* @return list of the index names
*/
public List<String> getBuiltIndexes()
{
List<String> indexes = new ArrayList<String>();
for (ColumnFamilyStore cfs : indexedColumns.values())
{
if (cfs.isIndexBuilt())
{
indexes.add(cfs.columnFamily); // store.columnFamily represents a name of the index
}
}
return indexes;
}
}

View File

@ -19,6 +19,7 @@
package org.apache.cassandra.db;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
@ -213,4 +214,10 @@ public interface ColumnFamilyStoreMBean
public long[] getEstimatedRowSizeHistogram();
public long[] getEstimatedColumnCountHistogram();
/**
* Returns a list of the names of the built column indexes for current store
* @return list of the index names
*/
public List<String> getBuiltIndexes();
}

View File

@ -643,7 +643,7 @@ public class Table
public String getTaskType()
{
return "Secondary index build";
return String.format("Secondary index build %s", cfs.columnFamily);
}
}