Status TableBuilder::Finish() { Rep* r = rep_; Flush(); assert(!r->closed); r->closed = true; BlockHandle filter_block_handle, metaindex_block_handle, index_block_handle; // Write filter block if (ok() && r->filter_block != nullptr) { WriteRawBlock(r->filter_block->Finish(), kNoCompression, &filter_block_handle); } // Write metaindex block if (ok()) { BlockBuilder meta_index_block(&r->options); if (r->filter_block != nullptr) { // Add mapping from "filter.Name" to location of filter data std::string key = "filter."; key.append(r->options.filter_policy->Name()); std::string handle_encoding; filter_block_handle.EncodeTo(&handle_encoding); meta_index_block.Add(key, handle_encoding); } // TODO(postrelease): Add stats and other meta blocks WriteBlock(&meta_index_block, &metaindex_block_handle); } // Write index block if (ok()) { if (r->pending_index_entry) { r->options.comparator->FindShortSuccessor(&r->last_key); std::string handle_encoding; r->pending_handle.EncodeTo(&handle_encoding); r->index_block.Add(r->last_key, Slice(handle_encoding)); r->pending_index_entry = false; } WriteBlock(&r->index_block, &index_block_handle); } // Write footer if (ok()) { Footer footer; footer.set_metaindex_handle(metaindex_block_handle); footer.set_index_handle(index_block_handle); std::string footer_encoding; footer.EncodeTo(&footer_encoding); r->status = r->file->Append(footer_encoding); if (r->status.ok()) { r->offset += footer_encoding.size(); } } return r->status; }在这段代码里 GenerateFiler()函数被调用了吗
时间: 2024-02-26 08:57:45 浏览: 69
在这段代码中,`GenerateFilter()` 函数没有被直接调用。但是,如果在创建 `TableBuilder` 对象时设置了过滤器策略 (`options.filter_policy`),则在 `TableBuilder::Finish()` 函数中会调用过滤器的生成和写入操作,这个操作会间接调用 `FilterBlockBuilder::GenerateFilter()` 函数。
具体来说,如果设置了过滤器策略,则在 `TableBuilder::Finish()` 函数中会调用 `filter_block_->Finish()` 函数生成并返回过滤器数据,然后在 `WriteRawBlock()` 函数中将其写入磁盘,这个过程会间接调用 `FilterBlockBuilder::GenerateFilter()` 函数。这个过程可以在上面的代码中看到:
```c++
// Write filter block
if (ok() && r->filter_block != nullptr) {
WriteRawBlock(r->filter_block->Finish(), kNoCompression,
&filter_block_handle);
}
```
因此,虽然 `GenerateFilter()` 函数没有被直接调用,但是它的代码实际上被包含在这个写入操作中。
阅读全文