首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提取cassandra的布隆过滤器

提取cassandra的布隆过滤器
EN

Stack Overflow用户
提问于 2016-11-19 23:26:06
回答 1查看 92关注 0票数 1

我有一个由另一个服务查询的cassandra服务器,我需要减少查询量。

我的第一个想法是每隔几分钟创建一个整个数据库的bloom过滤器,并将其发送到服务。但是,由于我的数据库中有几百in (预计将增长到几to ),因此每隔几分钟就重载数据库似乎不是一个好主意。

在寻找了一段更好的解决方案后,我想起了cassandra维护着自己的bloom过滤器。

是否可以复制*-Filter.db文件并在我的代码中使用它们,而不是创建我自己的bloom filter?

EN

回答 1

Stack Overflow用户

发布于 2016-11-20 02:09:21

我已经创建了一个表测试

代码语言:javascript
复制
CREATE TABLE test (
   a int PRIMARY KEY,
   b int
);

插入了1行

代码语言:javascript
复制
INSERT INTO test(a,b) VALUES(1, 10);

将数据刷新到磁盘之后。我们可以使用*-Filter.db文件。对于我的例子,它是la-2-big-Filter.db,下面是检查分区键是否存在的示例代码

代码语言:javascript
复制
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 ");
        }
    }
}

输出:

代码语言:javascript
复制
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 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40694568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档