]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/tools/sst_dump_tool_imp.h
ca60dd93c9c6a065d7401d47391c3b518ceab8cd
[ceph.git] / ceph / src / rocksdb / tools / sst_dump_tool_imp.h
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 #pragma once
6 #ifndef ROCKSDB_LITE
7
8 #include "rocksdb/sst_dump_tool.h"
9
10 #include <memory>
11 #include <string>
12 #include "db/dbformat.h"
13 #include "options/cf_options.h"
14 #include "util/file_reader_writer.h"
15
16 namespace rocksdb {
17
18 class SstFileReader {
19 public:
20 explicit SstFileReader(const std::string& file_name, bool verify_checksum,
21 bool output_hex);
22
23 Status ReadSequential(bool print_kv, uint64_t read_num, bool has_from,
24 const std::string& from_key, bool has_to,
25 const std::string& to_key,
26 bool use_from_as_prefix = false);
27
28 Status ReadTableProperties(
29 std::shared_ptr<const TableProperties>* table_properties);
30 uint64_t GetReadNumber() { return read_num_; }
31 TableProperties* GetInitTableProperties() { return table_properties_.get(); }
32
33 Status VerifyChecksum();
34 Status DumpTable(const std::string& out_filename);
35 Status getStatus() { return init_result_; }
36
37 int ShowAllCompressionSizes(
38 size_t block_size,
39 const std::vector<std::pair<CompressionType, const char*>>&
40 compression_types);
41
42 private:
43 // Get the TableReader implementation for the sst file
44 Status GetTableReader(const std::string& file_path);
45 Status ReadTableProperties(uint64_t table_magic_number,
46 RandomAccessFileReader* file, uint64_t file_size);
47
48 uint64_t CalculateCompressedTableSize(const TableBuilderOptions& tb_options,
49 size_t block_size);
50
51 Status SetTableOptionsByMagicNumber(uint64_t table_magic_number);
52 Status SetOldTableOptions();
53
54 // Helper function to call the factory with settings specific to the
55 // factory implementation
56 Status NewTableReader(const ImmutableCFOptions& ioptions,
57 const EnvOptions& soptions,
58 const InternalKeyComparator& internal_comparator,
59 uint64_t file_size,
60 unique_ptr<TableReader>* table_reader);
61
62 std::string file_name_;
63 uint64_t read_num_;
64 bool verify_checksum_;
65 bool output_hex_;
66 EnvOptions soptions_;
67
68 // options_ and internal_comparator_ will also be used in
69 // ReadSequential internally (specifically, seek-related operations)
70 Options options_;
71
72 Status init_result_;
73 unique_ptr<TableReader> table_reader_;
74 unique_ptr<RandomAccessFileReader> file_;
75
76 const ImmutableCFOptions ioptions_;
77 const MutableCFOptions moptions_;
78 InternalKeyComparator internal_comparator_;
79 unique_ptr<TableProperties> table_properties_;
80 };
81
82 } // namespace rocksdb
83
84 #endif // ROCKSDB_LITE