blob_dump_tool.h 1.7 KB

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