]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/tools/blob_dump.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / tools / blob_dump.cc
CommitLineData
11fdf7f2
TL
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
6#ifndef ROCKSDB_LITE
7#include <getopt.h>
8#include <cstdio>
9#include <string>
10#include <unordered_map>
11
12#include "utilities/blob_db/blob_dump_tool.h"
13
f67539c2
TL
14using namespace ROCKSDB_NAMESPACE;
15using namespace ROCKSDB_NAMESPACE::blob_db;
11fdf7f2
TL
16
17int main(int argc, char** argv) {
18 using DisplayType = BlobDumpTool::DisplayType;
19 const std::unordered_map<std::string, DisplayType> display_types = {
20 {"none", DisplayType::kNone},
21 {"raw", DisplayType::kRaw},
22 {"hex", DisplayType::kHex},
23 {"detail", DisplayType::kDetail},
24 };
25 const struct option options[] = {
26 {"help", no_argument, nullptr, 'h'},
27 {"file", required_argument, nullptr, 'f'},
28 {"show_key", optional_argument, nullptr, 'k'},
29 {"show_blob", optional_argument, nullptr, 'b'},
30 {"show_uncompressed_blob", optional_argument, nullptr, 'r'},
31 {"show_summary", optional_argument, nullptr, 's'},
32 };
33 DisplayType show_key = DisplayType::kRaw;
34 DisplayType show_blob = DisplayType::kNone;
35 DisplayType show_uncompressed_blob = DisplayType::kNone;
36 bool show_summary = false;
37 std::string file;
38 while (true) {
39 int c = getopt_long(argc, argv, "hk::b::f:", options, nullptr);
40 if (c < 0) {
41 break;
42 }
43 std::string arg_str(optarg ? optarg : "");
44 switch (c) {
45 case 'h':
46 fprintf(stdout,
47 "Usage: blob_dump --file=filename "
48 "[--show_key[=none|raw|hex|detail]] "
49 "[--show_blob[=none|raw|hex|detail]] "
50 "[--show_uncompressed_blob[=none|raw|hex|detail]] "
51 "[--show_summary]\n");
52 return 0;
53 case 'f':
54 file = optarg;
55 break;
56 case 'k':
57 if (optarg) {
58 if (display_types.count(arg_str) == 0) {
59 fprintf(stderr, "Unrecognized key display type.\n");
60 return -1;
61 }
62 show_key = display_types.at(arg_str);
63 }
64 break;
65 case 'b':
66 if (optarg) {
67 if (display_types.count(arg_str) == 0) {
68 fprintf(stderr, "Unrecognized blob display type.\n");
69 return -1;
70 }
71 show_blob = display_types.at(arg_str);
72 } else {
73 show_blob = DisplayType::kHex;
74 }
75 break;
76 case 'r':
77 if (optarg) {
78 if (display_types.count(arg_str) == 0) {
79 fprintf(stderr, "Unrecognized blob display type.\n");
80 return -1;
81 }
82 show_uncompressed_blob = display_types.at(arg_str);
83 } else {
84 show_uncompressed_blob = DisplayType::kHex;
85 }
86 break;
87 case 's':
88 show_summary = true;
89 break;
90 default:
91 fprintf(stderr, "Unrecognized option.\n");
92 return -1;
93 }
94 }
95 BlobDumpTool tool;
96 Status s =
97 tool.Run(file, show_key, show_blob, show_uncompressed_blob, show_summary);
98 if (!s.ok()) {
99 fprintf(stderr, "Failed: %s\n", s.ToString().c_str());
100 return -1;
101 }
102 return 0;
103}
104#else
105#include <stdio.h>
106int main(int /*argc*/, char** /*argv*/) {
107 fprintf(stderr, "Not supported in lite mode.\n");
108 return -1;
109}
110#endif // ROCKSDB_LITE