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