Skip to content

Commit 80f3d86

Browse files
mszeszko-metameta-codesync[bot]
authored andcommitted
Remove FIFO eviction support (facebook#14268)
Summary: Pull Request resolved: facebook#14268 FIFO eviction is unused in production, making this dead code that adds complexity. Core changes: - Remove `is_fifo` from `BlobDBOptions` - Remove `CheckSizeAndEvictBlobFiles` and related methods - Remove `fifo_eviction_seq` and `evict_expiration_up_to` from `BlobCompactionContext` CLI tool cleanup: - Remove `--blob_db_is_fifo` flag from db_bench - Remove stale FIFO eviction comments Tests: - Remove FIFO-related tests (`FIFOEviction_*`, `FilterForFIFOEviction`) Note: TTL-based expiration (`EvictExpiredFiles`) is preserved as it handles blob file cleanup based on TTL, which is separate from FIFO eviction. Reviewed By: xingbowang Differential Revision: D91088968 fbshipit-source-id: 123df98d1132095cef15473b76011de030c5df34
1 parent 2366f63 commit 80f3d86

9 files changed

Lines changed: 25 additions & 444 deletions

File tree

tools/db_bench_tool.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,6 @@ DEFINE_double(
10551055
ROCKSDB_NAMESPACE::blob_db::BlobDBOptions().garbage_collection_cutoff,
10561056
"[Stacked BlobDB] Cutoff ratio for BlobDB garbage collection.");
10571057

1058-
DEFINE_bool(blob_db_is_fifo,
1059-
ROCKSDB_NAMESPACE::blob_db::BlobDBOptions().is_fifo,
1060-
"[Stacked BlobDB] Enable FIFO eviction strategy in BlobDB.");
1061-
10621058
DEFINE_uint64(blob_db_max_db_size,
10631059
ROCKSDB_NAMESPACE::blob_db::BlobDBOptions().max_db_size,
10641060
"[Stacked BlobDB] Max size limit of the directory where blob "
@@ -5192,7 +5188,6 @@ class Benchmark {
51925188
blob_db::BlobDBOptions blob_db_options;
51935189
blob_db_options.enable_garbage_collection = FLAGS_blob_db_enable_gc;
51945190
blob_db_options.garbage_collection_cutoff = FLAGS_blob_db_gc_cutoff;
5195-
blob_db_options.is_fifo = FLAGS_blob_db_is_fifo;
51965191
blob_db_options.max_db_size = FLAGS_blob_db_max_db_size;
51975192
blob_db_options.ttl_range_secs = FLAGS_blob_db_ttl_range_secs;
51985193
blob_db_options.min_blob_size = FLAGS_blob_db_min_blob_size;

utilities/blob_db/blob_compaction_filter.cc

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,10 @@ CompactionFilter::Decision BlobIndexCompactionFilterBase::FilterV2(
5555
if (!blob_index.IsInlined() &&
5656
blob_index.file_number() < context_.next_file_number &&
5757
context_.current_blob_files.count(blob_index.file_number()) == 0) {
58-
// Corresponding blob file gone (most likely, evicted by FIFO eviction).
5958
evicted_count_++;
6059
evicted_size_ += key.size() + value.size();
6160
return Decision::kRemove;
6261
}
63-
if (context_.fifo_eviction_seq > 0 && blob_index.HasTTL() &&
64-
blob_index.expiration() < context_.evict_expiration_up_to) {
65-
// Hack: Internal key is passed to BlobIndexCompactionFilter for it to
66-
// get sequence number.
67-
ParsedInternalKey ikey;
68-
if (!ParseInternalKey(
69-
key, &ikey,
70-
context_.blob_db_impl->db_options_.allow_data_in_errors)
71-
.ok()) {
72-
assert(false);
73-
return Decision::kKeep;
74-
}
75-
// Remove keys that could have been remove by last FIFO eviction.
76-
// If get error while parsing key, ignore and continue.
77-
if (ikey.sequence < context_.fifo_eviction_seq) {
78-
evicted_count_++;
79-
evicted_size_ += key.size() + value.size();
80-
return Decision::kRemove;
81-
}
82-
}
8362
// Apply user compaction filter for all non-TTL blob data.
8463
if (ucf != nullptr && !blob_index.HasTTL()) {
8564
// Hack: Internal key is passed to BlobIndexCompactionFilter for it to
@@ -281,8 +260,7 @@ bool BlobIndexCompactionFilterBase::CloseAndRegisterNewBlobFile() const {
281260
// TODO: plumb Env::IOActivity, Env::IOPriority
282261
s = blob_db_impl->CloseBlobFile(WriteOptions(), blob_file_);
283262

284-
// Note: we delay registering the new blob file until it's closed to
285-
// prevent FIFO eviction from processing it during compaction/GC.
263+
// Note: we delay registering the new blob file until it's closed.
286264
blob_db_impl->RegisterBlobFile(blob_file_);
287265
}
288266

utilities/blob_db/blob_compaction_filter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ struct BlobCompactionContext {
2121
BlobDBImpl* blob_db_impl = nullptr;
2222
uint64_t next_file_number = 0;
2323
std::unordered_set<uint64_t> current_blob_files;
24-
SequenceNumber fifo_eviction_seq = 0;
25-
uint64_t evict_expiration_up_to = 0;
2624
};
2725

2826
struct BlobCompactionContextGC {

utilities/blob_db/blob_db.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ void BlobDBOptions::Dump(Logger* log) const {
7474
ROCKS_LOG_HEADER(
7575
log, " BlobDBOptions.path_relative: %d",
7676
path_relative);
77-
ROCKS_LOG_HEADER(
78-
log, " BlobDBOptions.is_fifo: %d",
79-
is_fifo);
8077
ROCKS_LOG_HEADER(
8178
log, " BlobDBOptions.max_db_size: %" PRIu64,
8279
max_db_size);

utilities/blob_db/blob_db.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ struct BlobDBOptions {
3535
// whether the blob_dir path is relative or absolute.
3636
bool path_relative = true;
3737

38-
// When max_db_size is reached, evict blob files to free up space
39-
// instead of returnning NoSpace error on write. Blob files will be
40-
// evicted from oldest to newest, based on file creation time.
41-
bool is_fifo = false;
42-
4338
// Maximum size of the database (including SST files and blob files).
4439
//
4540
// Default: 0 (no limits)

utilities/blob_db/blob_db_impl.cc

Lines changed: 12 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ BlobDBImpl::BlobDBImpl(const std::string& dbname,
8181
open_file_count_(0),
8282
total_blob_size_(0),
8383
live_sst_size_(0),
84-
fifo_eviction_seq_(0),
85-
evict_expiration_up_to_(0),
8684
debug_level_(0) {
8785
clock_ = env_->GetSystemClock().get();
8886
blob_dir_ = (bdb_options_.path_relative)
@@ -277,7 +275,7 @@ Status BlobDBImpl::Open(std::vector<ColumnFamilyHandle*>* handles) {
277275
return s;
278276
}
279277

280-
UpdateLiveSSTSize(WriteOptions(Env::IOActivity::kDBOpen));
278+
UpdateLiveSSTSize();
281279

282280
// Start background jobs.
283281
if (!bdb_options_.disable_background_tasks) {
@@ -591,7 +589,6 @@ bool BlobDBImpl::MarkBlobFileObsoleteIfNeeded(
591589
assert(blob_file->Immutable());
592590
assert(bdb_options_.enable_garbage_collection);
593591

594-
// Note: FIFO eviction could have marked this file obsolete already.
595592
if (blob_file->Obsolete()) {
596593
return true;
597594
}
@@ -1095,11 +1092,8 @@ Status BlobDBImpl::PutBlobValue(const WriteOptions& write_options,
10951092
std::string headerbuf;
10961093
BlobLogWriter::ConstructBlobHeader(&headerbuf, key, value, expiration);
10971094

1098-
// Check DB size limit before selecting blob file to
1099-
// Since CheckSizeAndEvictBlobFiles() can close blob files, it needs to be
1100-
// done before calling SelectBlobFile().
1101-
s = CheckSizeAndEvictBlobFiles(
1102-
write_options, headerbuf.size() + key.size() + value.size());
1095+
// Check DB size limit before selecting blob file.
1096+
s = CheckDbSizeLimit(headerbuf.size() + key.size() + value.size());
11031097
if (!s.ok()) {
11041098
return s;
11051099
}
@@ -1187,8 +1181,6 @@ void BlobDBImpl::GetCompactionContextCommon(BlobCompactionContext* context) {
11871181
for (auto& p : blob_files_) {
11881182
context->current_blob_files.insert(p.first);
11891183
}
1190-
context->fifo_eviction_seq = fifo_eviction_seq_;
1191-
context->evict_expiration_up_to = evict_expiration_up_to_;
11921184
}
11931185

11941186
void BlobDBImpl::GetCompactionContext(BlobCompactionContext* context) {
@@ -1216,7 +1208,7 @@ void BlobDBImpl::GetCompactionContext(BlobCompactionContext* context,
12161208
}
12171209
}
12181210

1219-
void BlobDBImpl::UpdateLiveSSTSize(const WriteOptions& write_options) {
1211+
void BlobDBImpl::UpdateLiveSSTSize() {
12201212
uint64_t live_sst_size = 0;
12211213
bool ok = GetIntProperty(DB::Properties::kLiveSstFilesSize, &live_sst_size);
12221214
if (ok) {
@@ -1229,90 +1221,21 @@ void BlobDBImpl::UpdateLiveSSTSize(const WriteOptions& write_options) {
12291221
db_options_.info_log,
12301222
"Failed to update total SST file size after flush or compaction.");
12311223
}
1232-
{
1233-
// Trigger FIFO eviction if needed.
1234-
MutexLock l(&write_mutex_);
1235-
Status s = CheckSizeAndEvictBlobFiles(write_options, 0, true /*force*/);
1236-
if (s.IsNoSpace()) {
1237-
ROCKS_LOG_WARN(db_options_.info_log,
1238-
"DB grow out-of-space after SST size updated. Current live"
1239-
" SST size: %" PRIu64
1240-
" , current blob files size: %" PRIu64 ".",
1241-
live_sst_size_.load(), total_blob_size_.load());
1242-
}
1243-
}
12441224
}
12451225

1246-
Status BlobDBImpl::CheckSizeAndEvictBlobFiles(const WriteOptions& write_options,
1247-
uint64_t blob_size,
1248-
bool force_evict) {
1249-
write_mutex_.AssertHeld();
1250-
1251-
uint64_t live_sst_size = live_sst_size_.load();
1252-
if (bdb_options_.max_db_size == 0 ||
1253-
live_sst_size + total_blob_size_.load() + blob_size <=
1254-
bdb_options_.max_db_size) {
1226+
Status BlobDBImpl::CheckDbSizeLimit(uint64_t blob_size) {
1227+
if (bdb_options_.max_db_size == 0) {
12551228
return Status::OK();
12561229
}
12571230

1258-
if (bdb_options_.is_fifo == false ||
1259-
(!force_evict && live_sst_size + blob_size > bdb_options_.max_db_size)) {
1260-
// FIFO eviction is disabled, or no space to insert new blob even we evict
1261-
// all blob files.
1262-
return Status::NoSpace(
1263-
"Write failed, as writing it would exceed max_db_size limit.");
1231+
uint64_t live_sst_size = live_sst_size_.load();
1232+
uint64_t total_blob_size = total_blob_size_.load();
1233+
if (live_sst_size + total_blob_size + blob_size <= bdb_options_.max_db_size) {
1234+
return Status::OK();
12641235
}
12651236

1266-
std::vector<std::shared_ptr<BlobFile>> candidate_files;
1267-
CopyBlobFiles(&candidate_files);
1268-
std::sort(candidate_files.begin(), candidate_files.end(),
1269-
BlobFileComparator());
1270-
fifo_eviction_seq_ = GetLatestSequenceNumber();
1271-
1272-
WriteLock l(&mutex_);
1273-
1274-
while (!candidate_files.empty() &&
1275-
live_sst_size + total_blob_size_.load() + blob_size >
1276-
bdb_options_.max_db_size) {
1277-
std::shared_ptr<BlobFile> blob_file = candidate_files.back();
1278-
candidate_files.pop_back();
1279-
WriteLock file_lock(&blob_file->mutex_);
1280-
if (blob_file->Obsolete()) {
1281-
// File already obsoleted by someone else.
1282-
assert(blob_file->Immutable());
1283-
continue;
1284-
}
1285-
// FIFO eviction can evict open blob files.
1286-
if (!blob_file->Immutable()) {
1287-
Status s = CloseBlobFile(write_options, blob_file);
1288-
if (!s.ok()) {
1289-
return s;
1290-
}
1291-
}
1292-
assert(blob_file->Immutable());
1293-
auto expiration_range = blob_file->GetExpirationRange();
1294-
ROCKS_LOG_INFO(db_options_.info_log,
1295-
"Evict oldest blob file since DB out of space. Current "
1296-
"live SST file size: %" PRIu64 ", total blob size: %" PRIu64
1297-
", max db size: %" PRIu64 ", evicted blob file #%" PRIu64
1298-
".",
1299-
live_sst_size, total_blob_size_.load(),
1300-
bdb_options_.max_db_size, blob_file->BlobFileNumber());
1301-
ObsoleteBlobFile(blob_file, fifo_eviction_seq_, true /*update_size*/);
1302-
evict_expiration_up_to_ = expiration_range.first;
1303-
RecordTick(statistics_, BLOB_DB_FIFO_NUM_FILES_EVICTED);
1304-
RecordTick(statistics_, BLOB_DB_FIFO_NUM_KEYS_EVICTED,
1305-
blob_file->BlobCount());
1306-
RecordTick(statistics_, BLOB_DB_FIFO_BYTES_EVICTED,
1307-
blob_file->GetFileSize());
1308-
TEST_SYNC_POINT("BlobDBImpl::EvictOldestBlobFile:Evicted");
1309-
}
1310-
if (live_sst_size + total_blob_size_.load() + blob_size >
1311-
bdb_options_.max_db_size) {
1312-
return Status::NoSpace(
1313-
"Write failed, as writing it would exceed max_db_size limit.");
1314-
}
1315-
return Status::OK();
1237+
return Status::NoSpace(
1238+
"Write failed, as writing it would exceed max_db_size limit.");
13161239
}
13171240

13181241
Status BlobDBImpl::AppendBlob(const WriteOptions& write_options,

utilities/blob_db/blob_db_impl.h

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ class BlobDBImpl : public BlobDB {
9393
// how often to schedule expired files eviction.
9494
static constexpr uint32_t kEvictExpiredFilesPeriodMillisecs = 10 * 1000;
9595

96-
// when should oldest file be evicted:
97-
// on reaching 90% of blob_dir_size
98-
static constexpr double kEvictOldestFileAtSize = 0.9;
99-
10096
using BlobDB::Put;
10197
Status Put(const WriteOptions& options, const Slice& key,
10298
const Slice& value) override;
@@ -194,10 +190,10 @@ class BlobDBImpl : public BlobDB {
194190
SequenceNumber obsolete_seq = 0,
195191
bool update_size = true);
196192

197-
void TEST_EvictExpiredFiles();
198-
199193
void TEST_DeleteObsoleteFiles();
200194

195+
void TEST_EvictExpiredFiles();
196+
201197
uint64_t TEST_live_sst_size();
202198

203199
const std::string& TEST_blob_dir() const { return blob_dir_; }
@@ -287,15 +283,14 @@ class BlobDBImpl : public BlobDB {
287283
// or GC). Check whether any snapshots exist which refer to the same.
288284
std::pair<bool, int64_t> DeleteObsoleteFiles(bool aborted);
289285

290-
// periodically check if open blob files and their TTL's has expired
291-
// if expired, close the sequential writer and make the file immutable
292-
std::pair<bool, int64_t> EvictExpiredFiles(bool aborted);
293-
294286
// if the number of open files, approaches ULIMIT's this
295287
// task will close random readers, which are kept around for
296288
// efficiency
297289
std::pair<bool, int64_t> ReclaimOpenFiles(bool aborted);
298290

291+
// Evict expired blob files from the TTL queue.
292+
std::pair<bool, int64_t> EvictExpiredFiles(bool aborted);
293+
299294
std::pair<bool, int64_t> RemoveTimerQ(TimerQueue* tq, bool aborted);
300295

301296
// Adds the background tasks to the timer queue
@@ -359,7 +354,11 @@ class BlobDBImpl : public BlobDB {
359354
void MarkUnreferencedBlobFilesObsolete();
360355
void MarkUnreferencedBlobFilesObsoleteDuringOpen();
361356

362-
void UpdateLiveSSTSize(const WriteOptions& write_options);
357+
void UpdateLiveSSTSize();
358+
359+
// Check if writing blob_size bytes would exceed max_db_size limit.
360+
// Returns Status::NoSpace() if limit would be exceeded.
361+
Status CheckDbSizeLimit(uint64_t blob_size);
363362

364363
Status GetBlobFileReader(const std::shared_ptr<BlobFile>& blob_file,
365364
std::shared_ptr<RandomAccessFileReader>* reader);
@@ -386,14 +385,6 @@ class BlobDBImpl : public BlobDB {
386385

387386
uint64_t EpochNow() { return clock_->NowMicros() / 1000000; }
388387

389-
// Check if inserting a new blob will make DB grow out of space.
390-
// If is_fifo = true, FIFO eviction will be triggered to make room for the
391-
// new blob. If force_evict = true, FIFO eviction will evict blob files
392-
// even eviction will not make enough room for the new blob.
393-
Status CheckSizeAndEvictBlobFiles(const WriteOptions& write_options,
394-
uint64_t blob_size,
395-
bool force_evict = false);
396-
397388
Status CloseImpl();
398389

399390
// name of the database directory
@@ -462,16 +453,6 @@ class BlobDBImpl : public BlobDB {
462453
// total size of SST files.
463454
std::atomic<uint64_t> live_sst_size_;
464455

465-
// Latest FIFO eviction timestamp
466-
//
467-
// REQUIRES: access with metex_ lock held.
468-
uint64_t fifo_eviction_seq_;
469-
470-
// The expiration up to which latest FIFO eviction evicts.
471-
//
472-
// REQUIRES: access with metex_ lock held.
473-
uint64_t evict_expiration_up_to_;
474-
475456
std::list<std::shared_ptr<BlobFile>> obsolete_files_;
476457

477458
// DeleteObsoleteFiles, DiableFileDeletions and EnableFileDeletions block

utilities/blob_db/blob_db_listener.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ class BlobDBListener : public EventListener {
2727

2828
void OnFlushCompleted(DB* /*db*/, const FlushJobInfo& /*info*/) override {
2929
assert(blob_db_impl_ != nullptr);
30-
blob_db_impl_->UpdateLiveSSTSize(WriteOptions(Env::IOActivity::kFlush));
30+
blob_db_impl_->UpdateLiveSSTSize();
3131
}
3232

3333
void OnCompactionCompleted(DB* /*db*/,
3434
const CompactionJobInfo& /*info*/) override {
3535
assert(blob_db_impl_ != nullptr);
36-
blob_db_impl_->UpdateLiveSSTSize(
37-
WriteOptions(Env::IOActivity::kCompaction));
36+
blob_db_impl_->UpdateLiveSSTSize();
3837
}
3938

4039
const char* Name() const override { return kClassName(); }

0 commit comments

Comments
 (0)