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