Coverage Report

Created: 2026-03-31 07:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/table/sst_file_dumper.h
Line
Count
Source
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
                         bool show_sequence_number_type = false);
26
27
  // read_num_limit limits the total number of keys read. If read_num_limit = 0,
28
  // then there is no limit. If read_num_limit = 0 or
29
  // std::numeric_limits<uint64_t>::max(), has_from and has_to are false, then
30
  // the number of keys read is compared with `num_entries` field in table
31
  // properties. A Corruption status is returned if they do not match.
32
  Status ReadSequential(bool print_kv, uint64_t read_num_limit, bool has_from,
33
                        const std::string& from_key, bool has_to,
34
                        const std::string& to_key,
35
                        bool use_from_as_prefix = false);
36
37
  Status ReadTableProperties(
38
      std::shared_ptr<const TableProperties>* table_properties);
39
0
  uint64_t GetReadNumber() { return read_num_; }
40
0
  TableProperties* GetInitTableProperties() { return table_properties_.get(); }
41
42
  Status VerifyChecksum();
43
  Status DumpTable(const std::string& out_filename);
44
0
  Status getStatus() { return init_result_; }
45
46
  Status ShowAllCompressionSizes(
47
      const std::vector<CompressionType>& compression_types,
48
      int32_t compress_level_from, int32_t compress_level_to);
49
50
  Status ShowCompressionSize(CompressionType compress_type,
51
                             const CompressionOptions& compress_opt);
52
53
0
  BlockContents& GetMetaIndexContents() { return meta_index_contents_; }
54
55
 private:
56
  // Get the TableReader implementation for the sst file
57
  Status GetTableReader(const std::string& file_path);
58
  Status ReadTableProperties(uint64_t table_magic_number,
59
                             RandomAccessFileReader* file, uint64_t file_size,
60
                             FilePrefetchBuffer* prefetch_buffer);
61
62
  Status CalculateCompressedTableSize(const TableBuilderOptions& tb_options,
63
                                      TableProperties* props,
64
                                      std::chrono::microseconds* write_time,
65
                                      std::chrono::microseconds* read_time);
66
67
  Status SetTableOptionsByMagicNumber(uint64_t table_magic_number);
68
69
  // Helper function to call the factory with settings specific to the
70
  // factory implementation
71
  Status NewTableReader(const ImmutableOptions& ioptions,
72
                        const EnvOptions& soptions,
73
                        const InternalKeyComparator& internal_comparator,
74
                        uint64_t file_size,
75
                        std::unique_ptr<TableReader>* table_reader);
76
77
  std::string file_name_;
78
  uint64_t read_num_;
79
  Temperature file_temp_;
80
  bool output_hex_;
81
  bool decode_blob_index_;
82
  bool show_sequence_number_type_;
83
  EnvOptions soptions_;
84
  // less verbose in stdout/stderr
85
  bool silent_;
86
87
  // options_ and internal_comparator_ will also be used in
88
  // ReadSequential internally (specifically, seek-related operations)
89
  Options options_;
90
91
  Status init_result_;
92
  std::unique_ptr<TableReader> table_reader_;
93
  std::unique_ptr<RandomAccessFileReader> file_;
94
95
  ImmutableOptions ioptions_;
96
  const MutableCFOptions moptions_;
97
  ReadOptions read_options_;
98
  InternalKeyComparator internal_comparator_;
99
  std::unique_ptr<TableProperties> table_properties_;
100
  BlockContents meta_index_contents_;
101
};
102
103
}  // namespace ROCKSDB_NAMESPACE