]>
Commit | Line | Data |
---|---|---|
494da23a TL |
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/db_iter.h" | |
11 | #include "db/dbformat.h" | |
12 | #include "options/cf_options.h" | |
13 | #include "table/get_context.h" | |
14 | #include "table/table_builder.h" | |
15 | #include "table/table_reader.h" | |
16 | #include "util/file_reader_writer.h" | |
17 | ||
18 | namespace rocksdb { | |
19 | ||
20 | struct SstFileReader::Rep { | |
21 | Options options; | |
22 | EnvOptions soptions; | |
23 | ImmutableCFOptions ioptions; | |
24 | MutableCFOptions moptions; | |
25 | ||
26 | std::unique_ptr<TableReader> table_reader; | |
27 | ||
28 | Rep(const Options& opts) | |
29 | : options(opts), | |
30 | soptions(options), | |
31 | ioptions(options), | |
32 | moptions(ColumnFamilyOptions(options)) {} | |
33 | }; | |
34 | ||
35 | SstFileReader::SstFileReader(const Options& options) : rep_(new Rep(options)) {} | |
36 | ||
37 | SstFileReader::~SstFileReader() {} | |
38 | ||
39 | Status SstFileReader::Open(const std::string& file_path) { | |
40 | auto r = rep_.get(); | |
41 | Status s; | |
42 | uint64_t file_size = 0; | |
43 | std::unique_ptr<RandomAccessFile> file; | |
44 | std::unique_ptr<RandomAccessFileReader> file_reader; | |
45 | s = r->options.env->GetFileSize(file_path, &file_size); | |
46 | if (s.ok()) { | |
47 | s = r->options.env->NewRandomAccessFile(file_path, &file, r->soptions); | |
48 | } | |
49 | if (s.ok()) { | |
50 | file_reader.reset(new RandomAccessFileReader(std::move(file), file_path)); | |
51 | } | |
52 | if (s.ok()) { | |
53 | TableReaderOptions t_opt(r->ioptions, r->moptions.prefix_extractor.get(), | |
54 | r->soptions, r->ioptions.internal_comparator); | |
55 | // Allow open file with global sequence number for backward compatibility. | |
56 | t_opt.largest_seqno = kMaxSequenceNumber; | |
57 | s = r->options.table_factory->NewTableReader(t_opt, std::move(file_reader), | |
58 | file_size, &r->table_reader); | |
59 | } | |
60 | return s; | |
61 | } | |
62 | ||
63 | Iterator* SstFileReader::NewIterator(const ReadOptions& options) { | |
64 | auto r = rep_.get(); | |
65 | auto sequence = options.snapshot != nullptr | |
66 | ? options.snapshot->GetSequenceNumber() | |
67 | : kMaxSequenceNumber; | |
68 | auto internal_iter = | |
69 | r->table_reader->NewIterator(options, r->moptions.prefix_extractor.get()); | |
70 | return NewDBIterator(r->options.env, options, r->ioptions, r->moptions, | |
71 | r->ioptions.user_comparator, internal_iter, sequence, | |
72 | r->moptions.max_sequential_skip_in_iterations, | |
73 | nullptr /* read_callback */); | |
74 | } | |
75 | ||
76 | std::shared_ptr<const TableProperties> SstFileReader::GetTableProperties() | |
77 | const { | |
78 | return rep_->table_reader->GetTableProperties(); | |
79 | } | |
80 | ||
81 | Status SstFileReader::VerifyChecksum() { | |
82 | return rep_->table_reader->VerifyChecksum(); | |
83 | } | |
84 | ||
85 | } // namespace rocksdb | |
86 | ||
87 | #endif // !ROCKSDB_LITE |