blob_dump_tool.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <memory>
  8. #include <string>
  9. #include <utility>
  10. #include "file/random_access_file_reader.h"
  11. #include "rocksdb/slice.h"
  12. #include "rocksdb/status.h"
  13. #include "utilities/blob_db/blob_log_format.h"
  14. namespace ROCKSDB_NAMESPACE {
  15. namespace blob_db {
  16. class BlobDumpTool {
  17. public:
  18. enum class DisplayType {
  19. kNone,
  20. kRaw,
  21. kHex,
  22. kDetail,
  23. };
  24. BlobDumpTool();
  25. Status Run(const std::string& filename, DisplayType show_key,
  26. DisplayType show_blob, DisplayType show_uncompressed_blob,
  27. bool show_summary);
  28. private:
  29. std::unique_ptr<RandomAccessFileReader> reader_;
  30. std::unique_ptr<char[]> buffer_;
  31. size_t buffer_size_;
  32. Status Read(uint64_t offset, size_t size, Slice* result);
  33. Status DumpBlobLogHeader(uint64_t* offset, CompressionType* compression);
  34. Status DumpBlobLogFooter(uint64_t file_size, uint64_t* footer_offset);
  35. Status DumpRecord(DisplayType show_key, DisplayType show_blob,
  36. DisplayType show_uncompressed_blob, bool show_summary,
  37. CompressionType compression, uint64_t* offset,
  38. uint64_t* total_records, uint64_t* total_key_size,
  39. uint64_t* total_blob_size,
  40. uint64_t* total_uncompressed_blob_size);
  41. void DumpSlice(const Slice s, DisplayType type);
  42. template <class T>
  43. std::string GetString(std::pair<T, T> p);
  44. };
  45. } // namespace blob_db
  46. } // namespace ROCKSDB_NAMESPACE
  47. #endif // ROCKSDB_LITE