Author: jbellis
Date: Tue Apr 14 15:47:40 2009
New Revision: 764840

URL: http://svn.apache.org/viewvc?rev=764840&view=rev
Log:
add instrumentation for memtable attributes

The current Memtable class implements an MBean interface, but it is not
wired up. Most likely, this is because it would become defunct after
the first flush when the memtable is switched out for a new one.

The solution is to instrument ColumnFamilyStore and expose the memtable
attributes from there.

patch by Eric Evans; reviewed by jbellis for #75

Added:
    
incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
      - copied, changed from r764679, 
incubator/cassandra/trunk/src/org/apache/cassandra/db/MemtableMBean.java
Removed:
    incubator/cassandra/trunk/src/org/apache/cassandra/db/MemtableMBean.java
Modified:
    incubator/cassandra/trunk/src/org/apache/cassandra/db/BinaryMemtable.java
    incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStore.java
    incubator/cassandra/trunk/src/org/apache/cassandra/db/Memtable.java

Modified: 
incubator/cassandra/trunk/src/org/apache/cassandra/db/BinaryMemtable.java
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/db/BinaryMemtable.java?rev=764840&r1=764839&r2=764840&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/db/BinaryMemtable.java 
(original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/db/BinaryMemtable.java 
Tue Apr 14 15:47:40 2009
@@ -39,7 +39,7 @@
  * Author : Avinash Lakshman ( [email protected]) & Prashant Malik ( 
[email protected] )
  */
 
-public class BinaryMemtable implements MemtableMBean
+public class BinaryMemtable
 {
     private static Logger logger_ = Logger.getLogger( Memtable.class );
     private int threshold_ = 512*1024*1024;

Modified: 
incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStore.java
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStore.java?rev=764840&r1=764839&r2=764840&view=diff
==============================================================================
--- 
incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStore.java 
(original)
+++ 
incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStore.java 
Tue Apr 14 15:47:40 2009
@@ -20,6 +20,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -56,7 +59,7 @@
  * Author : Avinash Lakshman ( [email protected]) & Prashant Malik ( 
[email protected] )
  */
 
-public class ColumnFamilyStore
+public class ColumnFamilyStore implements ColumnFamilyStoreMBean
 {
     private static int threshHold_ = 4;
     private static final int bufSize_ = 128*1024*1024;
@@ -116,6 +119,17 @@
         fileIndexGenerator_.set(value);
         memtable_ = new AtomicReference<Memtable>( new Memtable(table_, 
columnFamily_) );
         binaryMemtable_ = new AtomicReference<BinaryMemtable>( new 
BinaryMemtable(table_, columnFamily_) );
+        
+        try
+        {
+            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+            mbs.registerMBean(this, new ObjectName(
+                    "org.apache.cassandra.db:type=ColumnFamilyStore-" + 
columnFamily_));
+        }
+        catch (Exception e)
+        {
+            logger_.error(LogUtil.throwableToString(e));
+        }
     }
 
     void onStart() throws IOException
@@ -1356,4 +1370,14 @@
     {
         memtable_.get().flushOnRecovery();
     }
+
+    public int getMemtableColumnsCount()
+    {
+        return memtable_.get().getCurrentObjectCount();
+    }
+
+    public int getMemtableDataSize()
+    {
+        return memtable_.get().getCurrentSize();
+    }
 }

Copied: 
incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
 (from r764679, 
incubator/cassandra/trunk/src/org/apache/cassandra/db/MemtableMBean.java)
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStoreMBean.java?p2=incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStoreMBean.java&p1=incubator/cassandra/trunk/src/org/apache/cassandra/db/MemtableMBean.java&r1=764679&r2=764840&rev=764840&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/db/MemtableMBean.java 
(original)
+++ 
incubator/cassandra/trunk/src/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
 Tue Apr 14 15:47:40 2009
@@ -1,25 +1,43 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.cassandra.db;
-
-
-public interface MemtableMBean
-{
-    public int getMemtableThreshold();
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db;
+
+/**
+ * The MBean interface for ColumnFamilyStore
+ * 
+ * @author Eric Evans
+ *
+ */
+public interface ColumnFamilyStoreMBean
+{
+    /**
+     * Returns the total amount of data stored in the memtable, including
+     * column related overhead.
+     * 
+     * @return The size in bytes.
+     */
+    public int getMemtableDataSize();
+    
+    /**
+     * Returns the total number of columns present in the memtable.
+     * 
+     * @return The number of columns.
+     */
+    public int getMemtableColumnsCount();
+}

Modified: incubator/cassandra/trunk/src/org/apache/cassandra/db/Memtable.java
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/db/Memtable.java?rev=764840&r1=764839&r2=764840&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/db/Memtable.java 
(original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/db/Memtable.java Tue Apr 
14 15:47:40 2009
@@ -54,7 +54,7 @@
  * Author : Avinash Lakshman ( [email protected]) & Prashant Malik ( 
[email protected] )
  */
 
-public class Memtable implements MemtableMBean, Comparable<Memtable>
+public class Memtable implements Comparable<Memtable>
 {
        private static Logger logger_ = Logger.getLogger( Memtable.class );
     private static Map<String, ExecutorService> apartments_ = new 
HashMap<String, ExecutorService>();
@@ -183,10 +183,15 @@
                return 0;
     }
 
-    public int getMemtableThreshold()
+    public int getCurrentSize()
     {
         return currentSize_.get();
     }
+    
+    public int getCurrentObjectCount()
+    {
+        return currentObjectCount_.get();
+    }
 
     void resolveSize(int oldSize, int newSize)
     {


Reply via email to