]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/convenience.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / db / convenience.cc
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 #ifndef ROCKSDB_LITE
8
9 #include "rocksdb/convenience.h"
10
11 #include "db/db_impl/db_impl.h"
12 #include "util/cast_util.h"
13
14 namespace ROCKSDB_NAMESPACE {
15
16 void CancelAllBackgroundWork(DB* db, bool wait) {
17 (static_cast_with_check<DBImpl, DB>(db->GetRootDB()))
18 ->CancelAllBackgroundWork(wait);
19 }
20
21 Status DeleteFilesInRange(DB* db, ColumnFamilyHandle* column_family,
22 const Slice* begin, const Slice* end,
23 bool include_end) {
24 RangePtr range(begin, end);
25 return DeleteFilesInRanges(db, column_family, &range, 1, include_end);
26 }
27
28 Status DeleteFilesInRanges(DB* db, ColumnFamilyHandle* column_family,
29 const RangePtr* ranges, size_t n,
30 bool include_end) {
31 return (static_cast_with_check<DBImpl, DB>(db->GetRootDB()))
32 ->DeleteFilesInRanges(column_family, ranges, n, include_end);
33 }
34
35 Status VerifySstFileChecksum(const Options& options,
36 const EnvOptions& env_options,
37 const std::string& file_path) {
38 return VerifySstFileChecksum(options, env_options, ReadOptions(), file_path);
39 }
40 Status VerifySstFileChecksum(const Options& options,
41 const EnvOptions& env_options,
42 const ReadOptions& read_options,
43 const std::string& file_path) {
44 std::unique_ptr<FSRandomAccessFile> file;
45 uint64_t file_size;
46 InternalKeyComparator internal_comparator(options.comparator);
47 ImmutableCFOptions ioptions(options);
48
49 Status s = ioptions.fs->NewRandomAccessFile(file_path,
50 FileOptions(env_options),
51 &file, nullptr);
52 if (s.ok()) {
53 s = ioptions.fs->GetFileSize(file_path, IOOptions(), &file_size, nullptr);
54 } else {
55 return s;
56 }
57 std::unique_ptr<TableReader> table_reader;
58 std::unique_ptr<RandomAccessFileReader> file_reader(
59 new RandomAccessFileReader(std::move(file), file_path));
60 const bool kImmortal = true;
61 s = ioptions.table_factory->NewTableReader(
62 TableReaderOptions(ioptions, options.prefix_extractor.get(), env_options,
63 internal_comparator, false /* skip_filters */,
64 !kImmortal, -1 /* level */),
65 std::move(file_reader), file_size, &table_reader,
66 false /* prefetch_index_and_filter_in_cache */);
67 if (!s.ok()) {
68 return s;
69 }
70 s = table_reader->VerifyChecksum(read_options,
71 TableReaderCaller::kUserVerifyChecksum);
72 return s;
73 }
74
75 } // namespace ROCKSDB_NAMESPACE
76
77 #endif // ROCKSDB_LITE