| 1025 | } |
| 1026 | |
| 1027 | void VersionSet::Finalize(Version* v) { |
| 1028 | // Precomputed best level for next compaction |
| 1029 | int best_level = -1; |
| 1030 | double best_score = -1; |
| 1031 | |
| 1032 | for (int level = 0; level < config::kNumLevels - 1; level++) { |
| 1033 | double score; |
| 1034 | if (level == 0) { |
| 1035 | // We treat level-0 specially by bounding the number of files |
| 1036 | // instead of number of bytes for two reasons: |
| 1037 | // |
| 1038 | // (1) With larger write-buffer sizes, it is nice not to do too |
| 1039 | // many level-0 compactions. |
| 1040 | // |
| 1041 | // (2) The files in level-0 are merged on every read and |
| 1042 | // therefore we wish to avoid too many files when the individual |
| 1043 | // file size is small (perhaps because of a small write-buffer |
| 1044 | // setting, or very high compression ratios, or lots of |
| 1045 | // overwrites/deletions). |
| 1046 | score = v->files_[level].size() / |
| 1047 | static_cast<double>(config::kL0_CompactionTrigger); |
| 1048 | } else { |
| 1049 | // Compute the ratio of current size to size limit. |
| 1050 | const uint64_t level_bytes = TotalFileSize(v->files_[level]); |
| 1051 | score = |
| 1052 | static_cast<double>(level_bytes) / MaxBytesForLevel(options_, level); |
| 1053 | } |
| 1054 | |
| 1055 | if (score > best_score) { |
| 1056 | best_level = level; |
| 1057 | best_score = score; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | v->compaction_level_ = best_level; |
| 1062 | v->compaction_score_ = best_score; |
| 1063 | } |
| 1064 | |
| 1065 | Status VersionSet::WriteSnapshot(log::Writer* log) { |
| 1066 | // TODO: Break up into multiple records to reduce memory usage on recovery? |
nothing calls this directly
no test coverage detected