]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae | 5 | |
7c673cae FG |
6 | #include "db/db_info_dumper.h" |
7 | ||
7c673cae | 8 | #include <stdio.h> |
1e59de90 | 9 | |
7c673cae | 10 | #include <algorithm> |
f67539c2 TL |
11 | #include <cinttypes> |
12 | #include <string> | |
7c673cae FG |
13 | #include <vector> |
14 | ||
f67539c2 | 15 | #include "file/filename.h" |
7c673cae | 16 | #include "rocksdb/env.h" |
7c673cae | 17 | |
f67539c2 | 18 | namespace ROCKSDB_NAMESPACE { |
7c673cae FG |
19 | |
20 | void DumpDBFileSummary(const ImmutableDBOptions& options, | |
20effc67 TL |
21 | const std::string& dbname, |
22 | const std::string& session_id) { | |
7c673cae FG |
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"); | |
20effc67 TL |
37 | Header(options.info_log, "DB Session ID: %s\n", session_id.c_str()); |
38 | ||
1e59de90 | 39 | Status s; |
7c673cae | 40 | // Get files in dbname dir |
1e59de90 TL |
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()); | |
7c673cae FG |
45 | } |
46 | std::sort(files.begin(), files.end()); | |
494da23a | 47 | for (const std::string& file : files) { |
7c673cae FG |
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: | |
1e59de90 TL |
59 | s = env->GetFileSize(dbname + "/" + file, &file_size); |
60 | if (s.ok()) { | |
20effc67 TL |
61 | Header(options.info_log, |
62 | "MANIFEST file: %s size: %" PRIu64 " Bytes\n", file.c_str(), | |
63 | file_size); | |
64 | } else { | |
1e59de90 TL |
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()); | |
20effc67 | 68 | } |
7c673cae | 69 | break; |
20effc67 | 70 | case kWalFile: |
1e59de90 TL |
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(" ; "); | |
20effc67 | 77 | } else { |
1e59de90 TL |
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()); | |
20effc67 | 80 | } |
7c673cae FG |
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) { | |
1e59de90 TL |
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()); | |
7c673cae FG |
99 | continue; |
100 | } | |
101 | std::sort(files.begin(), files.end()); | |
494da23a | 102 | for (const std::string& file : files) { |
7c673cae FG |
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 | |
1e59de90 TL |
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()); | |
7c673cae FG |
124 | return; |
125 | } | |
126 | wal_info.clear(); | |
494da23a | 127 | for (const std::string& file : files) { |
7c673cae | 128 | if (ParseFileName(file, &number, &type)) { |
20effc67 | 129 | if (type == kWalFile) { |
1e59de90 TL |
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(" ; "); | |
20effc67 | 136 | } else { |
1e59de90 TL |
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()); | |
20effc67 | 139 | } |
7c673cae FG |
140 | } |
141 | } | |
142 | } | |
143 | } | |
1e59de90 TL |
144 | Header(options.info_log, "Write Ahead Log file in %s: %s\n", wal_dir.c_str(), |
145 | wal_info.c_str()); | |
7c673cae | 146 | } |
f67539c2 | 147 | } // namespace ROCKSDB_NAMESPACE |