diff --git a/src/org/apache/cassandra/db/BinaryMemtable.java b/src/org/apache/cassandra/db/BinaryMemtable.java index 64dc2b4944..558680bd7e 100644 --- a/src/org/apache/cassandra/db/BinaryMemtable.java +++ b/src/org/apache/cassandra/db/BinaryMemtable.java @@ -39,7 +39,7 @@ import org.cliffc.high_scale_lib.NonBlockingHashMap; * Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com ) */ -public class BinaryMemtable implements MemtableMBean +public class BinaryMemtable { private static Logger logger_ = Logger.getLogger( Memtable.class ); private int threshold_ = 512*1024*1024; diff --git a/src/org/apache/cassandra/db/ColumnFamilyStore.java b/src/org/apache/cassandra/db/ColumnFamilyStore.java index 8e414b6258..6649000f7b 100644 --- a/src/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/org/apache/cassandra/db/ColumnFamilyStore.java @@ -20,6 +20,9 @@ package org.apache.cassandra.db; 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 @@ import org.apache.cassandra.utils.LogUtil; * Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com ) */ -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 @@ public class ColumnFamilyStore fileIndexGenerator_.set(value); memtable_ = new AtomicReference( new Memtable(table_, columnFamily_) ); binaryMemtable_ = new AtomicReference( 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 @@ public class ColumnFamilyStore { memtable_.get().flushOnRecovery(); } + + public int getMemtableColumnsCount() + { + return memtable_.get().getCurrentObjectCount(); + } + + public int getMemtableDataSize() + { + return memtable_.get().getCurrentSize(); + } } diff --git a/src/org/apache/cassandra/db/MemtableMBean.java b/src/org/apache/cassandra/db/ColumnFamilyStoreMBean.java similarity index 62% rename from src/org/apache/cassandra/db/MemtableMBean.java rename to src/org/apache/cassandra/db/ColumnFamilyStoreMBean.java index 555391c9af..afa02c7a03 100644 --- a/src/org/apache/cassandra/db/MemtableMBean.java +++ b/src/org/apache/cassandra/db/ColumnFamilyStoreMBean.java @@ -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(); +} diff --git a/src/org/apache/cassandra/db/Memtable.java b/src/org/apache/cassandra/db/Memtable.java index c64bb05171..518afbaf30 100644 --- a/src/org/apache/cassandra/db/Memtable.java +++ b/src/org/apache/cassandra/db/Memtable.java @@ -54,7 +54,7 @@ import org.apache.cassandra.service.StorageService; * Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com ) */ -public class Memtable implements MemtableMBean, Comparable +public class Memtable implements Comparable { private static Logger logger_ = Logger.getLogger( Memtable.class ); private static Map apartments_ = new HashMap(); @@ -183,10 +183,15 @@ public class Memtable implements MemtableMBean, Comparable return 0; } - public int getMemtableThreshold() + public int getCurrentSize() { return currentSize_.get(); } + + public int getCurrentObjectCount() + { + return currentObjectCount_.get(); + } void resolveSize(int oldSize, int newSize) {