cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [4/8] git commit: remove sstables efficiently during cleanup that contain no keys that belong on this node patch by jbellis; reviewed by slebresne and Ben Coverston for CASSANDRA-4079
Date Mon, 16 Apr 2012 20:46:20 GMT
remove sstables efficiently during cleanup that contain no keys that belong on this node
patch by jbellis; reviewed by slebresne and Ben Coverston for CASSANDRA-4079


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

Branch: refs/heads/trunk
Commit: 57b9a346cb023da3d3a2cea09d9fed9298be7cc9
Parents: e48b940
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Tue Mar 27 11:59:07 2012 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Mon Apr 16 15:31:47 2012 -0500

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../cassandra/db/compaction/CompactionManager.java |    7 +++++
 .../org/apache/cassandra/dht/AbstractBounds.java   |   11 ++++++++
 src/java/org/apache/cassandra/dht/Range.java       |   19 +++++++++++++++
 4 files changed, 38 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/57b9a346/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index a539e66..1b8377a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 1.1.1-dev
+ * optimize cleanup to drop entire sstables where possible (CASSANDRA-4079)
  * optimize truncate when autosnapshot is disabled (CASSANDRA-4153)
  * add support for commitlog archiving and point-in-time recovery
    (CASSANDRA-3647)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57b9a346/src/java/org/apache/cassandra/db/compaction/CompactionManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java
index d14a13a..0ecac5c 100644
--- a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java
+++ b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java
@@ -40,6 +40,7 @@ import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.compaction.CompactionInfo.Holder;
 import org.apache.cassandra.db.index.SecondaryIndex;
 import org.apache.cassandra.db.index.SecondaryIndexBuilder;
+import org.apache.cassandra.dht.Bounds;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.io.sstable.*;
@@ -671,6 +672,12 @@ public class CompactionManager implements CompactionManagerMBean
 
         for (SSTableReader sstable : sstables)
         {
+            if (!new Bounds<Token>(sstable.first.token, sstable.last.token).intersects(ranges))
+            {
+                cfs.replaceCompactedSSTables(Arrays.asList(sstable), Collections.<SSTableReader>emptyList(),
OperationType.CLEANUP);
+                continue;
+            }
+
             CompactionController controller = new CompactionController(cfs, Collections.singletonList(sstable),
getDefaultGcBefore(cfs), false);
             long startTime = System.currentTimeMillis();
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57b9a346/src/java/org/apache/cassandra/dht/AbstractBounds.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/dht/AbstractBounds.java b/src/java/org/apache/cassandra/dht/AbstractBounds.java
index da93292..02f5f79 100644
--- a/src/java/org/apache/cassandra/dht/AbstractBounds.java
+++ b/src/java/org/apache/cassandra/dht/AbstractBounds.java
@@ -82,6 +82,17 @@ public abstract class AbstractBounds<T extends RingPosition> implements
Serializ
         return 31 * left.hashCode() + right.hashCode();
     }
 
+    /** return true if @param range intersects any of the given @param ranges */
+    public boolean intersects(Iterable<Range<T>> ranges)
+    {
+        for (Range<T> range2 : ranges)
+        {
+            if (range2.intersects(this))
+                return true;
+        }
+        return false;
+    }
+
     public abstract boolean contains(T start);
 
     public abstract List<? extends AbstractBounds<T>> unwrap();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57b9a346/src/java/org/apache/cassandra/dht/Range.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/dht/Range.java b/src/java/org/apache/cassandra/dht/Range.java
index 888c0ca..d6137d4 100644
--- a/src/java/org/apache/cassandra/dht/Range.java
+++ b/src/java/org/apache/cassandra/dht/Range.java
@@ -121,6 +121,25 @@ public class Range<T extends RingPosition> extends AbstractBounds<T>
implements
         return intersectionWith(that).size() > 0;
     }
 
+    public boolean intersects(AbstractBounds<T> that)
+    {
+        // implemented for cleanup compaction membership test, so only Range + Bounds are
supported for now
+        if (that instanceof Range)
+            return intersects((Range) that);
+        if (that instanceof Bounds)
+            return intersects((Bounds) that);
+        throw new UnsupportedOperationException("Intersection is only supported for Bounds
and Range objects; found " + that.getClass());
+    }
+
+    /**
+     * @param that range to check for intersection
+     * @return true if the given range intersects with this range.
+     */
+    public boolean intersects(Bounds<T> that)
+    {
+        return intersects(new Range<T>(that.left, that.right)) || contains(that.right);
+    }
+
     public static <T extends RingPosition> Set<Range<T>> rangeSet(Range<T>
... ranges)
     {
         return Collections.unmodifiableSet(new HashSet<Range<T>>(Arrays.asList(ranges)));


Mime
View raw message