sst_file_dumper.h 4.0 KB

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