mirror of
https://github.com/facebook/rocksdb.git
synced 2026-10-23 08:09:02 +03:00
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/15394 ## Summary RocksDB's `.clang-tidy` enables several readability checks that existing code still violates: `readability-isolate-declaration` (476 findings), `readability-braces-around-statements` (49), `readability-redundant-string-init` (25), `modernize-use-using` (10), `misc-definitions-in-headers` (3) and `readability-duplicate-include` (1). They keep getting flagged whenever nearby lines change. This diff fixes 553 of the 564; upstream has since fixed the other 11. What changed: - Multi-variable declarations such as `std::string a, b;` are split into one declaration per variable. Pointer and reference declarators are kept per variable. - Braces are added around single-statement `if`/`else`/`for`/`while` bodies, and empty spin loops get an empty `{}` body. - `std::string s = ""` / `member("")` initializers are removed. - Remaining `typedef`s in the touched C++ files become `using`. C headers and `extern "C"` code are untouched. - `inline` is added to non-template function definitions in test headers. - A duplicate `#include "util/udt_util.h"` in `db_impl.cc` is removed. These are clang-tidy's own fix-its, applied mechanically and then clang-formatted on the changed lines. Three kinds of broken fix-it output were repaired by hand. Removing a `member("")` initializer left a dangling comma in constructor initializer lists (`ExternalSstFileInfo`, `ColumnFamilyMetaData` and others). The function-type typedefs in `block_test.cc` came out malformed. Empty `while (cond);` spin loops got a `{;` body. Splitting declarations also exposed two vectors in `db_etc2_test.cc` to `performance-inefficient-vector-operation`, so a `reserve()` was added for each. The lint bot reports every finding in a file a diff touches. This diff splits declarations in `options/configurable_test.cc`, so it also fixes that file's 14 older `cert-err58-cpp` and `cppcoreguidelines-avoid-non-const-global-variables` findings, which come from seven mutable file-level maps. Six are now `const` and built where they are used (function-local statics, or locals in their only user). The unused `imm_struct_option_info` is deleted. Compatibility: no behavior change. In public headers, the only edits are removed redundant `""` initializers, split declarations and added braces. Reviewed By: rban1 Differential Revision: D123186310 fbshipit-source-id: f9c8e88b00e997db0196f8725c7c8d880cf798da
167 lines
5.2 KiB
C++
167 lines
5.2 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#include "db/db_info_dumper.h"
|
|
|
|
#include <algorithm>
|
|
#include <cinttypes>
|
|
#include <cstdio>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "file/filename.h"
|
|
#include "rocksdb/env.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
void DumpDBFileSummary(const ImmutableDBOptions& options,
|
|
const std::string& dbname,
|
|
const std::string& session_id) {
|
|
if (options.info_log == nullptr) {
|
|
return;
|
|
}
|
|
|
|
auto* env = options.env;
|
|
uint64_t number = 0;
|
|
FileType type = kInfoLogFile;
|
|
|
|
std::vector<std::string> files;
|
|
uint64_t file_num = 0;
|
|
uint64_t file_size;
|
|
std::string file_info;
|
|
std::string wal_info;
|
|
|
|
Header(options.info_log, "DB SUMMARY\n");
|
|
{
|
|
std::string hostname;
|
|
if (env->GetHostNameString(&hostname).ok()) {
|
|
Header(options.info_log, "Host name (Env): %s\n", hostname.c_str());
|
|
}
|
|
}
|
|
Header(options.info_log, "DB Session ID: %s\n", session_id.c_str());
|
|
|
|
Status s;
|
|
// Get files in dbname dir
|
|
s = env->GetChildren(dbname, &files);
|
|
if (!s.ok()) {
|
|
Error(options.info_log, "Error when reading %s dir %s\n", dbname.c_str(),
|
|
s.ToString().c_str());
|
|
}
|
|
std::sort(files.begin(), files.end());
|
|
for (const std::string& file : files) {
|
|
if (!ParseFileName(file, &number, &type)) {
|
|
continue;
|
|
}
|
|
switch (type) {
|
|
case kCurrentFile:
|
|
Header(options.info_log, "CURRENT file: %s\n", file.c_str());
|
|
break;
|
|
case kIdentityFile:
|
|
Header(options.info_log, "IDENTITY file: %s\n", file.c_str());
|
|
break;
|
|
case kDescriptorFile:
|
|
s = env->GetFileSize(dbname + "/" + file, &file_size);
|
|
if (s.ok()) {
|
|
Header(options.info_log,
|
|
"MANIFEST file: %s size: %" PRIu64 " Bytes\n", file.c_str(),
|
|
file_size);
|
|
} else {
|
|
Error(options.info_log,
|
|
"Error when reading MANIFEST file: %s/%s %s\n", dbname.c_str(),
|
|
file.c_str(), s.ToString().c_str());
|
|
}
|
|
break;
|
|
case kWalFile:
|
|
s = env->GetFileSize(dbname + "/" + file, &file_size);
|
|
if (s.ok()) {
|
|
wal_info.append(file)
|
|
.append(" size: ")
|
|
.append(std::to_string(file_size))
|
|
.append(" ; ");
|
|
} else {
|
|
Error(options.info_log, "Error when reading LOG file: %s/%s %s\n",
|
|
dbname.c_str(), file.c_str(), s.ToString().c_str());
|
|
}
|
|
break;
|
|
case kTableFile:
|
|
if (++file_num < 10) {
|
|
file_info.append(file).append(" ");
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Get sst files in db_path dir
|
|
for (auto& db_path : options.db_paths) {
|
|
if (dbname.compare(db_path.path) != 0) {
|
|
s = env->GetChildren(db_path.path, &files);
|
|
if (s.IsNotFound() || s.IsPathNotFound()) {
|
|
Header(options.info_log,
|
|
"Directory from db_paths/cf_paths does not yet exist: %s\n",
|
|
db_path.path.c_str());
|
|
continue;
|
|
} else if (!s.ok()) {
|
|
Error(options.info_log, "Error when reading %s dir %s\n",
|
|
db_path.path.c_str(), s.ToString().c_str());
|
|
continue;
|
|
}
|
|
std::sort(files.begin(), files.end());
|
|
for (const std::string& file : files) {
|
|
if (ParseFileName(file, &number, &type)) {
|
|
if (type == kTableFile && ++file_num < 10) {
|
|
file_info.append(file).append(" ");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Header(options.info_log,
|
|
"SST files in %s dir, Total Num: %" PRIu64 ", files: %s\n",
|
|
db_path.path.c_str(), file_num, file_info.c_str());
|
|
file_num = 0;
|
|
file_info.clear();
|
|
}
|
|
|
|
// Get wal file in wal_dir
|
|
const auto& wal_dir = options.GetWalDir(dbname);
|
|
bool log_wal_info = true;
|
|
if (!options.IsWalDirSameAsDBPath(dbname)) {
|
|
s = env->GetChildren(wal_dir, &files);
|
|
if (s.IsNotFound() || s.IsPathNotFound()) {
|
|
Header(options.info_log,
|
|
"Write Ahead Log directory does not yet exist: %s\n",
|
|
wal_dir.c_str());
|
|
log_wal_info = false;
|
|
} else if (!s.ok()) {
|
|
Error(options.info_log, "Error when reading wal dir %s: %s\n",
|
|
wal_dir.c_str(), s.ToString().c_str());
|
|
log_wal_info = false;
|
|
}
|
|
wal_info.clear();
|
|
for (const std::string& file : files) {
|
|
if (ParseFileName(file, &number, &type)) {
|
|
if (type == kWalFile) {
|
|
s = env->GetFileSize(wal_dir + "/" + file, &file_size);
|
|
if (s.ok()) {
|
|
wal_info.append(file)
|
|
.append(" size: ")
|
|
.append(std::to_string(file_size))
|
|
.append(" ; ");
|
|
} else {
|
|
Error(options.info_log, "Error when reading LOG file %s/%s %s\n",
|
|
wal_dir.c_str(), file.c_str(), s.ToString().c_str());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (log_wal_info) {
|
|
Header(options.info_log, "Write Ahead Log file in %s: %s\n",
|
|
wal_dir.c_str(), wal_info.c_str());
|
|
}
|
|
}
|
|
} // namespace ROCKSDB_NAMESPACE
|