From 8885b0537bc6be733a10dd82be5fbe121ff01541 Mon Sep 17 00:00:00 2001 From: LIU HU Date: Fri, 22 Jul 2022 09:20:35 -0700 Subject: [PATCH] Fix underflow in FIFOCompactionPicker (#10386) Summary: Fix https://github.com/facebook/rocksdb/issues/10133 Pull Request resolved: https://github.com/facebook/rocksdb/pull/10386 Reviewed By: riversand963 Differential Revision: D38067265 Pulled By: ajkr fbshipit-source-id: 3a99a98ac5d7ac37581b5b636fbfa7901563d834 --- HISTORY.md | 1 + db/compaction/compaction_picker_fifo.cc | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 21ebb1046..3ae92d365 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,7 @@ ### Bug Fixes * Fix a bug where `GenericRateLimiter` could revert the bandwidth set dynamically using `SetBytesPerSecond()` when a user configures a structure enclosing it, e.g., using `GetOptionsFromString()` to configure an `Options` that references an existing `RateLimiter` object. * Fix race conditions in `GenericRateLimiter`. +* Fix a bug in `FIFOCompactionPicker::PickTTLCompaction` where total_size calculating might cause underflow ## 7.5.0 (07/15/2022) ### New Features diff --git a/db/compaction/compaction_picker_fifo.cc b/db/compaction/compaction_picker_fifo.cc index 6034dd0ef..1816b95ed 100644 --- a/db/compaction/compaction_picker_fifo.cc +++ b/db/compaction/compaction_picker_fifo.cc @@ -83,7 +83,7 @@ Compaction* FIFOCompactionPicker::PickTTLCompaction( break; } } - total_size -= f->compensated_file_size; + total_size -= f->fd.file_size; inputs[0].files.push_back(f); } } @@ -191,7 +191,7 @@ Compaction* FIFOCompactionPicker::PickSizeCompaction( for (auto ritr = level_files.rbegin(); ritr != level_files.rend(); ++ritr) { auto f = *ritr; - total_size -= f->compensated_file_size; + total_size -= f->fd.file_size; inputs[0].files.push_back(f); char tmp_fsize[16]; AppendHumanBytes(f->fd.GetFileSize(), tmp_fsize, sizeof(tmp_fsize));