From c2affccc1839297b097e847cb539103e96a66e5d Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Fri, 15 Feb 2019 16:56:58 -0800 Subject: [PATCH] Header logger should call LogHeader() (#4980) Summary: The info log header feature never worked well, because log level Header was not translated to Logger::LogHeader() call. Fix it. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4980 Differential Revision: D14087283 Pulled By: siying fbshipit-source-id: 7e7d03ce35fa8d13d4ee549f46f7326f7bc0006d --- db/db_impl_open.cc | 3 ++- env/env.cc | 2 ++ java/src/test/java/org/rocksdb/InfoLogLevelTest.java | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/db/db_impl_open.cc b/db/db_impl_open.cc index e1e314098..6321b20d1 100644 --- a/db/db_impl_open.cc +++ b/db/db_impl_open.cc @@ -1316,7 +1316,8 @@ Status DBImpl::Open(const DBOptions& db_options, const std::string& dbname, #endif // !ROCKSDB_LITE if (s.ok()) { - ROCKS_LOG_INFO(impl->immutable_db_options_.info_log, "DB pointer %p", impl); + ROCKS_LOG_HEADER(impl->immutable_db_options_.info_log, "DB pointer %p", + impl); LogFlush(impl->immutable_db_options_.info_log); assert(impl->TEST_WALBufferIsEmpty()); // If the assert above fails then we need to FlushWAL before returning diff --git a/env/env.cc b/env/env.cc index a41feaf00..e98f082ff 100644 --- a/env/env.cc +++ b/env/env.cc @@ -138,6 +138,8 @@ void Logger::Logv(const InfoLogLevel log_level, const char* format, va_list ap) // are INFO level. We don't want to add extra costs to those existing // logging. Logv(format, ap); + } else if (log_level == InfoLogLevel::HEADER_LEVEL) { + LogHeader(format, ap); } else { char new_format[500]; snprintf(new_format, sizeof(new_format) - 1, "[%s] %s", diff --git a/java/src/test/java/org/rocksdb/InfoLogLevelTest.java b/java/src/test/java/org/rocksdb/InfoLogLevelTest.java index 48ecfa16a..b215dd17f 100644 --- a/java/src/test/java/org/rocksdb/InfoLogLevelTest.java +++ b/java/src/test/java/org/rocksdb/InfoLogLevelTest.java @@ -27,6 +27,7 @@ public class InfoLogLevelTest { try (final RocksDB db = RocksDB.open(dbFolder.getRoot().getAbsolutePath())) { db.put("key".getBytes(), "value".getBytes()); + db.flush(new FlushOptions().setWaitForFlush(true)); assertThat(getLogContentsWithoutHeader()).isNotEmpty(); } } @@ -93,7 +94,7 @@ public class InfoLogLevelTest { int first_non_header = lines.length; // Identify the last line of the header for (int i = lines.length - 1; i >= 0; --i) { - if (lines[i].indexOf("Options.") >= 0 && lines[i].indexOf(':') >= 0) { + if (lines[i].indexOf("DB pointer") >= 0) { first_non_header = i + 1; break; }