You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2010/01/25 19:36:19 UTC

svn commit: r902915 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra/tools: NodeCmd.java NodeProbe.java

Author: jbellis
Date: Mon Jan 25 18:36:19 2010
New Revision: 902915

URL: http://svn.apache.org/viewvc?rev=902915&view=rev
Log:
add cache info to cfstats; add setcachecapacity
patch by jbellis; reviewed by goffinet for CASSANDRA-708

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java?rev=902915&r1=902914&r2=902915&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java Mon Jan 25 18:36:19 2010
@@ -10,6 +10,11 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import javax.management.JMX;
+import javax.management.ObjectName;
+
+import org.apache.cassandra.cache.JMXAggregatingCacheMBean;
+import org.apache.cassandra.cache.JMXInstrumentedCacheMBean;
 import org.apache.cassandra.concurrent.IExecutorMBean;
 import org.apache.cassandra.db.ColumnFamilyStoreMBean;
 import org.apache.cassandra.db.CompactionManager;
@@ -45,9 +50,10 @@
     {
         HelpFormatter hf = new HelpFormatter();
         String header = String.format(
-                "%nAvailable commands: ring, info, cleanup, compact, cfstats, snapshot [name], clearsnapshot, " +
+                "%nAvailable commands: ring, info, cleanup, compact, cfstats, snapshot [snapshotname], clearsnapshot, " +
                 "tpstats, flush, repair, decommission, move, loadbalance, removetoken, " +
-                " getcompactionthreshold, setcompactionthreshold [minthreshold] ([maxthreshold])");
+                "setcachecapacity <keyspace> <cfname> <keycachecapacity> <rowcachecapacity>, " +
+                "getcompactionthreshold, setcompactionthreshold [minthreshold] ([maxthreshold])");
         String usage = String.format("java %s -host <arg> <command>%n", NodeProbe.class.getName());
         hf.printHelp(usage, "", options, header);
     }
@@ -169,7 +175,7 @@
     public void printColumnFamilyStats(PrintStream outs)
     {
         Map <String, List <ColumnFamilyStoreMBean>> cfstoreMap = new HashMap <String, List <ColumnFamilyStoreMBean>>();
-        
+
         // get a list of column family stores
         Iterator<Map.Entry<String, ColumnFamilyStoreMBean>> cfamilies = probe.getColumnFamilyStoreMBeanProxies();
 
@@ -178,7 +184,7 @@
             Map.Entry<String, ColumnFamilyStoreMBean> entry = cfamilies.next();
             String tableName = entry.getKey();
             ColumnFamilyStoreMBean cfsProxy = entry.getValue();
-            
+
             if (!cfstoreMap.containsKey(tableName))
             {
                 List<ColumnFamilyStoreMBean> columnFamilies = new ArrayList<ColumnFamilyStoreMBean>();
@@ -200,13 +206,13 @@
             int tablePendingTasks = 0;
             double tableTotalReadTime = 0.0f;
             double tableTotalWriteTime = 0.0f;
-            
+
             outs.println("Keyspace: " + tableName);
             for (ColumnFamilyStoreMBean cfstore : columnFamilies)
             {
                 int writeCount = cfstore.getWriteCount();
                 int readCount = cfstore.getReadCount();
-                
+
                 if (readCount > 0)
                 {
                     tableReadCount += readCount;
@@ -219,7 +225,7 @@
                 }
                 tablePendingTasks += cfstore.getPendingTasks();
             }
-            
+
             double tableReadLatency = tableReadCount > 0 ? tableTotalReadTime / tableReadCount : Double.NaN;
             double tableWriteLatency = tableWriteCount > 0 ? tableTotalWriteTime / tableWriteCount : Double.NaN;
 
@@ -244,6 +250,31 @@
                 outs.println("\t\tWrite Count: " + cfstore.getWriteCount());
                 outs.println("\t\tWrite Latency: " + String.format("%01.3f", cfstore.getWriteLatency()) + " ms.");
                 outs.println("\t\tPending Tasks: " + cfstore.getPendingTasks());
+
+                JMXAggregatingCacheMBean keyCacheMBean = probe.getKeyCacheMBean(tableName, cfstore.getColumnFamilyName());
+                if (keyCacheMBean.getCapacity() > 0)
+                {
+                    outs.println("\t\tKey cache capacity: " + keyCacheMBean.getCapacity());
+                    outs.println("\t\tKey cache size: " + keyCacheMBean.getSize());
+                    outs.println("\t\tKey cache hit rate: " + keyCacheMBean.getHitRate());
+                }
+                else
+                {
+                    outs.println("\t\tKey cache: disabled");
+                }
+
+                JMXInstrumentedCacheMBean rowCacheMBean = probe.getRowCacheMBean(tableName, cfstore.getColumnFamilyName());
+                if (rowCacheMBean.getCapacity() > 0)
+                {
+                    outs.println("\t\tRow cache capacity: " + rowCacheMBean.getCapacity());
+                    outs.println("\t\tRow cache size: " + rowCacheMBean.getSize());
+                    outs.println("\t\tRow cache hit rate: " + rowCacheMBean.getHitRate());
+                }
+                else
+                {
+                    outs.println("\t\tRow cache: disabled");
+                }
+
                 outs.println("");
             }
             outs.println("----------------");
@@ -375,6 +406,18 @@
             else // cmdName.equals("repair")
                 probe.forceTableRepair(cmd.getArgs()[1], columnFamilies);
         }
