cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject [2/2] git commit: avoid quadratic startup time in LeveledManifest
Date Tue, 06 Mar 2012 08:38:11 GMT
avoid quadratic startup time in LeveledManifest

patch by Dave Brosius; reviewed by scode (and partially jbellis) for CASSANDRA-3952


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e58540fe
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e58540fe
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e58540fe

Branch: refs/heads/cassandra-1.1
Commit: e58540fe368ed5f3d3c0d877fdaacc245fbce3bb
Parents: 154daa0
Author: Peter Schuller <peter.schuller@infidyne.com>
Authored: Tue Mar 6 00:35:55 2012 -0800
Committer: Peter Schuller <peter.schuller@infidyne.com>
Committed: Tue Mar 6 00:35:55 2012 -0800

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../cassandra/db/compaction/LeveledManifest.java   |   18 +++++++++-----
 2 files changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e58540fe/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 86ab50a..bebe029 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -18,6 +18,7 @@
  * perform static initialization of StorageProxy on start-up (CASSANDRA-3797)
  * support trickling fsync() on writes (CASSANDRA-3950)
  * expose counters for unavailable/timeout exceptions given to thrift clients (CASSANDRA-3671)
+ * avoid quadratic startup time in LeveledManifest (CASSANDRA-3952)
 Merged from 1.0:
  * remove the wait on hint future during write (CASSANDRA-3870)
  * (cqlsh) ignore missing CfDef opts (CASSANDRA-3933)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e58540fe/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java b/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java
index a546cbc..d2edebe 100644
--- a/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java
+++ b/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java
@@ -59,6 +59,7 @@ public class LeveledManifest
 
     private final ColumnFamilyStore cfs;
     private final List<SSTableReader>[] generations;
+    private final Map<SSTableReader, Integer> sstableGenerations;
     private final RowPosition[] lastCompactedKeys;
     private final int maxSSTableSizeInMB;
 
@@ -76,6 +77,7 @@ public class LeveledManifest
             generations[i] = new ArrayList<SSTableReader>();
             lastCompactedKeys[i] = cfs.partitioner.getMinimumToken().minKeyBound();
         }
+        sstableGenerations = new HashMap<SSTableReader, Integer>();
     }
 
     static LeveledManifest create(ColumnFamilyStore cfs, int maxSSTableSize)
@@ -138,7 +140,7 @@ public class LeveledManifest
     }
 
     /**
-     * if the number of SSTables in the current compacted set *by itself* exeeds the target
level's
+     * if the number of SSTables in the current compacted set *by itself* exceeds the target
level's
      * (regardless of the level's current contents), find an empty level instead
      */
     private int skipLevels(int newLevel, Iterable<SSTableReader> added)
@@ -165,6 +167,7 @@ public class LeveledManifest
         for (SSTableReader sstable : removed)
         {
             int thisLevel = levelOf(sstable);
+            assert thisLevel >= 0;
             maximumLevel = Math.max(maximumLevel, thisLevel);
             minimumLevel = Math.min(minimumLevel, thisLevel);
             remove(sstable);
@@ -283,12 +286,11 @@ public class LeveledManifest
 
     private int levelOf(SSTableReader sstable)
     {
-        for (int level = 0; level < generations.length; level++)
-        {
-            if (generations[level].contains(sstable))
-                return level;
-        }
-        return -1;
+        Integer level = sstableGenerations.get(sstable);
+        if (level == null)
+            return -1;
+
+        return level.intValue();
     }
 
     private void remove(SSTableReader reader)
@@ -296,12 +298,14 @@ public class LeveledManifest
         int level = levelOf(reader);
         assert level >= 0 : reader + " not present in manifest";
         generations[level].remove(reader);
+        sstableGenerations.remove(reader);
     }
 
     private void add(SSTableReader sstable, int level)
     {
         assert level < generations.length : "Invalid level " + level + " out of " + (generations.length
- 1);
         generations[level].add(sstable);
+        sstableGenerations.put(sstable, Integer.valueOf(level));
     }
 
     private static List<SSTableReader> overlapping(SSTableReader sstable, Iterable<SSTableReader>
candidates)


Mime
View raw message