Coverage Report

Created: 2026-09-28 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/db/convenience.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
7
#include "rocksdb/convenience.h"
8
9
#include "db/convenience_impl.h"
10
#include "db/db_impl/db_impl.h"
11
#include "util/cast_util.h"
12
13
namespace ROCKSDB_NAMESPACE {
14
15
0
void CancelAllBackgroundWork(DB* db, bool wait) {
16
0
  (static_cast_with_check<DBImpl>(db->GetRootDB()))
17
0
      ->CancelAllBackgroundWork(wait);
18
0
}
19
20
Status DeleteFilesInRange(DB* db, ColumnFamilyHandle* column_family,
21
                          const Slice* begin, const Slice* end,
22
0
                          bool include_end) {
23
0
  RangePtr range(begin, end);
24
0
  return DeleteFilesInRanges(db, column_family, &range, 1, include_end);
25
0
}
26
27
Status DeleteFilesInRanges(DB* db, ColumnFamilyHandle* column_family,
28
0
                           const RangePtr* ranges, size_t n, bool include_end) {
29
0
  std::vector<RangeOpt> range_opts(n);
30
0
  for (size_t i = 0; i < n; ++i) {
31
0
    range_opts[i] = {OptSlice::CopyFromPtr(ranges[i].start),
32
0
                     OptSlice::CopyFromPtr(ranges[i].limit)};
33
0
  }
34
0
  return DeleteFilesInRanges(db, column_family, range_opts.data(), n,
35
0
                             include_end);
36
0
}
37
38
Status DeleteFilesInRanges(DB* db, ColumnFamilyHandle* column_family,
39
0
                           const RangeOpt* ranges, size_t n, bool include_end) {
40
0
  return (static_cast_with_check<DBImpl>(db->GetRootDB()))
41
0
      ->DeleteFilesInRanges(column_family, ranges, n, include_end);
42
0
}
43
44
Status VerifySstFileChecksum(const Options& options,
45
                             const EnvOptions& env_options,
46
0
                             const std::string& file_path) {
47
  // TODO: plumb Env::IOActivity, Env::IOPriority
48
0
  const ReadOptions read_options;
49
0
  return VerifySstFileChecksum(options, env_options, read_options, file_path);
50
0
}
51
Status VerifySstFileChecksum(const Options& options,
52
                             const EnvOptions& env_options,
53
                             const ReadOptions& _read_options,
54
                             const std::string& file_path,
55
0
                             const SequenceNumber& largest_seqno) {
56
0
  if (_read_options.io_activity != Env::IOActivity::kUnknown) {
57
0
    return Status::InvalidArgument(
58
0
        "Can only call VerifySstFileChecksum with `ReadOptions::io_activity` "
59
0
        "is "
60
0
        "`Env::IOActivity::kUnknown`");
61
0
  }
62
0
  ReadOptions read_options(_read_options);
63
0
  return VerifySstFileChecksumInternal(options, env_options, read_options,
64
0
                                       file_path, largest_seqno);
65
0
}
66
67
Status VerifySstFileChecksumInternal(const Options& options,
68
                                     const FileOptions& file_options,
69
                                     const ReadOptions& read_options,
70
                                     const std::string& file_path,
71
0
                                     const SequenceNumber& largest_seqno) {
72
0
  std::unique_ptr<FSRandomAccessFile> file;
73
0
  uint64_t file_size;
74
0
  InternalKeyComparator internal_comparator(options.comparator);
75
0
  ImmutableOptions ioptions(options);
76
77
0
  Status s =
78
0
      ioptions.fs->NewRandomAccessFile(file_path, file_options, &file, nullptr);
79
0
  if (s.ok()) {
80
0
    s = ioptions.fs->GetFileSize(file_path, IOOptions(), &file_size, nullptr);
81
0
  } else {
82
0
    return s;
83
0
  }
84
0
  if (!s.ok()) {
85
0
    return s;
86
0
  }
87
0
  std::unique_ptr<TableReader> table_reader;
88
0
  std::unique_ptr<RandomAccessFileReader> file_reader(
89
0
      new RandomAccessFileReader(
90
0
          std::move(file), file_path, ioptions.clock, nullptr /* io_tracer */,
91
0
          ioptions.stats /* stats */,
92
0
          Histograms::SST_READ_MICROS /* hist_type */,
93
0
          nullptr /* file_read_hist */, ioptions.rate_limiter.get()));
94
0
  const bool kImmortal = true;
95
0
  auto reader_options = TableReaderOptions(
96
0
      ioptions, options.prefix_extractor, options.compression_manager.get(),
97
0
      file_options, internal_comparator, options.block_protection_bytes_per_key,
98
0
      false /* skip_filters */, !kImmortal, false /* force_direct_prefetch */,
99
0
      -1 /* level */);
100
0
  reader_options.largest_seqno = largest_seqno;
101
0
  s = options.table_factory->NewTableReader(
102
0
      read_options, reader_options, std::move(file_reader), file_size,
103
0
      &table_reader, false /* prefetch_index_and_filter_in_cache */);
104
0
  if (!s.ok()) {
105
0
    return s;
106
0
  }
107
0
  s = table_reader->VerifyChecksum(read_options,
108
0
                                   TableReaderCaller::kUserVerifyChecksum);
109
0
  return s;
110
0
}
111
112
}  // namespace ROCKSDB_NAMESPACE