2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// 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).
|
2014-08-13 20:45:13 +00:00
|
|
|
|
2016-01-26 01:49:58 +00:00
|
|
|
#include "db/db_info_dumper.h"
|
|
|
|
|
2014-08-13 20:45:13 +00:00
|
|
|
#include <algorithm>
|
2019-09-20 19:00:55 +00:00
|
|
|
#include <cinttypes>
|
2024-01-05 19:53:57 +00:00
|
|
|
#include <cstdio>
|
2019-09-20 19:00:55 +00:00
|
|
|
#include <string>
|
2014-08-13 20:45:13 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2019-05-30 03:44:08 +00:00
|
|
|
#include "file/filename.h"
|
2014-08-13 20:45:13 +00:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2014-08-13 20:45:13 +00:00
|
|
|
|
2016-09-23 23:34:04 +00:00
|
|
|
void DumpDBFileSummary(const ImmutableDBOptions& options,
|
2020-06-15 17:45:03 +00:00
|
|
|
const std::string& dbname,
|
|
|
|
const std::string& session_id) {
|
2014-08-13 20:45:13 +00:00
|
|
|
if (options.info_log == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* env = options.env;
|
2014-08-14 00:53:43 +00:00
|
|
|
uint64_t number = 0;
|
|
|
|
FileType type = kInfoLogFile;
|
2014-08-13 20:45:13 +00:00
|
|
|
|
|
|
|
std::vector<std::string> files;
|
|
|
|
uint64_t file_num = 0;
|
|
|
|
uint64_t file_size;
|
|
|
|
std::string file_info, wal_info;
|
|
|
|
|
2015-09-16 18:31:45 +00:00
|
|
|
Header(options.info_log, "DB SUMMARY\n");
|
2023-08-31 15:39:09 +00:00
|
|
|
{
|
|
|
|
std::string hostname;
|
|
|
|
if (env->GetHostNameString(&hostname).ok()) {
|
|
|
|
Header(options.info_log, "Host name (Env): %s\n", hostname.c_str());
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 17:45:03 +00:00
|
|
|
Header(options.info_log, "DB Session ID: %s\n", session_id.c_str());
|
|
|
|
|
2022-05-04 17:19:53 +00:00
|
|
|
Status s;
|
2014-08-13 20:45:13 +00:00
|
|
|
// Get files in dbname dir
|
2022-05-04 17:19:53 +00:00
|
|
|
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());
|
2014-08-13 20:45:13 +00:00
|
|
|
}
|
|
|
|
std::sort(files.begin(), files.end());
|
2018-10-10 00:13:53 +00:00
|
|
|
for (const std::string& file : files) {
|
2014-08-14 00:53:43 +00:00
|
|
|
if (!ParseFileName(file, &number, &type)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-13 20:45:13 +00:00
|
|
|
switch (type) {
|
|
|
|
case kCurrentFile:
|
2015-09-16 18:31:45 +00:00
|
|
|
Header(options.info_log, "CURRENT file: %s\n", file.c_str());
|
2014-08-13 20:45:13 +00:00
|
|
|
break;
|
|
|
|
case kIdentityFile:
|
2015-09-16 18:31:45 +00:00
|
|
|
Header(options.info_log, "IDENTITY file: %s\n", file.c_str());
|
2014-08-13 20:45:13 +00:00
|
|
|
break;
|
|
|
|
case kDescriptorFile:
|
2022-05-04 17:19:53 +00:00
|
|
|
s = env->GetFileSize(dbname + "/" + file, &file_size);
|
|
|
|
if (s.ok()) {
|
2020-08-24 23:41:42 +00:00
|
|
|
Header(options.info_log,
|
|
|
|
"MANIFEST file: %s size: %" PRIu64 " Bytes\n", file.c_str(),
|
|
|
|
file_size);
|
|
|
|
} else {
|
2022-05-04 17:19:53 +00:00
|
|
|
Error(options.info_log,
|
|
|
|
"Error when reading MANIFEST file: %s/%s %s\n", dbname.c_str(),
|
|
|
|
file.c_str(), s.ToString().c_str());
|
2020-08-24 23:41:42 +00:00
|
|
|
}
|
2014-08-13 20:45:13 +00:00
|
|
|
break;
|
2020-10-23 00:04:39 +00:00
|
|
|
case kWalFile:
|
2022-05-04 17:19:53 +00:00
|
|
|
s = env->GetFileSize(dbname + "/" + file, &file_size);
|
|
|
|
if (s.ok()) {
|
2021-01-19 21:46:03 +00:00
|
|
|
wal_info.append(file)
|
|
|
|
.append(" size: ")
|
|
|
|
.append(std::to_string(file_size))
|
|
|
|
.append(" ; ");
|
2020-08-24 23:41:42 +00:00
|
|
|
} else {
|
2022-05-04 17:19:53 +00:00
|
|
|
Error(options.info_log, "Error when reading LOG file: %s/%s %s\n",
|
|
|
|
dbname.c_str(), file.c_str(), s.ToString().c_str());
|
2020-08-24 23:41:42 +00:00
|
|
|
}
|
2014-08-13 20:45:13 +00:00
|
|
|
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) {
|
2022-05-04 17:19:53 +00:00
|
|
|
s = env->GetChildren(db_path.path, &files);
|
2024-02-05 18:26:41 +00:00
|
|
|
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()) {
|
2022-05-04 17:19:53 +00:00
|
|
|
Error(options.info_log, "Error when reading %s dir %s\n",
|
|
|
|
db_path.path.c_str(), s.ToString().c_str());
|
2014-08-13 20:45:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::sort(files.begin(), files.end());
|
2018-10-10 00:13:53 +00:00
|
|
|
for (const std::string& file : files) {
|
2014-08-14 00:53:43 +00:00
|
|
|
if (ParseFileName(file, &number, &type)) {
|
|
|
|
if (type == kTableFile && ++file_num < 10) {
|
|
|
|
file_info.append(file).append(" ");
|
|
|
|
}
|
2014-08-13 20:45:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-16 18:31:45 +00:00
|
|
|
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());
|
2014-08-13 20:45:13 +00:00
|
|
|
file_num = 0;
|
|
|
|
file_info.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get wal file in wal_dir
|
2021-07-30 19:15:04 +00:00
|
|
|
const auto& wal_dir = options.GetWalDir(dbname);
|
2024-02-05 18:26:41 +00:00
|
|
|
bool log_wal_info = true;
|
2021-07-30 19:15:04 +00:00
|
|
|
if (!options.IsWalDirSameAsDBPath(dbname)) {
|
2022-05-04 17:19:53 +00:00
|
|
|
s = env->GetChildren(wal_dir, &files);
|
2024-02-05 18:26:41 +00:00
|
|
|
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;
|
2014-08-13 20:45:13 +00:00
|
|
|
}
|
|
|
|
wal_info.clear();
|
2018-10-10 00:13:53 +00:00
|
|
|
for (const std::string& file : files) {
|
2014-08-14 00:53:43 +00:00
|
|
|
if (ParseFileName(file, &number, &type)) {
|
2020-10-23 00:04:39 +00:00
|
|
|
if (type == kWalFile) {
|
2022-05-04 17:19:53 +00:00
|
|
|
s = env->GetFileSize(wal_dir + "/" + file, &file_size);
|
|
|
|
if (s.ok()) {
|
2021-01-19 21:46:03 +00:00
|
|
|
wal_info.append(file)
|
|
|
|
.append(" size: ")
|
|
|
|
.append(std::to_string(file_size))
|
|
|
|
.append(" ; ");
|
2020-08-24 23:41:42 +00:00
|
|
|
} else {
|
2022-05-04 17:19:53 +00:00
|
|
|
Error(options.info_log, "Error when reading LOG file %s/%s %s\n",
|
|
|
|
wal_dir.c_str(), file.c_str(), s.ToString().c_str());
|
2020-08-24 23:41:42 +00:00
|
|
|
}
|
2014-08-14 00:53:43 +00:00
|
|
|
}
|
2014-08-13 20:45:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 18:26:41 +00:00
|
|
|
if (log_wal_info) {
|
|
|
|
Header(options.info_log, "Write Ahead Log file in %s: %s\n",
|
|
|
|
wal_dir.c_str(), wal_info.c_str());
|
|
|
|
}
|
2014-08-13 20:45:13 +00:00
|
|
|
}
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|