Skip to content

Commit 389edb6

Browse files
committed
universal compaction picker: use double for potential overflow
Summary: There is a possible overflow case in universal compaction picker. Use double to make the logic straight-forward Test Plan: make all check Reviewers: yhchiang, igor, MarkCallaghan, ljin Reviewed By: ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D23817
1 parent d439451 commit 389edb6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

db/compaction_picker.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -746,15 +746,15 @@ Compaction* UniversalCompactionPicker::PickCompactionUniversalReadAmp(
746746
// default kCompactionStopStyleTotalSize; with
747747
// kCompactionStopStyleSimilarSize, it's simply the size of the last
748748
// picked file.
749-
uint64_t sz = (candidate_size * (100L + ratio)) /100;
750-
if (sz < f->fd.GetFileSize()) {
749+
double sz = candidate_size * (100.0 + ratio) / 100.0;
750+
if (sz < static_cast<double>(f->fd.GetFileSize())) {
751751
break;
752752
}
753753
if (options_->compaction_options_universal.stop_style == kCompactionStopStyleSimilarSize) {
754754
// Similar-size stopping rule: also check the last picked file isn't
755755
// far larger than the next candidate file.
756-
sz = (f->fd.GetFileSize() * (100L + ratio)) / 100;
757-
if (sz < candidate_size) {
756+
sz = (f->fd.GetFileSize() * (100.0 + ratio)) / 100.0;
757+
if (sz < static_cast<double>(candidate_size)) {
758758
// If the small file we've encountered begins a run of similar-size
759759
// files, we'll pick them up on a future iteration of the outer
760760
// loop. If it's some lonely straggler, it'll eventually get picked

0 commit comments

Comments
 (0)