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