cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [1/2] git commit: apply CASSANDRA-8027 to cassandra-2.0 branch
Date Mon, 20 Oct 2014 17:34:15 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 6cca24f44 -> ba681300b


apply CASSANDRA-8027 to cassandra-2.0 branch


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

Branch: refs/heads/cassandra-2.1
Commit: b353aa34e31c1388fe64a560413c855535af3665
Parents: c6867c2
Author: T Jake Luciani <jake@apache.org>
Authored: Mon Oct 20 13:04:23 2014 -0400
Committer: T Jake Luciani <jake@apache.org>
Committed: Mon Oct 20 13:04:23 2014 -0400

----------------------------------------------------------------------
 .../org/apache/cassandra/config/CFMetaData.java | 17 ++++
 .../cassandra/io/sstable/SSTableReader.java     |  4 +-
 .../cql3/SSTableMetadataTrackingTest.java       | 82 +++++++++++++++++++-
 3 files changed, 98 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b353aa34/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index e726957..60eb70e 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -633,6 +633,23 @@ public final class CFMetaData
         return cfType == ColumnFamilyType.Super;
     }
 
+    /**
+      * The '.' char is the only way to identify if the CFMetadata is for a secondary index
+      */
+    public boolean isSecondaryIndex()
+    {
+        return cfName.contains(".");
+    }
+
+    /**
+     *
+     * @return The name of the parent cf if this is a seconday index
+     */
+    public String getParentColumnFamilyName()
+    {
+       return isSecondaryIndex() ? cfName.substring(0, cfName.indexOf('.')) : null;
+    }
+
     public double getReadRepairChance()
     {
         return readRepairChance;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b353aa34/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
index 92dee99..87f084c 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
@@ -626,7 +626,9 @@ public class SSTableReader extends SSTable implements Closeable
 
         CompressionMetadata cmd = ((ICompressedFile) dfile).getMetadata();
 
-        cmd.parameters.setLiveMetadata(Schema.instance.getCFMetaData(descriptor));
+        //We need the parent cf metadata
+        String cfName = metadata.isSecondaryIndex() ? metadata.getParentColumnFamilyName()
: metadata.cfName;
+        cmd.parameters.setLiveMetadata(Schema.instance.getCFMetaData(metadata.ksName, cfName));
 
         return cmd;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b353aa34/test/unit/org/apache/cassandra/cql3/SSTableMetadataTrackingTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/SSTableMetadataTrackingTest.java b/test/unit/org/apache/cassandra/cql3/SSTableMetadataTrackingTest.java
index 9104269..356c9e2 100644
--- a/test/unit/org/apache/cassandra/cql3/SSTableMetadataTrackingTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SSTableMetadataTrackingTest.java
@@ -17,10 +17,7 @@
  */
 package org.apache.cassandra.cql3;
 
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
 
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.db.ColumnFamilyStore;
@@ -179,6 +176,83 @@ public class SSTableMetadataTrackingTest
         assertEquals(metadata.maxTimestamp, metadata2.maxTimestamp);
     }
 
+    @Test
+    public void testChangingCrcCheckChance() throws Throwable
+    {
+        String currentTable = "crctest";
+
+        //Start with crc_check_chance of 99%
+        createTable("CREATE TABLE %s.crctest (p text, c text, v text, s text static, PRIMARY
KEY (p, c)) WITH compression = {'sstable_compression': 'LZ4Compressor', 'crc_check_chance'
: 0.99}");
+
+        createTable("CREATE INDEX foo ON %s.crctest(v)");
+
+        execute("INSERT INTO %s.crctest(p, c, v, s) values ('p1', 'k1', 'v1', 'sv1')");
+        execute("INSERT INTO %s.crctest(p, c, v) values ('p1', 'k2', 'v2')");
+        execute("INSERT INTO %s.crctest(p, s) values ('p2', 'sv2')");
+
+
+        ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(currentTable);
+        ColumnFamilyStore indexCfs = cfs.indexManager.getIndexesBackedByCfs().iterator().next();
+        cfs.forceBlockingFlush();
+
+        Assert.assertEquals(0.99, cfs.metadata.compressionParameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals(0.99, cfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals(0.99, indexCfs.metadata.compressionParameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals(0.99, indexCfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance(),
0.00);
+
+
+        Assert.assertEquals(execute("SELECT * FROM %s.crctest WHERE p='p1'").size(), 2);
+        Assert.assertEquals(execute("SELECT * FROM %s.crctest WHERE v='v1'").size(), 1);
+
+
+
+
+        //Write a few SSTables then Compact
+
+        execute("INSERT INTO %s.crctest(p, c, v, s) values ('p1', 'k1', 'v1', 'sv1')");
+        execute("INSERT INTO %s.crctest(p, c, v) values ('p1', 'k2', 'v2')");
+        execute("INSERT INTO %s.crctest(p, s) values ('p2', 'sv2')");
+
+        cfs.forceBlockingFlush();
+
+        execute("INSERT INTO %s.crctest(p, c, v, s) values ('p1', 'k1', 'v1', 'sv1')");
+        execute("INSERT INTO %s.crctest(p, c, v) values ('p1', 'k2', 'v2')");
+        execute("INSERT INTO %s.crctest(p, s) values ('p2', 'sv2')");
+
+
+        cfs.forceBlockingFlush();
+
+        execute("INSERT INTO %s.crctest(p, c, v, s) values ('p1', 'k1', 'v1', 'sv1')");
+        execute("INSERT INTO %s.crctest(p, c, v) values ('p1', 'k2', 'v2')");
+        execute("INSERT INTO %s.crctest(p, s) values ('p2', 'sv2')");
+
+
+        cfs.forceBlockingFlush();
+
+        cfs.forceMajorCompaction();
+
+        //Verify when we alter the value the live sstable readers hold the new one
+        createTable("ALTER TABLE %s.crctest WITH compression = {'sstable_compression': 'LZ4Compressor',
'crc_check_chance': 0.01}");
+
+        Assert.assertEquals( 0.01, cfs.metadata.compressionParameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals( 0.01, cfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals( 0.01, indexCfs.metadata.compressionParameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals( 0.01, indexCfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance(),
0.00);
+
+
+        Assert.assertEquals(execute("SELECT * FROM %s.crctest WHERE p='p1'").size(), 2);
+        Assert.assertEquals(execute("SELECT * FROM %s.crctest WHERE v='v1'").size(), 1);
+
+
+        //Verify the call used by JMX still works
+        cfs.setCrcCheckChance(0.03);
+        Assert.assertEquals( 0.03, cfs.metadata.compressionParameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals( 0.03, cfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals( 0.03, indexCfs.metadata.compressionParameters.getCrcCheckChance(),
0.00);
+        Assert.assertEquals( 0.03, indexCfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance(),
0.00);
+
+    }
+
     @AfterClass
     public static void stopGossiper()
     {


Mime
View raw message