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
main
Dhruba Borthakur 11 years ago
parent 289efe9922
commit 76a4923307
  1. 22
      db/version_set.cc
  2. 8
      db/version_set.h

@ -23,8 +23,8 @@
namespace leveldb { namespace leveldb {
static int64_t TotalFileSize(const std::vector<FileMetaData*>& files) { static uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
int64_t sum = 0; uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) { for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->file_size; sum += files[i]->file_size;
} }
@ -527,7 +527,7 @@ int Version::PickLevelForMemTableOutput(
break; break;
} }
GetOverlappingInputs(level + 2, &start, &limit, &overlaps); GetOverlappingInputs(level + 2, &start, &limit, &overlaps);
const int64_t sum = TotalFileSize(overlaps); const uint64_t sum = TotalFileSize(overlaps);
if (sum > vset_->MaxGrandParentOverlapBytes(level)) { if (sum > vset_->MaxGrandParentOverlapBytes(level)) {
break; break;
} }
@ -1824,14 +1824,14 @@ int64_t VersionSet::NumLevelBytes(int level) const {
} }
int64_t VersionSet::MaxNextLevelOverlappingBytes() { int64_t VersionSet::MaxNextLevelOverlappingBytes() {
int64_t result = 0; uint64_t result = 0;
std::vector<FileMetaData*> overlaps; std::vector<FileMetaData*> overlaps;
for (int level = 1; level < NumberLevels() - 1; level++) { for (int level = 1; level < NumberLevels() - 1; level++) {
for (size_t i = 0; i < current_->files_[level].size(); i++) { for (size_t i = 0; i < current_->files_[level].size(); i++) {
const FileMetaData* f = current_->files_[level][i]; const FileMetaData* f = current_->files_[level][i];
current_->GetOverlappingInputs(level+1, &f->smallest, &f->largest, current_->GetOverlappingInputs(level+1, &f->smallest, &f->largest,
&overlaps); &overlaps);
const int64_t sum = TotalFileSize(overlaps); const uint64_t sum = TotalFileSize(overlaps);
if (sum > result) { if (sum > result) {
result = sum; result = sum;
} }
@ -1927,13 +1927,13 @@ uint64_t VersionSet::MaxFileSizeForLevel(int level) {
return max_file_size_[level]; return max_file_size_[level];
} }
int64_t VersionSet::ExpandedCompactionByteSizeLimit(int level) { uint64_t VersionSet::ExpandedCompactionByteSizeLimit(int level) {
uint64_t result = MaxFileSizeForLevel(level); uint64_t result = MaxFileSizeForLevel(level);
result *= options_->expanded_compaction_factor; result *= options_->expanded_compaction_factor;
return result; return result;
} }
int64_t VersionSet::MaxGrandParentOverlapBytes(int level) { uint64_t VersionSet::MaxGrandParentOverlapBytes(int level) {
uint64_t result = MaxFileSizeForLevel(level); uint64_t result = MaxFileSizeForLevel(level);
result *= options_->max_grandparent_overlap_factor; result *= options_->max_grandparent_overlap_factor;
return result; return result;
@ -2394,10 +2394,10 @@ void VersionSet::SetupOtherInputs(Compaction* c) {
std::vector<FileMetaData*> expanded0; std::vector<FileMetaData*> expanded0;
current_->GetOverlappingInputs(level, &all_start, &all_limit, &expanded0, current_->GetOverlappingInputs(level, &all_start, &all_limit, &expanded0,
c->base_index_, nullptr); c->base_index_, nullptr);
const int64_t inputs0_size = TotalFileSize(c->inputs_[0]); const uint64_t inputs0_size = TotalFileSize(c->inputs_[0]);
const int64_t inputs1_size = TotalFileSize(c->inputs_[1]); const uint64_t inputs1_size = TotalFileSize(c->inputs_[1]);
const int64_t expanded0_size = TotalFileSize(expanded0); const uint64_t expanded0_size = TotalFileSize(expanded0);
int64_t limit = ExpandedCompactionByteSizeLimit(level); uint64_t limit = ExpandedCompactionByteSizeLimit(level);
if (expanded0.size() > c->inputs_[0].size() && if (expanded0.size() > c->inputs_[0].size() &&
inputs1_size + expanded0_size < limit && inputs1_size + expanded0_size < limit &&
!FilesInCompaction(expanded0)) { !FilesInCompaction(expanded0)) {

@ -422,9 +422,9 @@ class VersionSet {
bool ManifestContains(const std::string& record) const; 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_; Env* const env_;
const std::string dbname_; const std::string dbname_;
@ -554,7 +554,7 @@ class Compaction {
int level_; int level_;
int out_level_; // levels to which output files are stored int out_level_; // levels to which output files are stored
uint64_t max_output_file_size_; uint64_t max_output_file_size_;
int64_t maxGrandParentOverlapBytes_; uint64_t maxGrandParentOverlapBytes_;
Version* input_version_; Version* input_version_;
VersionEdit* edit_; VersionEdit* edit_;
int number_levels_; int number_levels_;
@ -569,7 +569,7 @@ class Compaction {
std::vector<FileMetaData*> grandparents_; std::vector<FileMetaData*> grandparents_;
size_t grandparent_index_; // Index in grandparent_starts_ size_t grandparent_index_; // Index in grandparent_starts_
bool seen_key_; // Some output key has been seen 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 // and grandparent files
int base_index_; // index of the file in files_[level_] int base_index_; // index of the file in files_[level_]
int parent_index_; // index of some file with same range in files_[level_+1] int parent_index_; // index of some file with same range in files_[level_+1]

Loading…
Cancel
Save