From f013d71d39494fb5fe4c56a5d09213dbea16a48e Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Fri, 13 Aug 2010 15:29:56 +0000 Subject: [PATCH] fix errors in hard-coded bloom filter optKPerBucket by computing it algorithmically. patch by Coda Hale; reviewed by jbellis for CASSANDRA-1220 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.6@985241 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 + .../cassandra/utils/BloomCalculations.java | 58 +++++++++++++------ 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3fd81db3e695..14495da5eaa5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,8 @@ * Dynamic snitch (CASSANDRA-981) * Use a regex to filter keyspace and column family names during initialization (CASSANDRA-1377) + * fix errors in hard-coded bloom filter optKPerBucket by computing it + algorithmically (CASSANDRA-1220 0.6.4 diff --git a/src/java/org/apache/cassandra/utils/BloomCalculations.java b/src/java/org/apache/cassandra/utils/BloomCalculations.java index 6ad6f15f748b..9d430ff83b60 100644 --- a/src/java/org/apache/cassandra/utils/BloomCalculations.java +++ b/src/java/org/apache/cassandra/utils/BloomCalculations.java @@ -31,10 +31,6 @@ class BloomCalculations { private static final int minBuckets = 2; private static final int minK = 1; - private static final int[] optKPerBuckets = - new int[]{1, // dummy K for 0 buckets per element - 1, // dummy K for 1 buckets per element - 1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8}; /** * In the following table, the row 'i' shows false positive rates if i buckets @@ -47,21 +43,49 @@ class BloomCalculations { {1.0}, // dummy row representing 0 buckets per element {1.0, 1.0}, // dummy row representing 1 buckets per element {1.0, 0.393, 0.400}, - {1.0, 0.283, 0.237, 0.253}, - {1.0, 0.221, 0.155, 0.147, 0.160}, - {1.0, 0.181, 0.109, 0.092, 0.092, 0.101}, // 5 - {1.0, 0.154, 0.0804, 0.0609, 0.0561, 0.0578, 0.0638}, - {1.0, 0.133, 0.0618, 0.0423, 0.0359, 0.0347, 0.0364}, - {1.0, 0.118, 0.0489, 0.0306, 0.024, 0.0217, 0.0216, 0.0229}, - {1.0, 0.105, 0.0397, 0.0228, 0.0166, 0.0141, 0.0133, 0.0135, 0.0145}, // 9 - {1.0, 0.0952, 0.0329, 0.0174, 0.0118, 0.00943, 0.00844, 0.00819, 0.00846}, - {1.0, 0.0869, 0.0276, 0.0136, 0.00864, 0.0065, 0.00552, 0.00513, 0.00509}, - {1.0, 0.08, 0.0236, 0.0108, 0.00646, 0.00459, 0.00371, 0.00329, 0.00314}, - {1.0, 0.074, 0.0203, 0.00875, 0.00492, 0.00332, 0.00255, 0.00217, 0.00199}, - {1.0, 0.0689, 0.0177, 0.00718, 0.00381, 0.00244, 0.00179, 0.00146, 0.00129}, - {1.0, 0.0645, 0.0156, 0.00596, 0.003, 0.00183, 0.00128, 0.001, 0.000852} // 15 + {1.0, 0.283, 0.237, 0.253}, + {1.0, 0.221, 0.155, 0.147, 0.160}, + {1.0, 0.181, 0.109, 0.092, 0.092, 0.101}, // 5 + {1.0, 0.154, 0.0804, 0.0609, 0.0561, 0.0578, 0.0638}, + {1.0, 0.133, 0.0618, 0.0423, 0.0359, 0.0347, 0.0364}, + {1.0, 0.118, 0.0489, 0.0306, 0.024, 0.0217, 0.0216, 0.0229}, + {1.0, 0.105, 0.0397, 0.0228, 0.0166, 0.0141, 0.0133, 0.0135, 0.0145}, + {1.0, 0.0952, 0.0329, 0.0174, 0.0118, 0.00943, 0.00844, 0.00819, 0.00846}, // 10 + {1.0, 0.0869, 0.0276, 0.0136, 0.00864, 0.0065, 0.00552, 0.00513, 0.00509}, + {1.0, 0.08, 0.0236, 0.0108, 0.00646, 0.00459, 0.00371, 0.00329, 0.00314}, + {1.0, 0.074, 0.0203, 0.00875, 0.00492, 0.00332, 0.00255, 0.00217, 0.00199, 0.00194}, + {1.0, 0.0689, 0.0177, 0.00718, 0.00381, 0.00244, 0.00179, 0.00146, 0.00129, 0.00121, 0.0012}, + {1.0, 0.0645, 0.0156, 0.00596, 0.003, 0.00183, 0.00128, 0.001, 0.000852, 0.000775, 0.000744}, // 15 + {1.0, 0.0606, 0.0138, 0.005, 0.00239, 0.00139, 0.000935, 0.000702, 0.000574, 0.000505, 0.00047, 0.000459}, + {1.0, 0.0571, 0.0123, 0.00423, 0.00193, 0.00107, 0.000692, 0.000499, 0.000394, 0.000335, 0.000302, 0.000287, 0.000284}, + {1.0, 0.054, 0.0111, 0.00362, 0.00158, 0.000839, 0.000519, 0.00036, 0.000275, 0.000226, 0.000198, 0.000183, 0.000176}, + {1.0, 0.0513, 0.00998, 0.00312, 0.0013, 0.000663, 0.000394, 0.000264, 0.000194, 0.000155, 0.000132, 0.000118, 0.000111, 0.000109}, + {1.0, 0.0488, 0.00906, 0.0027, 0.00108, 0.00053, 0.000303, 0.000196, 0.00014, 0.000108, 8.89e-05, 7.77e-05, 7.12e-05, 6.79e-05, 6.71e-05} // 20 }; // the first column is a dummy column representing K=0. + /** + * The optimal number of hashes for a given number of bits per element. + * These values are automatically calculated from the data above. + */ + private static final int[] optKPerBuckets = new int[probs.length]; + + static + { + for (int i = 0; i < probs.length; i++) + { + double min = Double.MAX_VALUE; + double[] prob = probs[i]; + for (int j = 0; j < prob.length; j++) + { + if (prob[j] < min) + { + min = prob[j]; + optKPerBuckets[i] = Math.max(minK, j); + } + } + } + } + /** * Given the number of buckets that can be used per element, return a * specification that minimizes the false positive rate.