+        else if (cmdName.equals("setcachecapacity"))
+        {
+            if (cmd.getArgs().length != 5)
+            {
+                System.err.println("cacheinfo requires keyspace and column family name arguments, followed by key cache capacity and row cache capacity, in rows");
+            }
+            String tableName = cmd.getArgs()[1];
+            String cfName = cmd.getArgs()[2];
+            int keyCacheCapacity = Integer.valueOf(cmd.getArgs()[3]);
+            int rowCacheCapacity = Integer.valueOf(cmd.getArgs()[4]);
+            probe.setCacheCapacities(tableName, cfName, keyCacheCapacity, rowCacheCapacity);
+        }
         else if (cmdName.equals("getcompactionthreshold"))
         {
             probe.getCompactionThreshold(System.out);

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java?rev=902915&r1=902914&r2=902915&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java Mon Jan 25 18:36:19 2010
@@ -32,14 +32,14 @@
 import java.util.Set;
 import java.util.Map.Entry;
 
-import javax.management.JMX;
-import javax.management.MBeanServerConnection;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
+import javax.management.*;
 import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
+import org.apache.cassandra.cache.JMXAggregatingCache;
+import org.apache.cassandra.cache.JMXAggregatingCacheMBean;
+import org.apache.cassandra.cache.JMXInstrumentedCacheMBean;
 import org.apache.cassandra.concurrent.IExecutorMBean;
 import org.apache.cassandra.db.ColumnFamilyStoreMBean;
 import org.apache.cassandra.db.CompactionManager;
@@ -175,7 +175,33 @@
             throw new RuntimeException("Could not retrieve list of stat mbeans.", e);
         }
     }
+
+    public JMXAggregatingCacheMBean getKeyCacheMBean(String tableName, String cfName)
+    {
+        String keyCachePath = "org.apache.cassandra.db:type=Caches,keyspace=" + tableName + ",cache=" + cfName + "KeyCache";
+        try
+        {
+            return JMX.newMBeanProxy(mbeanServerConn, new ObjectName(keyCachePath), JMXAggregatingCacheMBean.class);
+        }
+        catch (MalformedObjectNameException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
     
+    public JMXInstrumentedCacheMBean getRowCacheMBean(String tableName, String cfName)
+    {
+        String rowCachePath = "org.apache.cassandra.db:type=Caches,keyspace=" + tableName + ",cache=" + cfName + "RowCache";
+        try
+        {
+            return JMX.newMBeanProxy(mbeanServerConn, new ObjectName(rowCachePath), JMXInstrumentedCacheMBean.class);
+        }
+        catch (MalformedObjectNameException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
     public String getToken()
     {
         return ssProxy.getToken();
@@ -280,7 +306,26 @@
              mcmProxy.setMaximumCompactionThreshold(maximumCompactionThreshold);
         }
     }
-    
+
+    public void setCacheCapacities(String tableName, String cfName, int keyCacheCapacity, int rowCacheCapacity)
+    {
+        try
+        {
+            String keyCachePath = "org.apache.cassandra.db:type=Caches,keyspace=" + tableName + ",cache=" + cfName + "KeyCache";
+            JMXAggregatingCacheMBean keyCacheMBean = JMX.newMBeanProxy(mbeanServerConn, new ObjectName(keyCachePath), JMXAggregatingCacheMBean.class);
+            keyCacheMBean.setCapacity(keyCacheCapacity);
+
+            String rowCachePath = "org.apache.cassandra.db:type=Caches,keyspace=" + tableName + ",cache=" + cfName + "RowCache";
+            JMXInstrumentedCacheMBean rowCacheMBean = null;
+            rowCacheMBean = JMX.newMBeanProxy(mbeanServerConn, new ObjectName(rowCachePath), JMXInstrumentedCacheMBean.class);
+            rowCacheMBean.setCapacity(rowCacheCapacity);
+        }
+        catch (MalformedObjectNameException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
     public List<InetAddress> getEndPoints(String key)
     {
         return ssProxy.getNaturalEndpoints(key);
@@ -300,13 +345,11 @@
         this.mbeanServerConn = mbeanServerConn;
     }
 
-    @Override
     public boolean hasNext()
     {
         return resIter.hasNext();
     }
 
-    @Override
     public Entry<String, ColumnFamilyStoreMBean> next()
     {
         ObjectName objectName = resIter.next();
@@ -315,7 +358,6 @@
         return new AbstractMap.SimpleImmutableEntry<String, ColumnFamilyStoreMBean>(tableName, cfsProxy);
     }
 
-    @Override
     public void remove()
     {
         throw new UnsupportedOperationException();
@@ -335,13 +377,11 @@
         this.mbeanServerConn = mbeanServerConn;
     }
     
-    @Override
     public boolean hasNext()
     {
         return resIter.hasNext();
     }
 
-    @Override
     public Map.Entry<String, IExecutorMBean> next()
     {
         ObjectName objectName = resIter.next();
@@ -350,9 +390,8 @@
         return new AbstractMap.SimpleImmutableEntry<String, IExecutorMBean>(poolName, threadPoolProxy);
     }
 
-    @Override
     public void remove()
     {
         throw new UnsupportedOperationException();
     }   
-}
\ No newline at end of file
+}