You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jm...@apache.org on 2015/03/13 19:06:57 UTC

cassandra git commit: Fix SSTableRewriter when early re-open disabled

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 9caf0457a -> d97e7cb69


Fix SSTableRewriter when early re-open disabled

Patch by jmckenzie; reviewed by marcuse for CASSANDRA-8535


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

Branch: refs/heads/cassandra-2.1
Commit: d97e7cb69ebe8794adeb5be00b58a1b828bffd26
Parents: 9caf045
Author: Joshua McKenzie <jm...@apache.org>
Authored: Fri Mar 13 13:01:04 2015 -0500
Committer: Joshua McKenzie <jm...@apache.org>
Committed: Fri Mar 13 13:01:04 2015 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/io/sstable/SSTableRewriter.java   | 34 +++++++++++++++-----
 2 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/d97e7cb6/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 04861f0..d7ab277 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.4
+ * Fix SSTableRewriter with disabled early open (CASSANDRA-8535)
  * Allow invalidating permissions and cache time (CASSANDRA-8722)
  * Log warning when queries that will require ALLOW FILTERING in Cassandra 3.0
    are executed (CASSANDRA-8418)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d97e7cb6/src/java/org/apache/cassandra/io/sstable/SSTableRewriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableRewriter.java b/src/java/org/apache/cassandra/io/sstable/SSTableRewriter.java
index 914ce1f..641dd7c 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableRewriter.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableRewriter.java
@@ -20,7 +20,6 @@ package org.apache.cassandra.io.sstable;
 import java.util.*;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Functions;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 
@@ -56,7 +55,7 @@ public class SSTableRewriter
     static
     {
         long interval = DatabaseDescriptor.getSSTablePreempiveOpenIntervalInMB() * (1L << 20);
-        if (interval < 0)
+        if (interval < 0 || FBUtilities.isWindows())
             interval = Long.MAX_VALUE;
         preemptiveOpenInterval = interval;
     }
@@ -79,6 +78,7 @@ public class SSTableRewriter
     private SSTableReader currentlyOpenedEarly; // the reader for the most recent (re)opening of the target file
     private long currentlyOpenedEarlyAt; // the position (in MB) in the target file we last (re)opened at
 
+    private final List<SSTableReader> finishedReaders = new ArrayList<>();
     private final Queue<Finished> finishedEarly = new ArrayDeque<>();
     // as writers are closed from finishedEarly, their last readers are moved
     // into discard, so that abort can cleanup after us safely
@@ -159,7 +159,7 @@ public class SSTableRewriter
 
     private void maybeReopenEarly(DecoratedKey key)
     {
-        if (!FBUtilities.isWindows() && writer.getFilePointer() - currentlyOpenedEarlyAt > preemptiveOpenInterval)
+        if (writer.getFilePointer() - currentlyOpenedEarlyAt > preemptiveOpenInterval)
         {
             if (isOffline)
             {
@@ -365,13 +365,22 @@ public class SSTableRewriter
             return;
         }
 
-        // we leave it as a tmp file, but we open it and add it to the dataTracker
         if (writer.getFilePointer() != 0)
         {
-            SSTableReader reader = writer.finish(SSTableWriter.FinishType.EARLY, maxAge, -1);
-            replaceEarlyOpenedFile(currentlyOpenedEarly, reader);
-            moveStarts(reader, reader.last, false);
-            finishedEarly.add(new Finished(writer, reader));
+            // If early re-open is disabled, simply finalize the writer and store it
+            if (preemptiveOpenInterval == Long.MAX_VALUE)
+            {
+                SSTableReader reader = writer.finish(SSTableWriter.FinishType.NORMAL, maxAge, -1);
+                finishedReaders.add(reader);
+            }
+            else
+            {
+                // we leave it as a tmp file, but we open it and add it to the dataTracker
+                SSTableReader reader = writer.finish(SSTableWriter.FinishType.EARLY, maxAge, -1);
+                replaceEarlyOpenedFile(currentlyOpenedEarly, reader);
+                moveStarts(reader, reader.last, false);
+                finishedEarly.add(new Finished(writer, reader));
+            }
         }
         else
         {
@@ -427,6 +436,15 @@ public class SSTableRewriter
         if (throwEarly)
             throw new RuntimeException("exception thrown early in finish, for testing");
 
+        // No early open to finalize and replace
+        if (preemptiveOpenInterval == Long.MAX_VALUE)
+        {
+            replaceWithFinishedReaders(finishedReaders);
+            if (throwLate)
+                throw new RuntimeException("exception thrown after all sstables finished, for testing");
+            return finishedReaders;
+        }
+
         while (!finishedEarly.isEmpty())
         {
             Finished f = finishedEarly.peek();