From 76a4923307a178b66bf294dff3560db0ef62efdb Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Wed, 17 Jul 2013 13:56:24 -0700 Subject: [PATCH] Make file-sizes and grandparentoverlap to be unsigned to avoid bad comparisions. Summary: The maxGrandParentOverlapBytes_ was signed which was causing an erroneous comparision between signed and unsigned longs. This, in turn, was causing compaction-created-output-files to be very small in size. Test Plan: make check Differential Revision: https://reviews.facebook.net/D11727 --- db/version_set.cc | 22 +++++++++++----------- db/version_set.h | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index 876e41e84..4b2774ecd 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -23,8 +23,8 @@ namespace leveldb { -static int64_t TotalFileSize(const std::vector& files) { - int64_t sum = 0; +static uint64_t TotalFileSize(const std::vector& files) { + uint64_t sum = 0; for (size_t i = 0; i < files.size() && files[i]; i++) { sum += files[i]->file_size; } @@ -527,7 +527,7 @@ int Version::PickLevelForMemTableOutput( break; } GetOverlappingInputs(level + 2, &start, &limit, &overlaps); - const int64_t sum = TotalFileSize(overlaps); + const uint64_t sum = TotalFileSize(overlaps); if (sum > vset_->MaxGrandParentOverlapBytes(level)) { break; } @@ -1824,14 +1824,14 @@ int64_t VersionSet::NumLevelBytes(int level) const { } int64_t VersionSet::MaxNextLevelOverlappingBytes() { - int64_t result = 0; + uint64_t result = 0; std::vector overlaps; for (int level = 1; level < NumberLevels() - 1; level++) { for (size_t i = 0; i < current_->files_[level].size(); i++) { const FileMetaData* f = current_->files_[level][i]; current_->GetOverlappingInputs(level+1, &f->smallest, &f->largest, &overlaps); - const int64_t sum = TotalFileSize(overlaps); + const uint64_t sum = TotalFileSize(overlaps); if (sum > result) { result = sum; } @@ -1927,13 +1927,13 @@ uint64_t VersionSet::MaxFileSizeForLevel(int level) { return max_file_size_[level]; } -int64_t VersionSet::ExpandedCompactionByteSizeLimit(int level) { +uint64_t VersionSet::ExpandedCompactionByteSizeLimit(int level) { uint64_t result = MaxFileSizeForLevel(level); result *= options_->expanded_compaction_factor; return result; } -int64_t VersionSet::MaxGrandParentOverlapBytes(int level) { +uint64_t VersionSet::MaxGrandParentOverlapBytes(int level) { uint64_t result = MaxFileSizeForLevel(level); result *= options_->max_grandparent_overlap_factor; return result; @@ -2394,10 +2394,10 @@ void VersionSet::SetupOtherInputs(Compaction* c) { std::vector expanded0; current_->GetOverlappingInputs(level, &all_start, &all_limit, &expanded0, c->base_index_, nullptr); - const int64_t inputs0_size = TotalFileSize(c->inputs_[0]); - const int64_t inputs1_size = TotalFileSize(c->inputs_[1]); - const int64_t expanded0_size = TotalFileSize(expanded0); - int64_t limit = ExpandedCompactionByteSizeLimit(level); + const uint64_t inputs0_size = TotalFileSize(c->inputs_[0]); + const uint64_t inputs1_size = TotalFileSize(c->inputs_[1]); + const uint64_t expanded0_size = TotalFileSize(expanded0); + uint64_t limit = ExpandedCompactionByteSizeLimit(level); if (expanded0.size() > c->inputs_[0].size() && inputs1_size + expanded0_size < limit && !FilesInCompaction(expanded0)) { diff --git a/db/version_set.h b/db/version_set.h index bec738340..56eec7ecd 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -422,9 +422,9 @@ class VersionSet { bool ManifestContains(const std::string& record) const; - int64_t ExpandedCompactionByteSizeLimit(int level); + uint64_t ExpandedCompactionByteSizeLimit(int level); - int64_t MaxGrandParentOverlapBytes(int level); + uint64_t MaxGrandParentOverlapBytes(int level); Env* const env_; const std::string dbname_; @@ -554,7 +554,7 @@ class Compaction { int level_; int out_level_; // levels to which output files are stored uint64_t max_output_file_size_; - int64_t maxGrandParentOverlapBytes_; + uint64_t maxGrandParentOverlapBytes_; Version* input_version_; VersionEdit* edit_; int number_levels_; @@ -569,7 +569,7 @@ class Compaction { std::vector grandparents_; size_t grandparent_index_; // Index in grandparent_starts_ bool seen_key_; // Some output key has been seen - int64_t overlapped_bytes_; // Bytes of overlap between current output + uint64_t overlapped_bytes_; // Bytes of overlap between current output // and grandparent files int base_index_; // index of the file in files_[level_] int parent_index_; // index of some file with same range in files_[level_+1]