]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_info_dumper.cc
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / db / db_info_dumper.cc
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 __STDC_FORMAT_MACROS
7 #define __STDC_FORMAT_MACROS
8 #endif
9
10 #include "db/db_info_dumper.h"
11
12 #include <inttypes.h>
13 #include <stdio.h>
14 #include <string>
15 #include <algorithm>
16 #include <vector>
17
18 #include "rocksdb/env.h"
19 #include "util/filename.h"
20
21 namespace rocksdb {
22
23 void DumpDBFileSummary(const ImmutableDBOptions& options,
24 const std::string& dbname) {
25 if (options.info_log == nullptr) {
26 return;
27 }
28
29 auto* env = options.env;
30 uint64_t number = 0;
31 FileType type = kInfoLogFile;
32
33 std::vector<std::string> files;
34 uint64_t file_num = 0;
35 uint64_t file_size;
36 std::string file_info, wal_info;
37
38 Header(options.info_log, "DB SUMMARY\n");
39 // Get files in dbname dir
40 if (!env->GetChildren(dbname, &files).ok()) {
41 Error(options.info_log,
42 "Error when reading %s dir\n", dbname.c_str());
43 }
44 std::sort(files.begin(), files.end());
45 for (const std::string& file : files) {
46 if (!ParseFileName(file, &number, &type)) {
47 continue;
48 }
49 switch (type) {
50 case kCurrentFile:
51 Header(options.info_log, "CURRENT file: %s\n", file.c_str());
52 break;
53 case kIdentityFile:
54 Header(options.info_log, "IDENTITY file: %s\n", file.c_str());
55 break;
56 case kDescriptorFile:
57 env->GetFileSize(dbname + "/" + file, &file_size);
58 Header(options.info_log, "MANIFEST file: %s size: %" PRIu64 " Bytes\n",
59 file.c_str(), file_size);
60 break;
61 case kLogFile:
62 env->GetFileSize(dbname + "/" + file, &file_size);
63 char str[16];
64 snprintf(str, sizeof(str), "%" PRIu64, file_size);
65 wal_info.append(file).append(" size: ").
66 append(str).append(" ; ");
67 break;
68 case kTableFile:
69 if (++file_num < 10) {
70 file_info.append(file).append(" ");
71 }
72 break;
73 default:
74 break;
75 }
76 }
77
78 // Get sst files in db_path dir
79 for (auto& db_path : options.db_paths) {
80 if (dbname.compare(db_path.path) != 0) {
81 if (!env->GetChildren(db_path.path, &files).ok()) {
82 Error(options.info_log,
83 "Error when reading %s dir\n",
84 db_path.path.c_str());
85 continue;
86 }
87 std::sort(files.begin(), files.end());
88 for (const std::string& file : files) {
89 if (ParseFileName(file, &number, &type)) {
90 if (type == kTableFile && ++file_num < 10) {
91 file_info.append(file).append(" ");
92 }
93 }
94 }
95 }
96 Header(options.info_log,
97 "SST files in %s dir, Total Num: %" PRIu64 ", files: %s\n",
98 db_path.path.c_str(), file_num, file_info.c_str());
99 file_num = 0;
100 file_info.clear();
101 }
102
103 // Get wal file in wal_dir
104 if (dbname.compare(options.wal_dir) != 0) {
105 if (!env->GetChildren(options.wal_dir, &files).ok()) {
106 Error(options.info_log,
107 "Error when reading %s dir\n",
108 options.wal_dir.c_str());
109 return;
110 }
111 wal_info.clear();
112 for (const std::string& file : files) {
113 if (ParseFileName(file, &number, &type)) {
114 if (type == kLogFile) {
115 env->GetFileSize(options.wal_dir + "/" + file, &file_size);
116 char str[16];
117 snprintf(str, sizeof(str), "%" PRIu64, file_size);
118 wal_info.append(file).append(" size: ").
119 append(str).append(" ; ");
120 }
121 }
122 }
123 }
124 Header(options.info_log, "Write Ahead Log file in %s: %s\n",
125 options.wal_dir.c_str(), wal_info.c_str());
126 }
127 } // namespace rocksdb