我有一个由另一个服务查询的cassandra服务器,我需要减少查询量。
我的第一个想法是每隔几分钟创建一个整个数据库的bloom过滤器,并将其发送到服务。但是,由于我的数据库中有几百in (预计将增长到几to ),因此每隔几分钟就重载数据库似乎不是一个好主意。
在寻找了一段更好的解决方案后,我想起了cassandra维护着自己的bloom过滤器。
是否可以复制*-Filter.db文件并在我的代码中使用它们,而不是创建我自己的bloom filter?
发布于 2016-11-20 02:09:21
我已经创建了一个表测试
CREATE TABLE test (
a int PRIMARY KEY,
b int
);插入了1行
INSERT INTO test(a,b) VALUES(1, 10);将数据刷新到磁盘之后。我们可以使用*-Filter.db文件。对于我的例子,它是la-2-big-Filter.db,下面是检查分区键是否存在的示例代码
Murmur3Partitioner partitioner = new Murmur3Partitioner();
try (DataInputStream in = new DataInputStream(new FileInputStream(new File("la-2-big-Filter.db"))); IFilter filter = FilterFactory.deserialize(in, true)) {
for (int i = 1; i <= 10; i++) {
DecoratedKey decoratedKey = partitioner.decorateKey(Int32Type.instance.decompose(i));
if (filter.isPresent(decoratedKey)) {
System.out.println(i + " is present ");
} else {
System.out.println(i + " is not present ");
}
}
}输出:
1 is present
2 is not present
3 is not present
4 is not present
5 is not present
6 is not present
7 is not present
8 is not present
9 is not present
10 is not present https://stackoverflow.com/questions/40694568
复制相似问题