From 935aae3bcfce94a7d1d5152dc1a9564b510fbf27 Mon Sep 17 00:00:00 2001 From: akankshamahajan Date: Mon, 24 Oct 2022 18:13:43 -0700 Subject: [PATCH] Run clang format on logging folder (#10861) Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/10861 Test Plan: CircleCI jobs Reviewed By: siying Differential Revision: D40654198 Pulled By: akankshamahajan15 fbshipit-source-id: 787be2575578b3aa3bd985509f96fdb9e02f7ad7 --- logging/auto_roll_logger.cc | 6 ++--- logging/auto_roll_logger.h | 10 +++----- logging/auto_roll_logger_test.cc | 43 +++++++++++++++----------------- logging/env_logger_test.cc | 1 + logging/event_logger.cc | 4 +-- logging/event_logger.h | 9 +++---- logging/event_logger_test.cc | 3 ++- logging/log_buffer.cc | 5 ++-- logging/log_buffer.h | 5 ++-- logging/logging.h | 6 ++--- 10 files changed, 42 insertions(+), 50 deletions(-) diff --git a/logging/auto_roll_logger.cc b/logging/auto_roll_logger.cc index 66f346518..fe0958479 100644 --- a/logging/auto_roll_logger.cc +++ b/logging/auto_roll_logger.cc @@ -90,8 +90,8 @@ void AutoRollLogger::RollLogFile() { uint64_t now = clock_->NowMicros(); std::string old_fname; do { - old_fname = OldInfoLogFileName( - dbname_, now, db_absolute_path_, db_log_dir_); + old_fname = + OldInfoLogFileName(dbname_, now, db_absolute_path_, db_log_dir_); now++; } while (fs_->FileExists(old_fname, io_options_, &io_context_).ok()); // Wait for logger_ reference count to turn to 1 as it might be pinned by @@ -173,7 +173,7 @@ std::string AutoRollLogger::ValistToString(const char* format, char buffer[MAXBUFFERSIZE]; int count = vsnprintf(buffer, MAXBUFFERSIZE, format, args); - (void) count; + (void)count; assert(count >= 0); return buffer; diff --git a/logging/auto_roll_logger.h b/logging/auto_roll_logger.h index ccbce1d99..805925e5a 100644 --- a/logging/auto_roll_logger.h +++ b/logging/auto_roll_logger.h @@ -40,9 +40,7 @@ class AutoRollLogger : public Logger { virtual void LogHeader(const char* format, va_list ap) override; // check if the logger has encountered any problem. - Status GetStatus() { - return status_; - } + Status GetStatus() { return status_; } size_t GetLogFileSize() const override { if (!logger_) { @@ -101,9 +99,7 @@ class AutoRollLogger : public Logger { } // Expose the log file path for testing purpose - std::string TEST_log_fname() const { - return log_fname_; - } + std::string TEST_log_fname() const { return log_fname_; } uint64_t TEST_ctime() const { return ctime_; } @@ -134,7 +130,7 @@ class AutoRollLogger : public Logger { std::string ValistToString(const char* format, va_list args) const; // Write the logs marked as headers to the new log file void WriteHeaderInfo(); - std::string log_fname_; // Current active info log's file name. + std::string log_fname_; // Current active info log's file name. std::string dbname_; std::string db_log_dir_; std::string db_absolute_path_; diff --git a/logging/auto_roll_logger_test.cc b/logging/auto_roll_logger_test.cc index e9578369a..8e94a78c8 100644 --- a/logging/auto_roll_logger_test.cc +++ b/logging/auto_roll_logger_test.cc @@ -64,8 +64,9 @@ class AutoRollLoggerTest : public testing::Test { ASSERT_TRUE(system(deleteDbDirCmd.c_str()) == 0); std::string testDir(kTestDir); - std::replace_if(testDir.begin(), testDir.end(), - [](char ch) { return ch == '/'; }, '\\'); + std::replace_if( + testDir.begin(), testDir.end(), [](char ch) { return ch == '/'; }, + '\\'); std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; #else std::string deleteCmd = "rm -rf " + kTestDir + " " + kTestDbDir; @@ -203,15 +204,15 @@ void AutoRollLoggerTest::RollLogFileByTimeTest( } TEST_F(AutoRollLoggerTest, RollLogFileBySize) { - InitTestDb(); - size_t log_max_size = 1024 * 5; - size_t keep_log_file_num = 10; + InitTestDb(); + size_t log_max_size = 1024 * 5; + size_t keep_log_file_num = 10; - AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), - kTestDir, "", log_max_size, 0, keep_log_file_num); + AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), kTestDir, + "", log_max_size, 0, keep_log_file_num); - RollLogFileBySizeTest(&logger, log_max_size, - kSampleMessage + ":RollLogFileBySize"); + RollLogFileBySizeTest(&logger, log_max_size, + kSampleMessage + ":RollLogFileBySize"); } TEST_F(AutoRollLoggerTest, RollLogFileByTime) { @@ -319,11 +320,10 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) { options.max_log_file_size = 1024; ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); AutoRollLogger* auto_roll_logger = - dynamic_cast(logger.get()); + dynamic_cast(logger.get()); ASSERT_TRUE(auto_roll_logger); - RollLogFileBySizeTest( - auto_roll_logger, options.max_log_file_size, - kSampleMessage + ":CreateLoggerFromOptions - size"); + RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size, + kSampleMessage + ":CreateLoggerFromOptions - size"); // Only roll by Time options.env = nse.get(); @@ -331,8 +331,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) { options.max_log_file_size = 0; options.log_file_time_to_roll = 2; ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); - auto_roll_logger = - dynamic_cast(logger.get()); + auto_roll_logger = dynamic_cast(logger.get()); RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger, options.log_file_time_to_roll, kSampleMessage + ":CreateLoggerFromOptions - time"); @@ -342,8 +341,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) { options.max_log_file_size = 1024 * 5; options.log_file_time_to_roll = 2; ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); - auto_roll_logger = - dynamic_cast(logger.get()); + auto_roll_logger = dynamic_cast(logger.get()); RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size, kSampleMessage + ":CreateLoggerFromOptions - both"); RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger, @@ -527,7 +525,7 @@ TEST_F(AutoRollLoggerTest, InfoLogLevel) { } std::ifstream inFile(AutoRollLoggerTest::kLogFile.c_str()); size_t lines = std::count(std::istreambuf_iterator(inFile), - std::istreambuf_iterator(), '\n'); + std::istreambuf_iterator(), '\n'); ASSERT_EQ(log_lines, lines); inFile.close(); } @@ -567,7 +565,7 @@ TEST_F(AutoRollLoggerTest, Close) { std::ifstream inFile(AutoRollLoggerTest::kLogFile.c_str()); size_t lines = std::count(std::istreambuf_iterator(inFile), - std::istreambuf_iterator(), '\n'); + std::istreambuf_iterator(), '\n'); ASSERT_EQ(log_lines, lines); inFile.close(); } @@ -602,7 +600,6 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) { // test_num == 0 -> standard call to Header() // test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL for (int test_num = 0; test_num < 2; test_num++) { - InitTestDb(); AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), @@ -640,7 +637,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) { const auto oldfiles = GetOldFileNames(newfname); - ASSERT_EQ(oldfiles.size(), (size_t) 2); + ASSERT_EQ(oldfiles.size(), (size_t)2); for (auto& oldfname : oldfiles) { // verify that the files rolled over @@ -658,8 +655,8 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) { // Replace all slashes in the path so windows CompSpec does not // become confused std::string testDir(kTestDir); - std::replace_if(testDir.begin(), testDir.end(), - [](char ch) { return ch == '/'; }, '\\'); + std::replace_if( + testDir.begin(), testDir.end(), [](char ch) { return ch == '/'; }, '\\'); std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; #else std::string deleteCmd = "rm -rf " + kTestDir; diff --git a/logging/env_logger_test.cc b/logging/env_logger_test.cc index 0406ac0f4..467ab064f 100644 --- a/logging/env_logger_test.cc +++ b/logging/env_logger_test.cc @@ -5,6 +5,7 @@ // #include "logging/env_logger.h" + #include "test_util/testharness.h" #include "test_util/testutil.h" diff --git a/logging/event_logger.cc b/logging/event_logger.cc index 78bf4f8ff..cb9eca687 100644 --- a/logging/event_logger.cc +++ b/logging/event_logger.cc @@ -44,9 +44,7 @@ EventLoggerStream::~EventLoggerStream() { } } -void EventLogger::Log(const JSONWriter& jwriter) { - Log(logger_, jwriter); -} +void EventLogger::Log(const JSONWriter& jwriter) { Log(logger_, jwriter); } void EventLogger::Log(Logger* logger, const JSONWriter& jwriter) { #ifdef ROCKSDB_PRINT_EVENTS_TO_STDOUT diff --git a/logging/event_logger.h b/logging/event_logger.h index 596eb0f51..9ce982f50 100644 --- a/logging/event_logger.h +++ b/logging/event_logger.h @@ -5,10 +5,10 @@ #pragma once +#include #include #include #include -#include #include "logging/log_buffer.h" #include "rocksdb/env.h" @@ -157,7 +157,8 @@ class EventLoggerStream { json_writer_ = new JSONWriter(); *this << "time_micros" << std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); + std::chrono::system_clock::now().time_since_epoch()) + .count(); } } friend class EventLogger; @@ -177,9 +178,7 @@ class EventLoggerStream { // "file_size": 1909699} class EventLogger { public: - static const char* Prefix() { - return "EVENT_LOG_v1"; - } + static const char* Prefix() { return "EVENT_LOG_v1"; } explicit EventLogger(Logger* logger) : logger_(logger) {} EventLoggerStream Log() { return EventLoggerStream(logger_); } diff --git a/logging/event_logger_test.cc b/logging/event_logger_test.cc index a48bcdc0c..582f56ceb 100644 --- a/logging/event_logger_test.cc +++ b/logging/event_logger_test.cc @@ -3,9 +3,10 @@ // COPYING file in the root directory) and Apache 2.0 License // (found in the LICENSE.Apache file in the root directory). +#include "logging/event_logger.h" + #include -#include "logging/event_logger.h" #include "test_util/testharness.h" namespace ROCKSDB_NAMESPACE { diff --git a/logging/log_buffer.cc b/logging/log_buffer.cc index 378fcbb52..2763e617f 100644 --- a/logging/log_buffer.cc +++ b/logging/log_buffer.cc @@ -5,13 +5,12 @@ #include "logging/log_buffer.h" -#include "port/sys_time.h" #include "port/port.h" +#include "port/sys_time.h" namespace ROCKSDB_NAMESPACE { -LogBuffer::LogBuffer(const InfoLogLevel log_level, - Logger*info_log) +LogBuffer::LogBuffer(const InfoLogLevel log_level, Logger* info_log) : log_level_(log_level), info_log_(info_log) {} void LogBuffer::AddLogToBuffer(size_t max_log_size, const char* format, diff --git a/logging/log_buffer.h b/logging/log_buffer.h index 61d0be7df..92d38d10d 100644 --- a/logging/log_buffer.h +++ b/logging/log_buffer.h @@ -6,6 +6,7 @@ #pragma once #include + #include "memory/arena.h" #include "port/sys_time.h" #include "rocksdb/env.h" @@ -35,8 +36,8 @@ class LogBuffer { private: // One log entry with its timestamp struct BufferedLog { - port::TimeVal now_tv; // Timestamp of the log - char message[1]; // Beginning of log message + port::TimeVal now_tv; // Timestamp of the log + char message[1]; // Beginning of log message }; const InfoLogLevel log_level_; diff --git a/logging/logging.h b/logging/logging.h index 585111569..e7f4f7776 100644 --- a/logging/logging.h +++ b/logging/logging.h @@ -15,10 +15,10 @@ // Helper macros that include information about file name and line number #define ROCKS_LOG_STRINGIFY(x) #x #define ROCKS_LOG_TOSTRING(x) ROCKS_LOG_STRINGIFY(x) -#define ROCKS_LOG_PREPEND_FILE_LINE(FMT) ("[%s:" ROCKS_LOG_TOSTRING(__LINE__) "] " FMT) +#define ROCKS_LOG_PREPEND_FILE_LINE(FMT) \ + ("[%s:" ROCKS_LOG_TOSTRING(__LINE__) "] " FMT) -inline const char* RocksLogShorterFileName(const char* file) -{ +inline const char* RocksLogShorterFileName(const char* file) { // 18 is the length of "logging/logging.h". // If the name of this file changed, please change this number, too. return file + (sizeof(__FILE__) > 18 ? sizeof(__FILE__) - 18 : 0);