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
This commit is contained in:
Jonathan Ellis 2009-04-14 15:47:51 +00:00
parent 732695503b
commit a332fad07d
4 changed files with 76 additions and 29 deletions

View File

@ -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;

View File

@ -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<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 @@ public class ColumnFamilyStore
{
memtable_.get().flushOnRecovery();
}
public int getMemtableColumnsCount()
{
return memtable_.get().getCurrentObjectCount();
}
public int getMemtableDataSize()
{
return memtable_.get().getCurrentSize();
}
}

View File

@ -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();
}

View File

@ -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<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 @@ public class Memtable implements MemtableMBean, Comparable<Memtable>
return 0;
}
public int getMemtableThreshold()
public int getCurrentSize()
{
return currentSize_.get();
}
public int getCurrentObjectCount()
{
return currentObjectCount_.get();
}
void resolveSize(int oldSize, int newSize)
{