/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/db_info_dumper.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | |
21 | | #ifndef __STDC_FORMAT_MACROS |
22 | | #define __STDC_FORMAT_MACROS |
23 | | #endif |
24 | | |
25 | | #include "yb/rocksdb/db/db_info_dumper.h" |
26 | | |
27 | | #include <inttypes.h> |
28 | | #include <stdio.h> |
29 | | #include <string> |
30 | | #include <algorithm> |
31 | | #include <vector> |
32 | | |
33 | | #include "yb/rocksdb/db/filename.h" |
34 | | #include "yb/rocksdb/options.h" |
35 | | #include "yb/rocksdb/env.h" |
36 | | |
37 | | namespace rocksdb { |
38 | | |
39 | | void HandleLogFile(const DBOptions& options, const std::string& path, const std::string& file, |
40 | 0 | std::string* wal_info) { |
41 | 0 | uint64_t file_size; |
42 | 0 | auto status = options.env->GetFileSize(path + "/" + file, &file_size); |
43 | 0 | if (status.ok()) { |
44 | 0 | char str[16]; |
45 | 0 | snprintf(str, sizeof(str), "%" PRIu64, file_size); |
46 | 0 | wal_info->append(file).append(" size: ").append(str).append(" ; "); |
47 | 0 | } else { |
48 | 0 | RHEADER(options.info_log, "Failed to get log file size %s: %s\n", |
49 | 0 | file.c_str(), status.ToString().c_str()); |
50 | 0 | } |
51 | 0 | } |
52 | | |
53 | 0 | void DumpDBFileSummary(const DBOptions& options, const std::string& dbname) { |
54 | 0 | if (options.info_log == nullptr) { |
55 | 0 | return; |
56 | 0 | } |
57 | | |
58 | 0 | auto* env = options.env; |
59 | 0 | uint64_t number = 0; |
60 | 0 | FileType type = kInfoLogFile; |
61 | |
|
62 | 0 | std::vector<std::string> files; |
63 | 0 | uint64_t file_num = 0; |
64 | 0 | uint64_t file_size; |
65 | 0 | std::string file_info, wal_info; |
66 | |
|
67 | 0 | RHEADER(options.info_log, "DB SUMMARY\n"); |
68 | | // Get files in dbname dir |
69 | 0 | if (!env->GetChildren(dbname, &files).ok()) { |
70 | 0 | RERROR(options.info_log, |
71 | 0 | "Error when reading %s dir\n", dbname.c_str()); |
72 | 0 | } |
73 | 0 | std::sort(files.begin(), files.end()); |
74 | 0 | for (std::string file : files) { |
75 | 0 | if (!ParseFileName(file, &number, &type)) { |
76 | 0 | continue; |
77 | 0 | } |
78 | 0 | switch (type) { |
79 | 0 | case kCurrentFile: |
80 | 0 | RHEADER(options.info_log, "CURRENT file: %s\n", file.c_str()); |
81 | 0 | break; |
82 | 0 | case kIdentityFile: |
83 | 0 | RHEADER(options.info_log, "IDENTITY file: %s\n", file.c_str()); |
84 | 0 | break; |
85 | 0 | case kDescriptorFile: { |
86 | 0 | auto status = env->GetFileSize(dbname + "/" + file, &file_size); |
87 | 0 | if (status.ok()) { |
88 | 0 | RHEADER(options.info_log, "MANIFEST file: %s size: %" PRIu64 " Bytes\n", |
89 | 0 | file.c_str(), file_size); |
90 | 0 | } else { |
91 | 0 | RHEADER(options.info_log, "Failed to get MANIFEST file size %s: %s\n", |
92 | 0 | file.c_str(), status.ToString().c_str()); |
93 | 0 | } |
94 | 0 | } break; |
95 | 0 | case kLogFile: |
96 | 0 | HandleLogFile(options, dbname, file, &wal_info); |
97 | 0 | break; |
98 | 0 | case kTableFile: |
99 | 0 | if (++file_num < 10) { |
100 | 0 | file_info.append(file).append(" "); |
101 | 0 | } |
102 | 0 | break; |
103 | 0 | default: |
104 | 0 | break; |
105 | 0 | } |
106 | 0 | } |
107 | | |
108 | | // Get sst files in db_path dir |
109 | 0 | for (auto& db_path : options.db_paths) { |
110 | 0 | if (dbname.compare(db_path.path) != 0) { |
111 | 0 | if (!env->GetChildren(db_path.path, &files).ok()) { |
112 | 0 | RERROR(options.info_log, |
113 | 0 | "Error when reading %s dir\n", |
114 | 0 | db_path.path.c_str()); |
115 | 0 | continue; |
116 | 0 | } |
117 | 0 | std::sort(files.begin(), files.end()); |
118 | 0 | for (std::string file : files) { |
119 | 0 | if (ParseFileName(file, &number, &type)) { |
120 | 0 | if (type == kTableFile && ++file_num < 10) { |
121 | 0 | file_info.append(file).append(" "); |
122 | 0 | } |
123 | 0 | } |
124 | 0 | } |
125 | 0 | } |
126 | 0 | RHEADER(options.info_log, |
127 | 0 | "SST files in %s dir, Total Num: %" PRIu64 ", files: %s\n", |
128 | 0 | db_path.path.c_str(), file_num, file_info.c_str()); |
129 | 0 | file_num = 0; |
130 | 0 | file_info.clear(); |
131 | 0 | } |
132 | | |
133 | | // Get wal file in wal_dir |
134 | 0 | if (dbname.compare(options.wal_dir) != 0) { |
135 | 0 | if (!env->GetChildren(options.wal_dir, &files).ok()) { |
136 | 0 | RERROR(options.info_log, |
137 | 0 | "Error when reading %s dir\n", |
138 | 0 | options.wal_dir.c_str()); |
139 | 0 | return; |
140 | 0 | } |
141 | 0 | wal_info.clear(); |
142 | 0 | for (std::string file : files) { |
143 | 0 | if (ParseFileName(file, &number, &type)) { |
144 | 0 | if (type == kLogFile) { |
145 | 0 | HandleLogFile(options, options.wal_dir, file, &wal_info); |
146 | 0 | } |
147 | 0 | } |
148 | 0 | } |
149 | 0 | } |
150 | 0 | RHEADER(options.info_log, "Write Ahead Log file in %s: %s\n", |
151 | 0 | options.wal_dir.c_str(), wal_info.c_str()); |
152 | 0 | } |
153 | | } // namespace rocksdb |