]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/sst_file_dumper.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / table / sst_file_dumper.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 <memory>
9 #include <string>
10 #include "db/dbformat.h"
11 #include "file/writable_file_writer.h"
12 #include "options/cf_options.h"
13
14 namespace ROCKSDB_NAMESPACE {
15
16 class SstFileDumper {
17 public:
18 explicit SstFileDumper(const Options& options, const std::string& file_name,
19 size_t readahead_size, bool verify_checksum,
20 bool output_hex, bool decode_blob_index,
21 const EnvOptions& soptions = EnvOptions(),
22 bool silent = false);
23
24 Status ReadSequential(bool print_kv, uint64_t read_num, bool has_from,
25 const std::string& from_key, bool has_to,
26 const std::string& to_key,
27 bool use_from_as_prefix = false);
28
29 Status ReadTableProperties(
30 std::shared_ptr<const TableProperties>* table_properties);
31 uint64_t GetReadNumber() { return read_num_; }
32 TableProperties* GetInitTableProperties() { return table_properties_.get(); }
33
34 Status VerifyChecksum();
35 Status DumpTable(const std::string& out_filename);
36 Status getStatus() { return init_result_; }
37
38 Status ShowAllCompressionSizes(
39 size_t block_size,
40 const std::vector<std::pair<CompressionType, const char*>>&
41 compression_types,
42 int32_t compress_level_from, int32_t compress_level_to,
43 uint32_t max_dict_bytes, uint32_t zstd_max_train_bytes);
44
45 Status ShowCompressionSize(size_t block_size, CompressionType compress_type,
46 const CompressionOptions& compress_opt);
47
48 private:
49 // Get the TableReader implementation for the sst file
50 Status GetTableReader(const std::string& file_path);
51 Status ReadTableProperties(uint64_t table_magic_number,
52 RandomAccessFileReader* file, uint64_t file_size,
53 FilePrefetchBuffer* prefetch_buffer);
54
55 Status CalculateCompressedTableSize(const TableBuilderOptions& tb_options,
56 size_t block_size,
57 uint64_t* num_data_blocks,
58 uint64_t* compressed_table_size);
59
60 Status SetTableOptionsByMagicNumber(uint64_t table_magic_number);
61 Status SetOldTableOptions();
62
63 // Helper function to call the factory with settings specific to the
64 // factory implementation
65 Status NewTableReader(const ImmutableCFOptions& ioptions,
66 const EnvOptions& soptions,
67 const InternalKeyComparator& internal_comparator,
68 uint64_t file_size,
69 std::unique_ptr<TableReader>* table_reader);
70
71 std::string file_name_;
72 uint64_t read_num_;
73 bool output_hex_;
74 bool decode_blob_index_;
75 EnvOptions soptions_;
76 // less verbose in stdout/stderr
77 bool silent_;
78
79 // options_ and internal_comparator_ will also be used in
80 // ReadSequential internally (specifically, seek-related operations)
81 Options options_;
82
83 Status init_result_;
84 std::unique_ptr<TableReader> table_reader_;
85 std::unique_ptr<RandomAccessFileReader> file_;
86
87 const ImmutableCFOptions ioptions_;
88 const MutableCFOptions moptions_;
89 ReadOptions read_options_;
90 InternalKeyComparator internal_comparator_;
91 std::unique_ptr<TableProperties> table_properties_;
92 };
93
94 } // namespace ROCKSDB_NAMESPACE
95
96 #endif // ROCKSDB_LITE