cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marc...@apache.org
Subject [1/2] git commit: Fix resetAndTruncate:ing CompressionMetadata
Date Mon, 03 Mar 2014 14:05:41 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.0 41d8a5f48 -> ef20671c2


Fix resetAndTruncate:ing CompressionMetadata

Patch by kvaster, reviewed by marcuse for CASSANDRA-6791


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

Branch: refs/heads/cassandra-2.0
Commit: 64098f7d6f0b122448693a3c6da16af54c99013b
Parents: f08ae39
Author: Marcus Eriksson <marcuse@apache.org>
Authored: Mon Mar 3 15:03:34 2014 +0100
Committer: Marcus Eriksson <marcuse@apache.org>
Committed: Mon Mar 3 15:03:34 2014 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +-
 .../io/compress/CompressedSequentialWriter.java |  2 +-
 .../CompressedRandomAccessReaderTest.java       | 43 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/64098f7d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 780b528..b3c0a35 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -19,7 +19,7 @@
  * Support negative timestamps for CQL3 dates in query string (CASSANDRA-6718)
  * Avoid NPEs when receiving table changes for an unknown keyspace (CASSANDRA-5631)
  * Fix bootstrapping when there is no schema (CASSANDRA-6685)
-
+ * Fix truncating compression metadata (CASSANDRA-6791)
 
 1.2.15
  * Move handling of migration event source to solve bootstrap race (CASSANDRA-6648)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/64098f7d/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java b/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java
index 00eb5a7..da55e83 100644
--- a/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java
+++ b/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java
@@ -231,7 +231,7 @@ public class CompressedSequentialWriter extends SequentialWriter
 
         // truncate data and index file
         truncate(chunkOffset);
-        metadataWriter.resetAndTruncate(realMark.nextChunkIndex);
+        metadataWriter.resetAndTruncate(realMark.nextChunkIndex - 1);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/64098f7d/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java
b/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java
index 830c3e1..678a650 100644
--- a/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java
+++ b/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java
@@ -19,10 +19,12 @@
 package org.apache.cassandra.io.compress;
 
 import java.io.*;
+import java.util.Collections;
 import java.util.Random;
 
 import org.junit.Test;
 
+import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.io.sstable.CorruptSSTableException;
 import org.apache.cassandra.io.sstable.SSTableMetadata;
 import org.apache.cassandra.io.util.*;
@@ -95,6 +97,47 @@ public class CompressedRandomAccessReaderTest
     }
 
     @Test
+    public void test6791() throws IOException, ConfigurationException
+    {
+        File f = File.createTempFile("compressed6791_", "3");
+        String filename = f.getAbsolutePath();
+        try
+        {
+
+            SSTableMetadata.Collector sstableMetadataCollector = SSTableMetadata.createCollector().replayPosition(null);
+            CompressedSequentialWriter writer = new CompressedSequentialWriter(f, filename
+ ".metadata", false, new CompressionParameters(SnappyCompressor.instance, 32, Collections.<String,
String>emptyMap()), sstableMetadataCollector);
+
+            for (int i = 0; i < 20; i++)
+                writer.write("x".getBytes());
+
+            FileMark mark = writer.mark();
+            // write enough garbage to create new chunks:
+            for (int i = 0; i < 40; i++)
+                writer.write("y".getBytes());
+
+            writer.resetAndTruncate(mark);
+
+            for (int i = 0; i < 20; i++)
+                writer.write("x".getBytes());
+            writer.close();
+
+            CompressedRandomAccessReader reader = CompressedRandomAccessReader.open(filename,
new CompressionMetadata(filename + ".metadata", f.length()), false);
+            String res = reader.readLine();
+            assertEquals(res, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+            assertEquals(40, res.length());
+        }
+        finally
+        {
+            // cleanup
+            if (f.exists())
+                f.delete();
+            File metadata = new File(filename + ".metadata");
+                if (metadata.exists())
+                    metadata.delete();
+        }
+    }
+
+    @Test
     public void testDataCorruptionDetection() throws IOException
     {
         String CONTENT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam
vitae.";


Mime
View raw message