给出leveldb源码当中comparator.cc中的void FindShortestSeparator()的调用关系和调用次数
时间: 2024-02-09 09:08:01 浏览: 130
在leveldb源码中,void FindShortestSeparator()函数的调用关系如下:
1. 函数原型: void FindShortestSeparator(std::string* start, const Slice& limit, const Comparator* cmp)
2. 被调用于VersionSet::CompactRange()函数中的:
```
void VersionSet::CompactRange(int level, const Slice* begin, const Slice* end) {
...
while (r->Valid() &&
vset_->icmp_.Compare(r->key(), end) < 0) {
...
if (ikey.size() < smallest.size()) {
smallest.swap(ikey);
}
if (smallest.empty() ||
vset_->icmp_.Compare(largest.Encode(), ikey.Encode()) < 0) {
largest = ikey;
}
...
}
...
// If we have a base level, we should compact "slow" level zero
// files if there is lots of space in the level above.
if (level == 0 && !smallest.empty()) {
InternalKey start_key(*smallest, kMaxSequenceNumber, kValueTypeForSeek);
InternalKey end_key(*largest, 0, static_cast<ValueType>(0));
std::string compaction_filename = CompactionFileName(vset_->dbname_, compact_pointer_[level+1]);
Edit edit;
edit.SetCompaction(level, 0, MaxFileSizeForLevel(level),
compact_pointer_[level], compact_pointer_[level+1]);
vset_->LogAndApply(&edit, &mutex_);
Compaction* c = vset_->compact_pointer_[level+1] = new Compaction(
vset_->options_, level+1, vset_);
c->input_version_ = vset_->current_;
c->input_version_->Ref();
c->input_version_->GetOverlappingInputs(level, &start_key, &end_key, &c->inputs_);
c->EditCompactionRange(&start_key, &end_key);
c->SetupOtherInputs();
DoCompactionWork(c);
c->Cleanup();
vset_->compact_pointer_[level+1] = nullptr;
MaybeScheduleCompaction();
}
...
}
```
3. 调用次数
根据代码分析,FindShortestSeparator()函数在LevelDB中被调用的次数与LevelDB中的压缩次数有关,而压缩次数与LevelDB的运行情况及配置有关,因此无法提供精确的调用次数。
阅读全文