From ab5ccf1a87d459649eb0491e5fb062da268a63a6 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Thu, 21 May 2015 13:05:50 -0400 Subject: [PATCH] sstables: write filter component Before sealing an sstable, here's what we have to do, filter-wise: 1) determine wether or not we should have a filter file. We won't write one, if our fp_chance is 1.0, 2) add each index key to the filter, 3) and write the actual filter. This patch implements those steps. Signed-off-by: Glauber Costa --- sstables/sstables.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 6ff3a41905..98b51cbc72 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -1096,6 +1096,11 @@ future<> sstable::write_components(const memtable& mt) { auto index = make_shared(_index_file, 4096); prepare_summary(_summary, mt); + auto filter_fp_chance = mt.schema()->bloom_filter_fp_chance(); + if (filter_fp_chance != 1.0) { + _components.insert(component_type::Filter); + } + _filter = utils::i_filter::get_filter(mt.all_partitions().size(), filter_fp_chance); // Iterate through CQL partitions, then CQL rows, then CQL columns. // Each mt.all_partitions() entry is a set of clustered rows sharing the same partition key. @@ -1107,6 +1112,7 @@ future<> sstable::write_components(const memtable& mt) { // Maybe add summary entry into in-memory representation of summary file. maybe_add_summary_entry(_summary, bytes_view(partition_key), index->offset()); + _filter->add(bytes_view(partition_key)); return do_with(disk_string_view(), [w, index, &partition_key] (auto& p_key) { p_key.value = bytes_view(partition_key); @@ -1155,6 +1161,8 @@ future<> sstable::write_components(const memtable& mt) { return index->close().then([index] {}); }).then([this] { return write_summary(); + }).then([this] { + return write_filter(); }).then([this] { _components.insert(component_type::TOC); _components.insert(component_type::Index);