mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-29 18:33:58 +00:00
EstimatedNumKeys Counter Inaccurate
This commit is contained in:
parent
a9ca9107b9
commit
355fa94365
|
@ -338,7 +338,8 @@ class VersionBuilder::Rep {
|
|||
|
||||
void MaybeAddFile(VersionStorageInfo* vstorage, int level, FileMetaData* f) {
|
||||
if (levels_[level].deleted_files.count(f->fd.GetNumber()) > 0) {
|
||||
// File is deleted: do nothing
|
||||
// f is to-be-delected table file
|
||||
vstorage->RemoveCurrentStats(f);
|
||||
} else {
|
||||
vstorage->AddFile(level, f, info_log_);
|
||||
}
|
||||
|
|
|
@ -738,24 +738,24 @@ uint64_t VersionStorageInfo::GetEstimatedActiveKeys() const {
|
|||
// (2) keys are directly overwritten
|
||||
// (3) deletion on non-existing keys
|
||||
// (4) low number of samples
|
||||
if (num_samples_ == 0) {
|
||||
if (current_num_samples_ == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (accumulated_num_non_deletions_ <= accumulated_num_deletions_) {
|
||||
if (current_num_non_deletions_ <= current_num_deletions_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t est = accumulated_num_non_deletions_ - accumulated_num_deletions_;
|
||||
uint64_t est = current_num_non_deletions_ - current_num_deletions_;
|
||||
|
||||
uint64_t file_count = 0;
|
||||
for (int level = 0; level < num_levels_; ++level) {
|
||||
file_count += files_[level].size();
|
||||
}
|
||||
|
||||
if (num_samples_ < file_count) {
|
||||
if (current_num_samples_ < file_count) {
|
||||
// casting to avoid overflowing
|
||||
return (est * static_cast<double>(file_count) / num_samples_);
|
||||
return (est * static_cast<double>(file_count) / current_num_samples_);
|
||||
} else {
|
||||
return est;
|
||||
}
|
||||
|
@ -826,7 +826,9 @@ VersionStorageInfo::VersionStorageInfo(
|
|||
accumulated_raw_value_size_(0),
|
||||
accumulated_num_non_deletions_(0),
|
||||
accumulated_num_deletions_(0),
|
||||
num_samples_(0),
|
||||
current_num_non_deletions_(0),
|
||||
current_num_deletions_(0),
|
||||
current_num_samples_(0),
|
||||
estimated_compaction_needed_bytes_(0),
|
||||
finalized_(false) {
|
||||
if (ref_vstorage != nullptr) {
|
||||
|
@ -836,7 +838,9 @@ VersionStorageInfo::VersionStorageInfo(
|
|||
accumulated_num_non_deletions_ =
|
||||
ref_vstorage->accumulated_num_non_deletions_;
|
||||
accumulated_num_deletions_ = ref_vstorage->accumulated_num_deletions_;
|
||||
num_samples_ = ref_vstorage->num_samples_;
|
||||
current_num_non_deletions_ = ref_vstorage->current_num_non_deletions_;
|
||||
current_num_deletions_ = ref_vstorage->current_num_deletions_;
|
||||
current_num_samples_ = ref_vstorage->current_num_samples_;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -993,7 +997,20 @@ void VersionStorageInfo::UpdateAccumulatedStats(FileMetaData* file_meta) {
|
|||
accumulated_num_non_deletions_ +=
|
||||
file_meta->num_entries - file_meta->num_deletions;
|
||||
accumulated_num_deletions_ += file_meta->num_deletions;
|
||||
num_samples_++;
|
||||
|
||||
current_num_non_deletions_ +=
|
||||
file_meta->num_entries - file_meta->num_deletions;
|
||||
current_num_deletions_ += file_meta->num_deletions;
|
||||
current_num_samples_++;
|
||||
}
|
||||
|
||||
void VersionStorageInfo::RemoveCurrentStats(FileMetaData* file_meta) {
|
||||
if (file_meta->init_stats_from_file) {
|
||||
current_num_non_deletions_ -=
|
||||
file_meta->num_entries - file_meta->num_deletions;
|
||||
current_num_deletions_ -= file_meta->num_deletions;
|
||||
current_num_samples_--;
|
||||
}
|
||||
}
|
||||
|
||||
void Version::UpdateAccumulatedStats(bool update_stats) {
|
||||
|
|
|
@ -111,6 +111,9 @@ class VersionStorageInfo {
|
|||
// Update the accumulated stats from a file-meta.
|
||||
void UpdateAccumulatedStats(FileMetaData* file_meta);
|
||||
|
||||
// Decrease the current stat form a to-be-delected file-meta
|
||||
void RemoveCurrentStats(FileMetaData* file_meta);
|
||||
|
||||
void ComputeCompensatedSizes();
|
||||
|
||||
// Updates internal structures that keep track of compaction scores
|
||||
|
@ -400,8 +403,12 @@ class VersionStorageInfo {
|
|||
uint64_t accumulated_num_non_deletions_;
|
||||
// total number of deletion entries
|
||||
uint64_t accumulated_num_deletions_;
|
||||
// the number of samples
|
||||
uint64_t num_samples_;
|
||||
// current number of non_deletion entries
|
||||
uint64_t current_num_non_deletions_;
|
||||
// current number of delection entries
|
||||
uint64_t current_num_deletions_;
|
||||
// current number of file samples
|
||||
uint64_t current_num_samples_;
|
||||
// Estimated bytes needed to be compacted until all levels' size is down to
|
||||
// target sizes.
|
||||
uint64_t estimated_compaction_needed_bytes_;
|
||||
|
|
Loading…
Reference in a new issue