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