Author: jbellis
Date: Mon Dec 20 04:31:04 2010
New Revision: 1050981

URL: http://svn.apache.org/viewvc?rev=1050981&view=rev
Log:
Re-cache hotkeys post-compaction without hitting disk
patch by jbellis; reviewed by tjake for CASSANDRA-1878

Modified:
    cassandra/branches/cassandra-0.6/CHANGES.txt
    
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/CompactionManager.java
    
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableReader.java

Modified: cassandra/branches/cassandra-0.6/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=1050981&r1=1050980&r2=1050981&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.6/CHANGES.txt Mon Dec 20 04:31:04 2010
@@ -25,6 +25,7 @@
  * large row support for SSTableExport (CASSANDRA-1867)
  * return InvalidRequest when remove of subcolumn without supercolumn
    is requested (CASSANDRA-1866)
+ * Re-cache hot keys post-compaction without hitting disk (CASSANDRA-1878)
 
 
 0.6.8

Modified: 
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/CompactionManager.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/CompactionManager.java?rev=1050981&r1=1050980&r2=1050981&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/CompactionManager.java
 (original)
+++ 
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/CompactionManager.java
 Mon Dec 20 04:31:04 2010
@@ -281,6 +281,8 @@ public class CompactionManager implement
         Iterator<CompactionIterator.CompactedRow> nni = new FilterIterator(ci, 
PredicateUtils.notNullPredicate());
         executor.beginCompaction(cfs, ci);
 
+        Map<DecoratedKey, SSTable.PositionSize> cachedKeys = new 
HashMap<DecoratedKey, SSTable.PositionSize>();
+
         try
         {
             if (!nni.hasNext())
@@ -306,6 +308,15 @@ public class CompactionManager implement
                 if (rowsize > DatabaseDescriptor.getRowWarningThreshold())
                     logger.warn("Large row " + row.key.key + " in " + 
cfs.getColumnFamilyName() + " " + rowsize + " bytes");
                 cfs.addToCompactedRowStats(rowsize);
+
+                for (SSTableReader sstable : sstables)
+                {
+                    if (sstable.getCachedPosition(row.key) != null)
+                    {
+                        cachedKeys.put(row.key, new 
SSTable.PositionSize(prevpos, rowsize));
+                        break;
+                    }
+                }
             }
         }
         finally
@@ -315,6 +326,8 @@ public class CompactionManager implement
 
         SSTableReader ssTable = writer.closeAndOpenReader();
         cfs.replaceCompactedSSTables(sstables, Arrays.asList(ssTable));
+        for (Entry<DecoratedKey, SSTable.PositionSize> entry : 
cachedKeys.entrySet())
+            ssTable.cacheKey(entry.getKey(), entry.getValue());
         submitMinorIfNeeded(cfs);
 
         String format = "Compacted to %s.  %d/%d bytes for %d keys.  Time: 
%dms";

Modified: 
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableReader.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableReader.java?rev=1050981&r1=1050980&r2=1050981&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableReader.java
 (original)
+++ 
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableReader.java
 Mon Dec 20 04:31:04 2010
@@ -323,6 +323,23 @@ public class SSTableReader extends SSTab
         }
     }
 
+    public void cacheKey(DecoratedKey key, PositionSize info)
+    {
+        keyCache.put(new Pair<String, DecoratedKey>(path, key), info);
+    }
+
+    public PositionSize getCachedPosition(DecoratedKey key)
+    {
+        return getCachedPosition(new Pair<String, DecoratedKey>(path, key));
+    }
+
+    private PositionSize getCachedPosition(Pair<String, DecoratedKey> 
unifiedKey)
+    {
+        if (keyCache != null && keyCache.getCapacity() > 0)
+            return keyCache.get(unifiedKey);
+        return null;
+    }
+
     /**
      * returns the position in the data file to find the given key, or -1 if 
the key is not present
      */
@@ -334,14 +351,9 @@ public class SSTableReader extends SSTab
 
         // next, the key cache
         Pair<String, DecoratedKey> unifiedKey = new Pair<String, 
DecoratedKey>(path, decoratedKey);
-        if (keyCache != null && keyCache.getCapacity() > 0)
-        {
-            PositionSize cachedPosition = keyCache.get(unifiedKey);
-            if (cachedPosition != null)
-            {
-                return cachedPosition;
-            }
-        }
+        PositionSize cachedPosition = getCachedPosition(unifiedKey);
+        if (cachedPosition != null)
+            return cachedPosition;
 
         // next, see if the sampled index says it's impossible for the key to 
be present
         IndexSummary.KeyPosition sampledPosition = 
getIndexScanPosition(decoratedKey);


Reply via email to