diff options
Diffstat (limited to 'db/version_set.cc')
-rw-r--r-- | db/version_set.cc | 95 |
1 files changed, 49 insertions, 46 deletions
diff --git a/db/version_set.cc b/db/version_set.cc index 7891dfc..56493ac 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1347,78 +1347,81 @@ Compaction* VersionSet::PickCompaction() { return c; } -// find the largest key in a vector of files. returns true if files it not empty -bool FindLargestKey(const InternalKeyComparator & icmp, const std::vector<FileMetaData*> & files, InternalKey *largestKey) { +// Finds the largest key in a vector of files. Returns true if files it not +// empty. +bool FindLargestKey(const InternalKeyComparator& icmp, + const std::vector<FileMetaData*>& files, + InternalKey* largest_key) { if (files.empty()) { return false; } - *largestKey = files[0]->largest; + *largest_key = files[0]->largest; for (size_t i = 1; i < files.size(); ++i) { FileMetaData* f = files[i]; - if (icmp.Compare(f->largest, *largestKey) > 0) { - *largestKey = f->largest; + if (icmp.Compare(f->largest, *largest_key) > 0) { + *largest_key = f->largest; } } return true; } -// find minimum file b2=(l2, u2) in level file for which l2 > u1 and user_key(l2) = user_key(u1) -FileMetaData* FindSmallestBoundaryFile(const InternalKeyComparator & icmp, - const std::vector<FileMetaData*> & levelFiles, - const InternalKey & largestKey) { +// Finds minimum file b2=(l2, u2) in level file for which l2 > u1 and +// user_key(l2) = user_key(u1) +FileMetaData* FindSmallestBoundaryFile( + const InternalKeyComparator& icmp, + const std::vector<FileMetaData*>& level_files, + const InternalKey& largest_key) { const Comparator* user_cmp = icmp.user_comparator(); - FileMetaData* smallestBoundaryFile = NULL; - for (size_t i = 0; i < levelFiles.size(); ++i) { - FileMetaData* f = levelFiles[i]; - if (icmp.Compare(f->smallest, largestKey) > 0 && - user_cmp->Compare(f->smallest.user_key(), largestKey.user_key()) == 0) { - if (smallestBoundaryFile == NULL || - icmp.Compare(f->smallest, smallestBoundaryFile->smallest) < 0) { - smallestBoundaryFile = f; + FileMetaData* smallest_boundary_file = nullptr; + for (size_t i = 0; i < level_files.size(); ++i) { + FileMetaData* f = level_files[i]; + if (icmp.Compare(f->smallest, largest_key) > 0 && + user_cmp->Compare(f->smallest.user_key(), largest_key.user_key()) == + 0) { + if (smallest_boundary_file == nullptr || + icmp.Compare(f->smallest, smallest_boundary_file->smallest) < 0) { + smallest_boundary_file = f; } } } - return smallestBoundaryFile; + return smallest_boundary_file; } -// If there are two blocks, b1=(l1, u1) and b2=(l2, u2) and -// user_key(u1) = user_key(l2), and if we compact b1 but not -// b2 then a subsequent get operation will yield an incorrect -// result because it will return the record from b2 in level -// i rather than from b1 because it searches level by level -// for records matching the supplied user key. +// Extracts the largest file b1 from |compaction_files| and then searches for a +// b2 in |level_files| for which user_key(u1) = user_key(l2). If it finds such a +// file b2 (known as a boundary file) it adds it to |compaction_files| and then +// searches again using this new upper bound. // -// This function extracts the largest file b1 from compactionFiles -// and then searches for a b2 in levelFiles for which user_key(u1) = -// user_key(l2). If it finds such a file b2 (known as a boundary file) -// it adds it to compactionFiles and then searches again using this -// new upper bound. +// If there are two blocks, b1=(l1, u1) and b2=(l2, u2) and +// user_key(u1) = user_key(l2), and if we compact b1 but not b2 then a +// subsequent get operation will yield an incorrect result because it will +// return the record from b2 in level i rather than from b1 because it searches +// level by level for records matching the supplied user key. // // parameters: -// in levelFiles: list of files to search for boundary files -// in/out compactionFiles: list of files to extend by adding boundary files +// in level_files: List of files to search for boundary files. +// in/out compaction_files: List of files to extend by adding boundary files. void AddBoundaryInputs(const InternalKeyComparator& icmp, - const std::vector<FileMetaData*>& levelFiles, - std::vector<FileMetaData*>* compactionFiles) { - InternalKey largestKey; + const std::vector<FileMetaData*>& level_files, + std::vector<FileMetaData*>* compaction_files) { + InternalKey largest_key; - // find largestKey in compactionFiles, quick return if compactionFiles is - // empty - if (!FindLargestKey(icmp, *compactionFiles, &largestKey)) { + // Quick return if compaction_files is empty. + if (!FindLargestKey(icmp, *compaction_files, &largest_key)) { return; } - bool continueSearching = true; - while (continueSearching) { - FileMetaData* smallestBoundaryFile = - FindSmallestBoundaryFile(icmp, levelFiles, largestKey); + bool continue_searching = true; + while (continue_searching) { + FileMetaData* smallest_boundary_file = + FindSmallestBoundaryFile(icmp, level_files, largest_key); - // if a boundary file was found advance largestKey, otherwise we're done - if (smallestBoundaryFile != NULL) { - compactionFiles->push_back(smallestBoundaryFile); - largestKey = smallestBoundaryFile->largest; + // If a boundary file was found advance largest_key, otherwise we're done. + if (smallest_boundary_file != NULL) { + compaction_files->push_back(smallest_boundary_file); + largest_key = smallest_boundary_file->largest; } else { - continueSearching = false; + continue_searching = false; } } } |