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
|
|
|
|
2014-09-05 08:14:37 +02:00
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
2014-08-14 14:01:01 +02:00
|
|
|
#define __STDC_FORMAT_MACROS
|
2014-09-05 08:14:37 +02:00
|
|
|
#endif
|
|
|
|
|
2016-01-26 02:49:58 +01:00
|
|
|
#include "db/db_info_dumper.h"
|
|
|
|
|
2014-08-14 14:01:01 +02:00
|
|
|
#include <inttypes.h>
|
2014-08-13 22:45:13 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "rocksdb/env.h"
|
2017-04-04 03:27:24 +02:00
|
|
|
#include "util/filename.h"
|
2014-08-13 22:45:13 +02:00
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
2016-09-24 01:34:04 +02:00
|
|
|
void DumpDBFileSummary(const ImmutableDBOptions& options,
|
|
|
|
const std::string& dbname) {
|
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");
|
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());
|
|
|
|
for (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:
|
|
|
|
env->GetFileSize(dbname + "/" + file, &file_size);
|
2015-09-16 20:31:45 +02:00
|
|
|
Header(options.info_log, "MANIFEST file: %s size: %" PRIu64 " Bytes\n",
|
|
|
|
file.c_str(), file_size);
|
2014-08-13 22:45:13 +02:00
|
|
|
break;
|
|
|
|
case kLogFile:
|
|
|
|
env->GetFileSize(dbname + "/" + file, &file_size);
|
2015-07-16 07:56:17 +02:00
|
|
|
char str[16];
|
2014-08-14 14:01:01 +02:00
|
|
|
snprintf(str, sizeof(str), "%" PRIu64, file_size);
|
2014-08-13 22:45:13 +02:00
|
|
|
wal_info.append(file).append(" size: ").
|
2015-07-16 06:02:03 +02:00
|
|
|
append(str).append(" ; ");
|
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());
|
|
|
|
for (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
|
|
|
|
if (dbname.compare(options.wal_dir) != 0) {
|
|
|
|
if (!env->GetChildren(options.wal_dir, &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
|
|
|
options.wal_dir.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wal_info.clear();
|
|
|
|
for (std::string file : files) {
|
2014-08-14 02:53:43 +02:00
|
|
|
if (ParseFileName(file, &number, &type)) {
|
|
|
|
if (type == kLogFile) {
|
|
|
|
env->GetFileSize(options.wal_dir + "/" + file, &file_size);
|
2015-07-16 07:56:17 +02:00
|
|
|
char str[16];
|
2014-08-14 14:01:01 +02:00
|
|
|
snprintf(str, sizeof(str), "%" PRIu64, file_size);
|
2014-08-14 02:53:43 +02:00
|
|
|
wal_info.append(file).append(" size: ").
|
2015-07-16 06:02:03 +02:00
|
|
|
append(str).append(" ; ");
|
2014-08-14 02:53:43 +02:00
|
|
|
}
|
2014-08-13 22:45:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-16 20:31:45 +02: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 22:45:13 +02:00
|
|
|
}
|
|
|
|
} // namespace rocksdb
|