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>
|
|
|
|
#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());
|
|
|
|
|
2014-08-13 20:45:13 +00:00
|
|
|
// Get files in dbname dir
|
|
|
|
if (!env->GetChildren(dbname, &files).ok()) {
|
2015-05-22 18:54:59 +00:00
|
|
|
Error(options.info_log,
|
|
|
|
"Error when reading %s dir\n", dbname.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:
|
2020-08-24 23:41:42 +00: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 20:45:13 +00:00
|
|
|
break;
|
2020-10-23 00:04:39 +00:00
|
|
|
case kWalFile:
|
2020-08-24 23:41:42 +00:00
|
|
|
if (env->GetFileSize(dbname + "/" + file, &file_size).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 {
|
|
|
|
Error(options.info_log, "Error when reading LOG file: %s/%s\n",
|
|
|
|
dbname.c_str(), file.c_str());
|
|
|
|
}
|
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) {
|
|
|
|
if (!env->GetChildren(db_path.path, &files).ok()) {
|
2015-05-22 18:54:59 +00:00
|
|
|
Error(options.info_log,
|
2014-10-30 20:34:44 +00:00
|
|
|
"Error when reading %s dir\n",
|
2014-08-13 20:45:13 +00:00
|
|
|
db_path.path.c_str());
|
|
|
|
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
|
|
|
|
if (dbname.compare(options.wal_dir) != 0) {
|
|
|
|
if (!env->GetChildren(options.wal_dir, &files).ok()) {
|
2015-05-22 18:54:59 +00:00
|
|
|
Error(options.info_log,
|
2014-10-30 20:34:44 +00:00
|
|
|
"Error when reading %s dir\n",
|
2014-08-13 20:45:13 +00:00
|
|
|
options.wal_dir.c_str());
|
|
|
|
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) {
|
2020-08-24 23:41:42 +00:00
|
|
|
if (env->GetFileSize(options.wal_dir + "/" + file, &file_size).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 {
|
|
|
|
Error(options.info_log, "Error when reading LOG file %s/%s\n",
|
|
|
|
options.wal_dir.c_str(), file.c_str());
|
|
|
|
}
|
2014-08-14 00:53:43 +00:00
|
|
|
}
|
2014-08-13 20:45:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-16 18:31:45 +00:00
|
|
|
Header(options.info_log, "Write Ahead Log file in %s: %s\n",
|
|
|
|
options.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
|