sst_dump_tool_imp.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include "rocksdb/sst_dump_tool.h"
  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. namespace ROCKSDB_NAMESPACE {
  14. class SstFileDumper {
  15. public:
  16. explicit SstFileDumper(const Options& options, const std::string& file_name,
  17. bool verify_checksum, bool output_hex,
  18. bool decode_blob_index);
  19. Status ReadSequential(bool print_kv, uint64_t read_num, bool has_from,
  20. const std::string& from_key, bool has_to,
  21. const std::string& to_key,
  22. bool use_from_as_prefix = false);
  23. Status ReadTableProperties(
  24. std::shared_ptr<const TableProperties>* table_properties);
  25. uint64_t GetReadNumber() { return read_num_; }
  26. TableProperties* GetInitTableProperties() { return table_properties_.get(); }
  27. Status VerifyChecksum();
  28. Status DumpTable(const std::string& out_filename);
  29. Status getStatus() { return init_result_; }
  30. int ShowAllCompressionSizes(
  31. size_t block_size,
  32. const std::vector<std::pair<CompressionType, const char*>>&
  33. compression_types);
  34. private:
  35. // Get the TableReader implementation for the sst file
  36. Status GetTableReader(const std::string& file_path);
  37. Status ReadTableProperties(uint64_t table_magic_number,
  38. RandomAccessFileReader* file, uint64_t file_size);
  39. uint64_t CalculateCompressedTableSize(const TableBuilderOptions& tb_options,
  40. size_t block_size,
  41. uint64_t* num_data_blocks);
  42. Status SetTableOptionsByMagicNumber(uint64_t table_magic_number);
  43. Status SetOldTableOptions();
  44. // Helper function to call the factory with settings specific to the
  45. // factory implementation
  46. Status NewTableReader(const ImmutableCFOptions& ioptions,
  47. const EnvOptions& soptions,
  48. const InternalKeyComparator& internal_comparator,
  49. uint64_t file_size,
  50. std::unique_ptr<TableReader>* table_reader);
  51. std::string file_name_;
  52. uint64_t read_num_;
  53. bool verify_checksum_;
  54. bool output_hex_;
  55. bool decode_blob_index_;
  56. EnvOptions soptions_;
  57. // options_ and internal_comparator_ will also be used in
  58. // ReadSequential internally (specifically, seek-related operations)
  59. Options options_;
  60. Status init_result_;
  61. std::unique_ptr<TableReader> table_reader_;
  62. std::unique_ptr<RandomAccessFileReader> file_;
  63. const ImmutableCFOptions ioptions_;
  64. const MutableCFOptions moptions_;
  65. InternalKeyComparator internal_comparator_;
  66. std::unique_ptr<TableProperties> table_properties_;
  67. };
  68. } // namespace ROCKSDB_NAMESPACE
  69. #endif // ROCKSDB_LITE