Skip to content

Commit

Permalink
Add TableBuilder::GetBoundaryUserKey() for sst file writer
Browse files Browse the repository at this point in the history
This reduced comparing user keys for computing smallest_key & largest_key
in SstFileWriter::Add.
  • Loading branch information
rockeet committed Oct 4, 2022
1 parent 6a85877 commit 1e4fbdc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions table/sst_file_writer.cc
Expand Up @@ -72,6 +72,7 @@ struct SstFileWriter::Rep {
}

if (sst_support_auto_sort) {
#if 0 // now we use GetBoundaryUserKey after Finish
assert(internal_comparator.IsBytewise());
// now auto sort just support bytewise comparator
// we use Slice default compare to omit comparator virtual call
Expand All @@ -85,6 +86,7 @@ struct SstFileWriter::Rep {
else if (user_key < file_info.smallest_key)
file_info.smallest_key.assign(user_key.data(), user_key.size());
}
#endif
}
else if (file_info.num_entries == 0) {
file_info.smallest_key.assign(user_key.data(), user_key.size());
Expand Down Expand Up @@ -388,6 +390,12 @@ Status SstFileWriter::Finish(ExternalSstFileInfo* file_info) {
s = r->file_writer->Close();
}
}
if (s.ok() && rep_->sst_support_auto_sort) {
// this reduced comparing user keys with smallest_key & largest_key.
auto& fi = r->file_info;
s = r->builder->GetBoundaryUserKey(&fi.smallest_key, &fi.largest_key);
ROCKSDB_VERIFY_F(s.ok(), "GetBoundaryUserKey = %s", s.ToString().c_str());
}
if (s.ok()) {
r->file_info.file_checksum = r->file_writer->GetFileChecksum();
r->file_info.file_checksum_func_name =
Expand Down
4 changes: 4 additions & 0 deletions table/table_builder.h
Expand Up @@ -221,6 +221,10 @@ class TableBuilder {
// Returns table properties
virtual TableProperties GetTableProperties() const = 0;

virtual Status GetBoundaryUserKey(std::string*, std::string*) const {
return Status::NotSupported("Only supported by auto sort sst");
}

// Return file checksum
virtual std::string GetFileChecksum() const = 0;

Expand Down

0 comments on commit 1e4fbdc

Please sign in to comment.