mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-29 18:33:58 +00:00
fdf882ded2
Summary: When dynamically linking two binaries together, different builds of RocksDB from two sources might cause errors. To provide a tool for user to solve the problem, the RocksDB namespace is changed to a flag which can be overridden in build time. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6433 Test Plan: Build release, all and jtest. Try to build with ROCKSDB_NAMESPACE with another flag. Differential Revision: D19977691 fbshipit-source-id: aa7f2d0972e1c31d75339ac48478f34f6cfcfb3e
124 lines
3.7 KiB
C++
124 lines
3.7 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// 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).
|
|
|
|
#include "db/db_info_dumper.h"
|
|
|
|
#include <stdio.h>
|
|
#include <algorithm>
|
|
#include <cinttypes>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "file/filename.h"
|
|
#include "rocksdb/env.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
void DumpDBFileSummary(const ImmutableDBOptions& options,
|
|
const std::string& dbname) {
|
|
if (options.info_log == nullptr) {
|
|
return;
|
|
}
|
|
|
|
auto* env = options.env;
|
|
uint64_t number = 0;
|
|
FileType type = kInfoLogFile;
|
|
|
|
std::vector<std::string> files;
|
|
uint64_t file_num = 0;
|
|
uint64_t file_size;
|
|
std::string file_info, wal_info;
|
|
|
|
Header(options.info_log, "DB SUMMARY\n");
|
|
// Get files in dbname dir
|
|
if (!env->GetChildren(dbname, &files).ok()) {
|
|
Error(options.info_log,
|
|
"Error when reading %s dir\n", dbname.c_str());
|
|
}
|
|
std::sort(files.begin(), files.end());
|
|
for (const std::string& file : files) {
|
|
if (!ParseFileName(file, &number, &type)) {
|
|
continue;
|
|
}
|
|
switch (type) {
|
|
case kCurrentFile:
|
|
Header(options.info_log, "CURRENT file: %s\n", file.c_str());
|
|
break;
|
|
case kIdentityFile:
|
|
Header(options.info_log, "IDENTITY file: %s\n", file.c_str());
|
|
break;
|
|
case kDescriptorFile:
|
|
env->GetFileSize(dbname + "/" + file, &file_size);
|
|
Header(options.info_log, "MANIFEST file: %s size: %" PRIu64 " Bytes\n",
|
|
file.c_str(), file_size);
|
|
break;
|
|
case kLogFile:
|
|
env->GetFileSize(dbname + "/" + file, &file_size);
|
|
char str[16];
|
|
snprintf(str, sizeof(str), "%" PRIu64, file_size);
|
|
wal_info.append(file).append(" size: ").
|
|
append(str).append(" ; ");
|
|
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()) {
|
|
Error(options.info_log,
|
|
"Error when reading %s dir\n",
|
|
db_path.path.c_str());
|
|
continue;
|
|
}
|
|
std::sort(files.begin(), files.end());
|
|
for (const std::string& file : files) {
|
|
if (ParseFileName(file, &number, &type)) {
|
|
if (type == kTableFile && ++file_num < 10) {
|
|
file_info.append(file).append(" ");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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());
|
|
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()) {
|
|
Error(options.info_log,
|
|
"Error when reading %s dir\n",
|
|
options.wal_dir.c_str());
|
|
return;
|
|
}
|
|
wal_info.clear();
|
|
for (const std::string& file : files) {
|
|
if (ParseFileName(file, &number, &type)) {
|
|
if (type == kLogFile) {
|
|
env->GetFileSize(options.wal_dir + "/" + file, &file_size);
|
|
char str[16];
|
|
snprintf(str, sizeof(str), "%" PRIu64, file_size);
|
|
wal_info.append(file).append(" size: ").
|
|
append(str).append(" ; ");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Header(options.info_log, "Write Ahead Log file in %s: %s\n",
|
|
options.wal_dir.c_str(), wal_info.c_str());
|
|
}
|
|
} // namespace ROCKSDB_NAMESPACE
|