Coverage Report

Created: 2024-07-27 06:53

/src/rocksdb/table/sst_file_dumper.h
Line
Count
Source (jump to first uncovered line)
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
7
#include <memory>
8
#include <string>
9
10
#include "db/dbformat.h"
11
#include "file/writable_file_writer.h"
12
#include "options/cf_options.h"
13
#include "rocksdb/advanced_options.h"
14
15
namespace ROCKSDB_NAMESPACE {
16
17
class SstFileDumper {
18
 public:
19
  explicit SstFileDumper(const Options& options, const std::string& file_name,
20
                         Temperature file_temp, size_t readahead_size,
21
                         bool verify_checksum, bool output_hex,
22
                         bool decode_blob_index,
23
                         const EnvOptions& soptions = EnvOptions(),
24
                         bool silent = false);
25
26
  // read_num_limit limits the total number of keys read. If read_num_limit = 0,
27
  // then there is no limit. If read_num_limit = 0 or
28
  // std::numeric_limits<uint64_t>::max(), has_from and has_to are false, then
29
  // the number of keys read is compared with `num_entries` field in table
30
  // properties. A Corruption status is returned if they do not match.
31
  Status ReadSequential(bool print_kv, uint64_t read_num_limit, bool has_from,
32
                        const std::string& from_key, bool has_to,
33
                        const std::string& to_key,
34
                        bool use_from_as_prefix = false);
35
36
  Status ReadTableProperties(
37
      std::shared_ptr<const TableProperties>* table_properties);
38
0
  uint64_t GetReadNumber() { return read_num_; }
39
0
  TableProperties* GetInitTableProperties() { return table_properties_.get(); }
40
41
  Status VerifyChecksum();
42
  Status DumpTable(const std::string& out_filename);
43
0
  Status getStatus() { return init_result_; }
44
45
  Status ShowAllCompressionSizes(
46
      size_t block_size,
47
      const std::vector<std::pair<CompressionType, const char*>>&
48
          compression_types,
49
      int32_t compress_level_from, int32_t compress_level_to,
50
      uint32_t max_dict_bytes, uint32_t zstd_max_train_bytes,
51
      uint64_t max_dict_buffer_bytes, bool use_zstd_dict_trainer);
52
53
  Status ShowCompressionSize(size_t block_size, CompressionType compress_type,
54
                             const CompressionOptions& compress_opt);
55
56
 private:
57
  // Get the TableReader implementation for the sst file
58
  Status GetTableReader(const std::string& file_path);
59
  Status ReadTableProperties(uint64_t table_magic_number,
60
                             RandomAccessFileReader* file, uint64_t file_size,
61
                             FilePrefetchBuffer* prefetch_buffer);
62
63
  Status CalculateCompressedTableSize(const TableBuilderOptions& tb_options,
64
                                      size_t block_size,
65
                                      uint64_t* num_data_blocks,
66
                                      uint64_t* compressed_table_size);
67
68
  Status SetTableOptionsByMagicNumber(uint64_t table_magic_number);
69
  Status SetOldTableOptions();
70
71
  // Helper function to call the factory with settings specific to the
72
  // factory implementation
73
  Status NewTableReader(const ImmutableOptions& ioptions,
74
                        const EnvOptions& soptions,
75
                        const InternalKeyComparator& internal_comparator,
76
                        uint64_t file_size,
77
                        std::unique_ptr<TableReader>* table_reader);
78
79
  std::string file_name_;
80
  uint64_t read_num_;
81
  Temperature file_temp_;
82
  bool output_hex_;
83
  bool decode_blob_index_;
84
  EnvOptions soptions_;
85
  // less verbose in stdout/stderr
86
  bool silent_;
87
88
  // options_ and internal_comparator_ will also be used in
89
  // ReadSequential internally (specifically, seek-related operations)
90
  Options options_;
91
92
  Status init_result_;
93
  std::unique_ptr<TableReader> table_reader_;
94
  std::unique_ptr<RandomAccessFileReader> file_;
95
96
  ImmutableOptions ioptions_;
97
  const MutableCFOptions moptions_;
98
  ReadOptions read_options_;
99
  InternalKeyComparator internal_comparator_;
100
  std::unique_ptr<TableProperties> table_properties_;
101
};
102
103
}  // namespace ROCKSDB_NAMESPACE
104