From a332fad07d085297ae4e4926d58456ef1f2b8fd8 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 14 Apr 2009 15:47:51 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@764840 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/cassandra/db/BinaryMemtable.java | 2 +- .../cassandra/db/ColumnFamilyStore.java | 26 ++++++- ...MBean.java => ColumnFamilyStoreMBean.java} | 68 ++++++++++++------- src/org/apache/cassandra/db/Memtable.java | 9 ++- 4 files changed, 76 insertions(+), 29 deletions(-) rename src/org/apache/cassandra/db/{MemtableMBean.java => ColumnFamilyStoreMBean.java} (62%) 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) {