【问题标题】:Extracting cassandra's bloom filter提取 cassandra 的布隆过滤器
【发布时间】:2016-11-19 15:26:06
【问题描述】:

我有一个 cassandra 服务器正在被另一个服务查询,我需要减少查询量。

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

在寻找更好的解决方案一段时间后,我记得 cassandra 维护自己的布隆过滤器。

是否可以复制 *-Filter.db 文件并在我的代码中使用它们而不是创建我自己的布隆过滤器?

【问题讨论】:

  • 查询如何?我不明白你为什么认为你需要访问它的布隆过滤器。
  • 我正在运行从服务到 cassandra 的 cql 查询。我想减少对 cassandra 的查询量。我不想创建自己的布隆过滤器,而是想使用 cassandra 中内置的布隆过滤器。
  • 为什么你想做 cassandra 已经做过的事情?如果您使用“相同”BF 预过滤查询,您的系统不会更快。如果你想更快,你需要缓存数据(当然,比 cassandra 已经做的更多,或者以不同的方式)。恕我直言。

标签: java cassandra bloom-filter


【解决方案1】:

我已经创建了一个表测试

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 

【讨论】:

  • 如果BF仍在内存中并且没有持久化在磁盘上怎么办?
  • 当 memtable 内容超过可配置的阈值时,包含索引的 memtable 数据被放入队列中以刷新到磁盘。您可以通过更改 cassandra.yaml 中的 memtable_heap_space_in_mb 或 memtable_offheap_space_in_mb 设置来配置队列的长度,但我认为您不应该更改阈值,而应该将新添加的值添加到您的布隆过滤器。
  • 或者你可以使用缓存
  • 这正是重点。如果您没有这些文件,您将无法做任何事情。您需要完成 C* 已经完成的相同工作。绝对没有理由在性能方面这样做。恕我直言。
猜你喜欢
  • 2017-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-22
  • 1970-01-01
  • 2017-03-17
  • 2017-05-07
  • 2010-10-12
相关资源
最近更新 更多