Author: jbellis
Date: Mon Sep 12 15:50:16 2011
New Revision: 1169807

URL: http://svn.apache.org/viewvc?rev=1169807&view=rev
Log:
remove allocator.size() from Memtable.getLiveSize calculation
patch by jbellis and stuhood for CASSANDRA-3168

Modified:
    cassandra/branches/cassandra-1.0.0/CHANGES.txt
    cassandra/branches/cassandra-1.0.0/NEWS.txt
    
cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/db/Memtable.java
    
cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/utils/SlabAllocator.java

Modified: cassandra/branches/cassandra-1.0.0/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0.0/CHANGES.txt?rev=1169807&r1=1169806&r2=1169807&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0.0/CHANGES.txt (original)
+++ cassandra/branches/cassandra-1.0.0/CHANGES.txt Mon Sep 12 15:50:16 2011
@@ -67,7 +67,7 @@
  * fix inconsistency of the CLI syntax when {} should be used instead of [{}]
    (CASSANDRA-3119)
  * rename CQL type names to match expected SQL behavior (CASSANDRA-3149, 3031)
- * Arena-based allocation for memtables (CASSANDRA-2252, 3162, 3163)
+ * Arena-based allocation for memtables (CASSANDRA-2252, 3162, 3163, 3168)
  * Default RR chance to 0.1 (CASSANDRA-3169)
 
 

Modified: cassandra/branches/cassandra-1.0.0/NEWS.txt
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0.0/NEWS.txt?rev=1169807&r1=1169806&r2=1169807&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0.0/NEWS.txt (original)
+++ cassandra/branches/cassandra-1.0.0/NEWS.txt Mon Sep 12 15:50:16 2011
@@ -11,6 +11,9 @@ Upgrading
     - CQL types bytea and date were renamed to blob and timestamp, 
respectively,
       to conform with SQL norms.  CQL type int is now a 4-byte int, not 8
       (which is still available as bigint).
+    - Cassandra 1.0 uses arena allocation to reduce old generation 
fragmentation.
+      This means there is a minimum overhead of 1MB per ColumnFamily plus
+      1MB per index.
 
 Features
 --------

Modified: 
cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/db/Memtable.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/db/Memtable.java?rev=1169807&r1=1169806&r2=1169807&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/db/Memtable.java
 (original)
+++ 
cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/db/Memtable.java
 Mon Sep 12 15:50:16 2011
@@ -90,7 +90,7 @@ public class Memtable
     {
         // 25% fudge factor on the base throughput * liveRatio calculation.  
(Based on observed
         // pre-slabbing behavior -- not sure what accounts for this. May have 
changed with introduction of slabbing.)
-        return (long) (currentThroughput.get() * cfs.liveRatio * 1.25) + 
allocator.size();
+        return (long) (currentThroughput.get() * cfs.liveRatio * 1.25);
     }
 
     public long getSerializedSize()

Modified: 
cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/utils/SlabAllocator.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/utils/SlabAllocator.java?rev=1169807&r1=1169806&r2=1169807&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/utils/SlabAllocator.java
 (original)
+++ 
cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/utils/SlabAllocator.java
 Mon Sep 12 15:50:16 2011
@@ -29,6 +29,8 @@ import java.util.concurrent.atomic.Atomi
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.MapMaker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The SlabAllocator is a bump-the-pointer allocator that allocates
@@ -46,24 +48,13 @@ import com.google.common.collect.MapMake
  */
 public class SlabAllocator extends Allocator
 {
+    private static Logger logger = 
LoggerFactory.getLogger(SlabAllocator.class);
+
     private final static int REGION_SIZE = 1024 * 1024;
     private final static int MAX_CLONED_SIZE = 128 * 1024; // bigger than this 
don't go in the region
 
     private final AtomicReference<Region> currentRegion = new 
AtomicReference<Region>();
-    private final Collection<Region> filledRegions = 
Collections.newSetFromMap(new MapMaker().weakKeys().<Region, Boolean>makeMap());
-
-    /** @return Total number of bytes allocated by this allocator. */
-    public long size()
-    {
-        Iterable<Region> regions = filledRegions;
-        if (currentRegion.get() != null)
-            regions = Iterables.concat(regions, 
Collections.<Region>singleton(currentRegion.get()));
-
-        long total = 0;
-        for (Region region : regions)
-            total += region.size;
-        return total;
-    }
+    private volatile int regionCount;
 
     public ByteBuffer allocate(int size)
     {
@@ -86,23 +77,11 @@ public class SlabAllocator extends Alloc
                 return cloned;
 
             // not enough space!
-            tryRetireRegion(region);
+            currentRegion.compareAndSet(region, null);
         }
     }
     
     /**
-     * Try to retire the current region if it is still <code>region</code>.
-     * Postcondition is that curRegion.get() != region
-     */
-    private void tryRetireRegion(Region region)
-    {
-        if (currentRegion.compareAndSet(region, null))
-        {
-            filledRegions.add(region);
-        }
-    }
-
-    /**
      * Get the current region, or, if there is no current region, allocate a 
new one
      */
     private Region getRegion()
@@ -122,6 +101,8 @@ public class SlabAllocator extends Alloc
             {
                 // we won race - now we need to actually do the expensive 
allocation step
                 region.init();
+                regionCount++;
+                logger.debug("{} regions now allocated in {}", regionCount, 
this);
                 return region;
             }
             // someone else won race - that's fine, we'll try to grab theirs


Reply via email to