TableBuilder::Finish() dose not call rep_->file->Sync() at the end
- Dominant language
- C++
- Stars
- 39.4k
- Forks
- 8.2k
- PR merge metrics
- No merged PRs in 30d
Description
When I used TableBuilder to manually build an SSTable, I found that TableBuilder::FileSize() was not equal to the size of rep_->file after I called TableBuilder::Finish(). It was very confusing to me.
The reason is that TableBuilder::Finish() does not call rep_->file->Sync() at the end. So, some data(meta index block, index block, and footer block ) in rep_->file may be still buffered and not flushed to persistent storage.
**But semantically, "Finish" means that after we called this function successfully, the SSTable should be completely built.**
So, I think that rep_->file->Sync() should be called at the end of TableBuilder::Finish().
[https://github.com/google/leveldb/blob/master/table/table_builder.cc#L240](https://github.com/google/leveldb/blob/master/table/table_builder.cc#L240)
```cpp
// 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();
}
}
if (ok()) {
r->status = r->file->Sync();
}
return r->status;
```
Contributor guide
Assessment
This issue has not been assessed yet.