cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject cassandra git commit: Validate bloom_filter_fp_chance during table creation
Date Tue, 21 Jun 2016 16:14:38 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 5a096274d -> 9e85e85bf


Validate bloom_filter_fp_chance during table creation

Patch by Arinadm Gupta; reviewed by Tyler Hobbs for CASSANDRA-11920


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

Branch: refs/heads/cassandra-2.2
Commit: 9e85e85bf259cc7839226a7c93475505d262946a
Parents: 5a09627
Author: Arindam Gupta <arindamg@cisco.com>
Authored: Fri Jun 17 16:06:22 2016 -0500
Committer: Tyler Hobbs <tylerlhobbs@gmail.com>
Committed: Tue Jun 21 11:12:15 2016 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  5 +-
 .../cassandra/cql3/statements/CFPropDefs.java   | 13 ++++-
 .../cassandra/utils/BloomCalculations.java      | 15 +++++-
 .../schema/CreateTableValidationTest.java       | 51 ++++++++++++++++++++
 4 files changed, 78 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/9e85e85b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index fe4728d..36009c5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,6 @@
-<<<<<<< HEAD
 2.2.7
+ * Validate bloom_filter_fp_chance against lowest supported
+   value when the table is created (CASSANDRA-11920)
  * RandomAccessReader: call isEOF() only when rebuffering, not for every read operation (CASSANDRA-12013)
  * Don't send erroneous NEW_NODE notifications on restart (CASSANDRA-11038)
  * StorageService shutdown hook should use a volatile variable (CASSANDRA-11984)
@@ -28,10 +29,8 @@
  * Always close cluster with connection in CqlRecordWriter (CASSANDRA-11553)
  * Fix slice queries on ordered COMPACT tables (CASSANDRA-10988)
 Merged from 2.1:
-=======
 2.1.15
  * Remove distinction between non-existing static columns and existing but null in LWTs (CASSANDRA-9842)
->>>>>>> asf/cassandra-2.1
  * Support mlockall on IBM POWER arch (CASSANDRA-11576)
  * Cache local ranges when calculating repair neighbors (CASSANDRA-11933)
  * Allow LWT operation on static column with only partition keys (CASSANDRA-10532)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9e85e85b/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java b/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
index d897cb7..c02e78e 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CFPropDefs.java
@@ -26,6 +26,7 @@ import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
 import org.apache.cassandra.io.compress.CompressionParameters;
+import org.apache.cassandra.utils.BloomCalculations;
 
 public class CFPropDefs extends PropertyDefinitions
 {
@@ -211,7 +212,17 @@ public class CFPropDefs extends PropertyDefinitions
             cfm.compactionStrategyOptions(new HashMap<>(getCompactionOptions()));
         }
 
-        cfm.bloomFilterFpChance(getDouble(KW_BF_FP_CHANCE, cfm.getBloomFilterFpChance()));
+        double bloomFilterFpChance = getDouble(KW_BF_FP_CHANCE, cfm.getBloomFilterFpChance());
+        double minBloomFilterFpChanceValue = BloomCalculations.minSupportedBloomFilterFpChance();
+        if (bloomFilterFpChance <=  minBloomFilterFpChanceValue || bloomFilterFpChance
> 1)
+        {
+            throw new ConfigurationException(String.format(
+                    "%s must be larger than %s and less than or equal to 1.0 (got %s)",
+                    KW_BF_FP_CHANCE,
+                    minBloomFilterFpChanceValue,
+                    bloomFilterFpChance));
+        }
+        cfm.bloomFilterFpChance(bloomFilterFpChance);
 
         if (!getCompressionOptions().isEmpty())
             cfm.compressionParameters(CompressionParameters.create(getCompressionOptions()));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9e85e85b/src/java/org/apache/cassandra/utils/BloomCalculations.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/BloomCalculations.java b/src/java/org/apache/cassandra/utils/BloomCalculations.java
index b73f531..7ba5452 100644
--- a/src/java/org/apache/cassandra/utils/BloomCalculations.java
+++ b/src/java/org/apache/cassandra/utils/BloomCalculations.java
@@ -26,8 +26,8 @@ package org.apache.cassandra.utils;
  * Filter class by helping to choose correct values of 'bits per element' and
  * 'number of hash functions, k'.
  */
-class BloomCalculations {
-
+public class BloomCalculations
+{
     private static final int minBuckets = 2;
     private static final int minK = 1;
 
@@ -182,4 +182,15 @@ class BloomCalculations {
         }
         return Math.min(BloomCalculations.probs.length - 1, (int)v);
     }
+
+    /**
+     * Retrieves the minimum supported BloomFilterFpChance value
+     * @return Minimum supported value for BloomFilterFpChance
+     */
+    public static double minSupportedBloomFilterFpChance()
+    {
+        int maxBuckets = probs.length - 1;
+        int maxK = probs[maxBuckets].length - 1;
+        return probs[maxBuckets][maxK];
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9e85e85b/test/unit/org/apache/cassandra/schema/CreateTableValidationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/schema/CreateTableValidationTest.java b/test/unit/org/apache/cassandra/schema/CreateTableValidationTest.java
new file mode 100644
index 0000000..9708552
--- /dev/null
+++ b/test/unit/org/apache/cassandra/schema/CreateTableValidationTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cassandra.schema;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class CreateTableValidationTest extends CQLTester
+{
+    private static final String KEYSPACE1 = "CreateTableValidationTest";
+
+    @Test
+    public void testInvalidBloomFilterFPRatio() throws Throwable
+    {
+        try
+        {
+            createTableMayThrow("CREATE TABLE %s (a int PRIMARY KEY, b int) WITH bloom_filter_fp_chance
= 0.0000001");
+            fail("Expected an fp chance of 0.0000001 to be rejected");
+        }
+        catch (ConfigurationException exc) { }
+
+        try
+        {
+            createTableMayThrow("CREATE TABLE %s (a int PRIMARY KEY, b int) WITH bloom_filter_fp_chance
= 1.1");
+            fail("Expected an fp chance of 1.1 to be rejected");
+        }
+        catch (ConfigurationException exc) { }
+
+        // sanity check
+        createTable("CREATE TABLE %s (a int PRIMARY KEY, b int) WITH bloom_filter_fp_chance
= 0.1");
+    }
+}


Mime
View raw message