Coverage Report

Created: 2026-09-28 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/db/trim_history_scheduler.cc
Line
Count
Source
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under both the GPLv2 (found in the
3
//  COPYING file in the root directory) and Apache 2.0 License
4
//  (found in the LICENSE.Apache file in the root directory).
5
6
#include "db/trim_history_scheduler.h"
7
8
#include <cassert>
9
10
#include "db/column_family.h"
11
12
namespace ROCKSDB_NAMESPACE {
13
14
0
void TrimHistoryScheduler::ScheduleWork(ColumnFamilyData* cfd) {
15
0
  std::lock_guard<std::mutex> lock(checking_mutex_);
16
0
  cfd->Ref();
17
0
  cfds_.push_back(cfd);
18
0
  is_empty_.store(false, std::memory_order_relaxed);
19
0
}
20
21
98.2k
ColumnFamilyData* TrimHistoryScheduler::TakeNextColumnFamily() {
22
98.2k
  std::lock_guard<std::mutex> lock(checking_mutex_);
23
98.2k
  while (true) {
24
98.2k
    if (cfds_.empty()) {
25
98.2k
      return nullptr;
26
98.2k
    }
27
0
    ColumnFamilyData* cfd = cfds_.back();
28
0
    cfds_.pop_back();
29
0
    if (cfds_.empty()) {
30
0
      is_empty_.store(true, std::memory_order_relaxed);
31
0
    }
32
33
0
    if (!cfd->IsDropped()) {
34
      // success
35
0
      return cfd;
36
0
    }
37
0
    cfd->UnrefAndTryDelete();
38
0
  }
39
98.2k
}
40
41
826k
bool TrimHistoryScheduler::Empty() {
42
826k
  bool is_empty = is_empty_.load(std::memory_order_relaxed);
43
826k
  return is_empty;
44
826k
}
45
46
98.2k
void TrimHistoryScheduler::Clear() {
47
98.2k
  ColumnFamilyData* cfd;
48
98.2k
  while ((cfd = TakeNextColumnFamily()) != nullptr) {
49
0
    cfd->UnrefAndTryDelete();
50
0
  }
51
  assert(Empty());
52
98.2k
}
53
54
}  // namespace ROCKSDB_NAMESPACE