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 <stdio.h>
|
2022-11-02 21:34:24 +00:00
|
|
|
|
2014-08-13 20:45:13 +00:00
|
|
|
#include <algorithm>
|
2019-09-20 19:00:55 +00:00
|
|
|
#include <cinttypes>
|
|
|
|
#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");
|
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);
|
|
|
|
if (!s.ok()) {
|
|
|
|
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);
|
|
|
|
if (!options.IsWalDirSameAsDBPath(dbname)) {
|
2022-05-04 17:19:53 +00:00
|
|
|
s = env->GetChildren(wal_dir, &files);
|
|
|
|
if (!s.ok()) {
|
|
|
|
Error(options.info_log, "Error when reading %s dir %s\n", wal_dir.c_str(),
|
|
|
|
s.ToString().c_str());
|
2014-08-13 20:45:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-30 19:15:04 +00:00
|
|
|
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
|