Stderr info logger

Summary:
Adapted a stderr logger from the option tests. Moved it to a separate
header so we can reuse it, e.g., from ldb subcommands for faster debugging. This
is especially useful to make errors/warnings more visible when running
"ldb repair", which involves potential data loss.

Test Plan:
ran options_test and "ldb repair"

  $ ./ldb repair --db=./tmp/
  [WARN] **** Repaired rocksdb ./tmp/; recovered 1 files; 588bytes. Some data may have been lost. ****
  OK

Reviewers: IslamAbdelRahman, yhchiang, sdong

Reviewed By: sdong

Subscribers: andrewkr, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D56151
This commit is contained in:
Andrew Kryczka 2016-04-01 11:06:06 -07:00
parent b55e2165be
commit f2c43a4a27
3 changed files with 39 additions and 14 deletions

View File

@ -12,19 +12,20 @@
#include <inttypes.h>
#include "db/dbformat.h"
#include "db/db_impl.h"
#include "db/log_reader.h"
#include "db/dbformat.h"
#include "db/filename.h"
#include "db/writebuffer.h"
#include "db/log_reader.h"
#include "db/write_batch_internal.h"
#include "rocksdb/write_batch.h"
#include "db/writebuffer.h"
#include "port/dirent.h"
#include "rocksdb/cache.h"
#include "rocksdb/table_properties.h"
#include "rocksdb/write_batch.h"
#include "table/scoped_arena_iterator.h"
#include "port/dirent.h"
#include "tools/sst_dump_tool_imp.h"
#include "util/coding.h"
#include "util/stderr_logger.h"
#include "util/string_util.h"
#include "utilities/ttl/db_ttl_impl.h"
@ -2159,6 +2160,7 @@ void RepairCommand::Help(string& ret) {
void RepairCommand::DoCommand() {
Options options = PrepareOptionsForOpenDB();
options.info_log.reset(new StderrLogger(InfoLogLevel::WARN_LEVEL));
Status status = RepairDB(db_path_, options);
if (status.ok()) {
printf("OK\n");

View File

@ -24,6 +24,7 @@
#include "util/options_parser.h"
#include "util/options_sanity_check.h"
#include "util/random.h"
#include "util/stderr_logger.h"
#include "util/testharness.h"
#include "util/testutil.h"
@ -37,15 +38,6 @@ DEFINE_bool(enable_print, false, "Print options generated to console.");
namespace rocksdb {
class StderrLogger : public Logger {
public:
using Logger::Logv;
virtual void Logv(const char* format, va_list ap) override {
vprintf(format, ap);
printf("\n");
}
};
Options PrintAndGetOptions(size_t total_write_buffer_limit,
int read_amplification_threshold,
int write_amplification_threshold,

31
util/stderr_logger.h Normal file
View File

@ -0,0 +1,31 @@
// Copyright (c) 2016-present, 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.
#pragma once
#include <stdarg.h>
#include <stdio.h>
#include "rocksdb/env.h"
namespace rocksdb {
// Prints logs to stderr for faster debugging
class StderrLogger : public Logger {
public:
explicit StderrLogger(const InfoLogLevel log_level = InfoLogLevel::INFO_LEVEL)
: Logger(log_level) {}
// Brings overloaded Logv()s into scope so they're not hidden when we override
// a subset of them.
using Logger::Logv;
virtual void Logv(const char* format, va_list ap) override {
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
}
};
} // namespace rocksdb