From cef74a8db0578dc9edebdb20dabf25fdbcff6929 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Wed, 3 Feb 2010 23:14:08 +0000 Subject: [PATCH] give BMT a reference to CFS object instead of Strings; clean out underscores and unused code. patch by jbellis git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@906283 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/cassandra/db/BinaryMemtable.java | 82 +++++++------------ .../cassandra/db/ColumnFamilyStore.java | 4 +- 2 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/java/org/apache/cassandra/db/BinaryMemtable.java b/src/java/org/apache/cassandra/db/BinaryMemtable.java index 15418bf5ba..7f01866a35 100644 --- a/src/java/org/apache/cassandra/db/BinaryMemtable.java +++ b/src/java/org/apache/cassandra/db/BinaryMemtable.java @@ -39,46 +39,28 @@ import org.apache.cassandra.dht.IPartitioner; public class BinaryMemtable implements IFlushable { - private static Logger logger_ = Logger.getLogger(BinaryMemtable.class); - private int threshold_ = DatabaseDescriptor.getBMTThreshold() * 1024 * 1024; - private AtomicInteger currentSize_ = new AtomicInteger(0); + private static final Logger logger = Logger.getLogger(BinaryMemtable.class); + private final int threshold = DatabaseDescriptor.getBMTThreshold() * 1024 * 1024; + private final AtomicInteger currentSize = new AtomicInteger(0); /* Table and ColumnFamily name are used to determine the ColumnFamilyStore */ - private String table_; - private String cfName_; - private boolean isFrozen_ = false; - private Map columnFamilies_ = new NonBlockingHashMap(); + private boolean isFrozen = false; + private final Map columnFamilies = new NonBlockingHashMap(); /* Lock and Condition for notifying new clients about Memtable switches */ - Lock lock_ = new ReentrantLock(); - Condition condition_; - private final IPartitioner partitioner_ = StorageService.getPartitioner(); + private final Lock lock = new ReentrantLock(); + Condition condition; + private final IPartitioner partitioner = StorageService.getPartitioner(); + private final ColumnFamilyStore cfs; - BinaryMemtable(String table, String cfName) throws IOException + public BinaryMemtable(ColumnFamilyStore cfs) { - condition_ = lock_.newCondition(); - table_ = table; - cfName_ = cfName; + this.cfs = cfs; + condition = lock.newCondition(); } - public int getMemtableThreshold() - { - return currentSize_.get(); - } - - void resolveSize(int oldSize, int newSize) - { - currentSize_.addAndGet(newSize - oldSize); - } - - boolean isThresholdViolated() { - return currentSize_.get() >= threshold_; - } - - String getColumnFamily() - { - return cfName_; + return currentSize.get() >= threshold; } /* @@ -90,24 +72,23 @@ public class BinaryMemtable implements IFlushable { if (isThresholdViolated()) { - lock_.lock(); + lock.lock(); try { - ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_); - if (!isFrozen_) + if (!isFrozen) { - isFrozen_ = true; - cfStore.submitFlush(this); - cfStore.switchBinaryMemtable(key, buffer); + isFrozen = true; + cfs.submitFlush(this); + cfs.switchBinaryMemtable(key, buffer); } else { - cfStore.applyBinary(key, buffer); + cfs.applyBinary(key, buffer); } } finally { - lock_.unlock(); + lock.unlock(); } } else @@ -118,39 +99,38 @@ public class BinaryMemtable implements IFlushable public boolean isClean() { - return columnFamilies_.isEmpty(); + return columnFamilies.isEmpty(); } private void resolve(String key, byte[] buffer) { - columnFamilies_.put(partitioner_.decorateKey(key), buffer); - currentSize_.addAndGet(buffer.length + key.length()); + columnFamilies.put(partitioner.decorateKey(key), buffer); + currentSize.addAndGet(buffer.length + key.length()); } public List getSortedKeys() { - assert !columnFamilies_.isEmpty(); - logger_.info("Sorting " + this); - List keys = new ArrayList(columnFamilies_.keySet()); + assert !columnFamilies.isEmpty(); + logger.info("Sorting " + this); + List keys = new ArrayList(columnFamilies.keySet()); Collections.sort(keys); return keys; } public SSTableReader writeSortedContents(List sortedKeys) throws IOException { - logger_.info("Writing " + this); - ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_); - String path = cfStore.getTempSSTablePath(); + logger.info("Writing " + this); + String path = cfs.getTempSSTablePath(); SSTableWriter writer = new SSTableWriter(path, sortedKeys.size(), StorageService.getPartitioner()); for (DecoratedKey key : sortedKeys) { - byte[] bytes = columnFamilies_.get(key); + byte[] bytes = columnFamilies.get(key); assert bytes.length > 0; writer.append(key, bytes); } - SSTableReader sstable = writer.closeAndOpenReader(DatabaseDescriptor.getKeysCachedFraction(table_, cfName_)); - logger_.info("Completed flushing " + writer.getFilename()); + SSTableReader sstable = writer.closeAndOpenReader(DatabaseDescriptor.getKeysCachedFraction(cfs.getTable().name, cfs.getColumnFamilyName())); + logger.info("Completed flushing " + writer.getFilename()); return sstable; } } diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 4ec32aab88..b93542fa87 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -127,7 +127,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean isSuper_ = isSuper; fileIndexGenerator_.set(indexValue); memtable_ = new Memtable(table_, columnFamily_); - binaryMemtable_ = new AtomicReference(new BinaryMemtable(table_, columnFamily_)); + binaryMemtable_ = new AtomicReference(new BinaryMemtable(this)); if (logger_.isDebugEnabled()) logger_.debug("Starting CFS " + columnFamily_); @@ -396,7 +396,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean void switchBinaryMemtable(String key, byte[] buffer) throws IOException { - binaryMemtable_.set(new BinaryMemtable(table_, columnFamily_)); + binaryMemtable_.set(new BinaryMemtable(this)); binaryMemtable_.get().put(key, buffer); }