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); GetReadNumber()31 uint64_t GetReadNumber() { return read_num_; } GetInitTableProperties()32 TableProperties* GetInitTableProperties() { return table_properties_.get(); } 33 34 Status VerifyChecksum(); 35 Status DumpTable(const std::string& out_filename); getStatus()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 uint64_t max_dict_buffer_bytes); 45 46 Status ShowCompressionSize(size_t block_size, CompressionType compress_type, 47 const CompressionOptions& compress_opt); 48 49 private: 50 // Get the TableReader implementation for the sst file 51 Status GetTableReader(const std::string& file_path); 52 Status ReadTableProperties(uint64_t table_magic_number, 53 RandomAccessFileReader* file, uint64_t file_size, 54 FilePrefetchBuffer* prefetch_buffer); 55 56 Status CalculateCompressedTableSize(const TableBuilderOptions& tb_options, 57 size_t block_size, 58 uint64_t* num_data_blocks, 59 uint64_t* compressed_table_size); 60 61 Status SetTableOptionsByMagicNumber(uint64_t table_magic_number); 62 Status SetOldTableOptions(); 63 64 // Helper function to call the factory with settings specific to the 65 // factory implementation 66 Status NewTableReader(const ImmutableOptions& ioptions, 67 const EnvOptions& soptions, 68 const InternalKeyComparator& internal_comparator, 69 uint64_t file_size, 70 std::unique_ptr<TableReader>* table_reader); 71 72 std::string file_name_; 73 uint64_t read_num_; 74 bool output_hex_; 75 bool decode_blob_index_; 76 EnvOptions soptions_; 77 // less verbose in stdout/stderr 78 bool silent_; 79 80 // options_ and internal_comparator_ will also be used in 81 // ReadSequential internally (specifically, seek-related operations) 82 Options options_; 83 84 Status init_result_; 85 std::unique_ptr<TableReader> table_reader_; 86 std::unique_ptr<RandomAccessFileReader> file_; 87 88 const ImmutableOptions ioptions_; 89 const MutableCFOptions moptions_; 90 ReadOptions read_options_; 91 InternalKeyComparator internal_comparator_; 92 std::unique_ptr<TableProperties> table_properties_; 93 }; 94 95 } // namespace ROCKSDB_NAMESPACE 96 97 #endif // ROCKSDB_LITE 98