Skip to content

Commit

Permalink
Stderr info logger
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ajkr committed Apr 1, 2016
1 parent b55e216 commit f2c43a4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
12 changes: 7 additions & 5 deletions tools/ldb_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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");
Expand Down
10 changes: 1 addition & 9 deletions util/options_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions util/stderr_logger.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f2c43a4

Please sign in to comment.