]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/sst_file_reader.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / table / sst_file_reader.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 #ifndef ROCKSDB_LITE
7
8 #include "rocksdb/sst_file_reader.h"
9
10 #include "db/arena_wrapped_db_iter.h"
11 #include "db/db_iter.h"
12 #include "db/dbformat.h"
13 #include "file/random_access_file_reader.h"
14 #include "options/cf_options.h"
15 #include "rocksdb/env.h"
16 #include "rocksdb/file_system.h"
17 #include "table/get_context.h"
18 #include "table/table_builder.h"
19 #include "table/table_reader.h"
20
21 namespace ROCKSDB_NAMESPACE {
22
23 struct SstFileReader::Rep {
24 Options options;
25 EnvOptions soptions;
26 ImmutableOptions ioptions;
27 MutableCFOptions moptions;
28
29 std::unique_ptr<TableReader> table_reader;
30
31 Rep(const Options& opts)
32 : options(opts),
33 soptions(options),
34 ioptions(options),
35 moptions(ColumnFamilyOptions(options)) {}
36 };
37
38 SstFileReader::SstFileReader(const Options& options) : rep_(new Rep(options)) {}
39
40 SstFileReader::~SstFileReader() {}
41
42 Status SstFileReader::Open(const std::string& file_path) {
43 auto r = rep_.get();
44 Status s;
45 uint64_t file_size = 0;
46 std::unique_ptr<FSRandomAccessFile> file;
47 std::unique_ptr<RandomAccessFileReader> file_reader;
48 FileOptions fopts(r->soptions);
49 const auto& fs = r->options.env->GetFileSystem();
50
51 s = fs->GetFileSize(file_path, fopts.io_options, &file_size, nullptr);
52 if (s.ok()) {
53 s = fs->NewRandomAccessFile(file_path, fopts, &file, nullptr);
54 }
55 if (s.ok()) {
56 file_reader.reset(new RandomAccessFileReader(std::move(file), file_path));
57 }
58 if (s.ok()) {
59 TableReaderOptions t_opt(r->ioptions, r->moptions.prefix_extractor,
60 r->soptions, r->ioptions.internal_comparator);
61 // Allow open file with global sequence number for backward compatibility.
62 t_opt.largest_seqno = kMaxSequenceNumber;
63 s = r->options.table_factory->NewTableReader(t_opt, std::move(file_reader),
64 file_size, &r->table_reader);
65 }
66 return s;
67 }
68
69 Iterator* SstFileReader::NewIterator(const ReadOptions& roptions) {
70 auto r = rep_.get();
71 auto sequence = roptions.snapshot != nullptr
72 ? roptions.snapshot->GetSequenceNumber()
73 : kMaxSequenceNumber;
74 ArenaWrappedDBIter* res = new ArenaWrappedDBIter();
75 res->Init(r->options.env, roptions, r->ioptions, r->moptions,
76 nullptr /* version */, sequence,
77 r->moptions.max_sequential_skip_in_iterations,
78 0 /* version_number */, nullptr /* read_callback */,
79 nullptr /* db_impl */, nullptr /* cfd */,
80 true /* expose_blob_index */, false /* allow_refresh */);
81 auto internal_iter = r->table_reader->NewIterator(
82 res->GetReadOptions(), r->moptions.prefix_extractor.get(),
83 res->GetArena(), false /* skip_filters */,
84 TableReaderCaller::kSSTFileReader);
85 res->SetIterUnderDBIter(internal_iter);
86 return res;
87 }
88
89 std::shared_ptr<const TableProperties> SstFileReader::GetTableProperties()
90 const {
91 return rep_->table_reader->GetTableProperties();
92 }
93
94 Status SstFileReader::VerifyChecksum(const ReadOptions& read_options) {
95 return rep_->table_reader->VerifyChecksum(read_options,
96 TableReaderCaller::kSSTFileReader);
97 }
98
99 } // namespace ROCKSDB_NAMESPACE
100
101 #endif // !ROCKSDB_LITE