fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
4.0 KiB
133 lines
4.0 KiB
11 years ago
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
||
|
// This source code is licensed under the BSD-style license found in the
|
||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||
|
//
|
||
|
// Must not be included from any .h files to avoid polluting the namespace
|
||
|
// with macros.
|
||
|
|
||
10 years ago
|
#ifndef __STDC_FORMAT_MACROS
|
||
11 years ago
|
#define __STDC_FORMAT_MACROS
|
||
10 years ago
|
#endif
|
||
|
|
||
11 years ago
|
#include <inttypes.h>
|
||
11 years ago
|
#include <stdio.h>
|
||
|
#include <string>
|
||
|
#include <algorithm>
|
||
|
#include <vector>
|
||
|
|
||
|
#include "rocksdb/options.h"
|
||
|
#include "rocksdb/env.h"
|
||
|
#include "db/filename.h"
|
||
|
|
||
|
namespace rocksdb {
|
||
|
|
||
|
void DumpDBFileSummary(const DBOptions& options, const std::string& dbname) {
|
||
|
if (options.info_log == nullptr) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
auto* env = options.env;
|
||
11 years ago
|
uint64_t number = 0;
|
||
|
FileType type = kInfoLogFile;
|
||
11 years ago
|
|
||
|
std::vector<std::string> files;
|
||
|
uint64_t file_num = 0;
|
||
|
uint64_t file_size;
|
||
|
std::string file_info, wal_info;
|
||
|
|
||
10 years ago
|
Log(InfoLogLevel::INFO_LEVEL, options.info_log, "DB SUMMARY\n");
|
||
11 years ago
|
// Get files in dbname dir
|
||
|
if (!env->GetChildren(dbname, &files).ok()) {
|
||
10 years ago
|
Log(InfoLogLevel::ERROR_LEVEL,
|
||
|
options.info_log, "Error when reading %s dir\n", dbname.c_str());
|
||
11 years ago
|
}
|
||
|
std::sort(files.begin(), files.end());
|
||
|
for (std::string file : files) {
|
||
11 years ago
|
if (!ParseFileName(file, &number, &type)) {
|
||
|
continue;
|
||
|
}
|
||
11 years ago
|
switch (type) {
|
||
|
case kCurrentFile:
|
||
10 years ago
|
Log(InfoLogLevel::INFO_LEVEL, options.info_log,
|
||
|
"CURRENT file: %s\n", file.c_str());
|
||
11 years ago
|
break;
|
||
|
case kIdentityFile:
|
||
10 years ago
|
Log(InfoLogLevel::INFO_LEVEL, options.info_log,
|
||
|
"IDENTITY file: %s\n", file.c_str());
|
||
11 years ago
|
break;
|
||
|
case kDescriptorFile:
|
||
|
env->GetFileSize(dbname + "/" + file, &file_size);
|
||
10 years ago
|
Log(InfoLogLevel::INFO_LEVEL, options.info_log,
|
||
|
"MANIFEST file: %s size: %" PRIu64 " Bytes\n",
|
||
11 years ago
|
file.c_str(), file_size);
|
||
|
break;
|
||
|
case kLogFile:
|
||
|
env->GetFileSize(dbname + "/" + file, &file_size);
|
||
|
char str[8];
|
||
11 years ago
|
snprintf(str, sizeof(str), "%" PRIu64, file_size);
|
||
11 years ago
|
wal_info.append(file).append(" size: ").
|
||
|
append(str, sizeof(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()) {
|
||
10 years ago
|
Log(InfoLogLevel::ERROR_LEVEL, options.info_log,
|
||
|
"Error when reading %s dir\n",
|
||
11 years ago
|
db_path.path.c_str());
|
||
|
continue;
|
||
|
}
|
||
|
std::sort(files.begin(), files.end());
|
||
|
for (std::string file : files) {
|
||
11 years ago
|
if (ParseFileName(file, &number, &type)) {
|
||
|
if (type == kTableFile && ++file_num < 10) {
|
||
|
file_info.append(file).append(" ");
|
||
|
}
|
||
11 years ago
|
}
|
||
|
}
|
||
|
}
|
||
10 years ago
|
Log(InfoLogLevel::INFO_LEVEL, options.info_log,
|
||
|
"SST files in %s dir, Total Num: %" PRIu64 ", files: %s\n",
|
||
11 years ago
|
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()) {
|
||
10 years ago
|
Log(InfoLogLevel::ERROR_LEVEL, options.info_log,
|
||
|
"Error when reading %s dir\n",
|
||
11 years ago
|
options.wal_dir.c_str());
|
||
|
return;
|
||
|
}
|
||
|
wal_info.clear();
|
||
|
for (std::string file : files) {
|
||
11 years ago
|
if (ParseFileName(file, &number, &type)) {
|
||
|
if (type == kLogFile) {
|
||
|
env->GetFileSize(options.wal_dir + "/" + file, &file_size);
|
||
|
char str[8];
|
||
11 years ago
|
snprintf(str, sizeof(str), "%" PRIu64, file_size);
|
||
11 years ago
|
wal_info.append(file).append(" size: ").
|
||
|
append(str, sizeof(str)).append(" ;");
|
||
|
}
|
||
11 years ago
|
}
|
||
|
}
|
||
|
}
|
||
10 years ago
|
Log(InfoLogLevel::INFO_LEVEL, options.info_log,
|
||
|
"Write Ahead Log file in %s: %s\n",
|
||
11 years ago
|
options.wal_dir.c_str(), wal_info.c_str());
|
||
|
}
|
||
|
} // namespace rocksdb
|