1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-03 16:22:35 +03:00

Debug log level implementation

Debug log will now filter output based on debug level that is enabled.
This commit is contained in:
mkaruza
2019-02-12 10:44:26 +01:00
committed by Teemu Ollakka
parent 510c7f767f
commit be98517cb3
9 changed files with 131 additions and 74 deletions

View File

@ -27,6 +27,9 @@ option(WSREP_LIB_WITH_COVERAGE "Compile with coverage instrumentation" OFF)
option(WSREP_LIB_STRICT_BUILD_FLAGS "Compile with strict build flags" OFF) option(WSREP_LIB_STRICT_BUILD_FLAGS "Compile with strict build flags" OFF)
option(WSREP_LIB_MAINTAINER_MODE "Fail compilation on any warnings" OFF) option(WSREP_LIB_MAINTAINER_MODE "Fail compilation on any warnings" OFF)
# Compiler options
set(CMAKE_CXX_STANDARD 11)
# CXX flags # CXX flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Woverloaded-virtual -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Woverloaded-virtual -g")

View File

@ -674,7 +674,7 @@ namespace wsrep
int debug_log_level() const int debug_log_level() const
{ {
return std::max(debug_log_level_, return std::max(debug_log_level_,
server_state_.debug_log_level()); wsrep::log::debug_log_level());
} }
// //

View File

@ -25,6 +25,12 @@
#include <iosfwd> #include <iosfwd>
#include <sstream> #include <sstream>
#include <atomic>
#define WSREP_LOG_DEBUG(debug_level_fn, debug_level, msg) \
do { \
if (debug_level_fn >= debug_level) wsrep::log_debug() << msg; \
} while (0)
namespace wsrep namespace wsrep
{ {
@ -39,6 +45,14 @@ namespace wsrep
error error
}; };
enum debug_level
{
debug_level_server_state = 1,
debug_level_transaction,
debug_level_streaming,
debug_level_client_state
};
/** /**
* Signature for user defined logger callback function. * Signature for user defined logger callback function.
*/ */
@ -85,6 +99,17 @@ namespace wsrep
* Set user defined logger callback function. * Set user defined logger callback function.
*/ */
static void logger_fn(logger_fn_type); static void logger_fn(logger_fn_type);
/**
* Set debug log level from client
*/
static void debug_log_level(int debug_level);
/**
* Get current debug log level
*/
static int debug_log_level();
private: private:
log(const log&); log(const log&);
log& operator=(const log&); log& operator=(const log&);
@ -94,6 +119,7 @@ namespace wsrep
static wsrep::mutex& mutex_; static wsrep::mutex& mutex_;
static std::ostream& os_; static std::ostream& os_;
static logger_fn_type logger_fn_; static logger_fn_type logger_fn_;
static std::atomic_int debug_log_level_;
}; };
class log_error : public log class log_error : public log

View File

@ -87,6 +87,7 @@
#include "id.hpp" #include "id.hpp"
#include "view.hpp" #include "view.hpp"
#include "transaction_id.hpp" #include "transaction_id.hpp"
#include "logger.hpp"
#include "provider.hpp" #include "provider.hpp"
#include "compiler.hpp" #include "compiler.hpp"
@ -542,17 +543,10 @@ namespace wsrep
* - 0 - No debug logging. * - 0 - No debug logging.
* - 1..n - Debug logging with increasing verbosity. * - 1..n - Debug logging with increasing verbosity.
*/ */
void debug_log_level(int level) { debug_log_level_ = level; } void debug_log_level(int level)
{
/** wsrep::log::debug_log_level(level);
* }
*/
int debug_log_level() const { return debug_log_level_; }
/**
* @todo Set filter for debug logging.
*/
void debug_log_filter(const std::string&);
wsrep::mutex& mutex() { return mutex_; } wsrep::mutex& mutex() { return mutex_; }
@ -611,7 +605,6 @@ namespace wsrep
, connected_gtid_() , connected_gtid_()
, current_view_() , current_view_()
, last_committed_gtid_() , last_committed_gtid_()
, debug_log_level_(0)
{ } { }
private: private:
@ -701,7 +694,6 @@ namespace wsrep
wsrep::gtid connected_gtid_; wsrep::gtid connected_gtid_;
wsrep::view current_view_; wsrep::view current_view_;
wsrep::gtid last_committed_gtid_; wsrep::gtid last_committed_gtid_;
int debug_log_level_;
}; };

View File

@ -62,12 +62,16 @@ namespace wsrep
{ {
if (fragment_size) if (fragment_size)
{ {
wsrep::log_debug() << "Enabling streaming: " WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
<< fragment_unit << " " << fragment_size; wsrep::log::debug_level_streaming,
"Enabling streaming: "
<< fragment_unit << " " << fragment_size);
} }
else else
{ {
wsrep::log_debug() << "Disabling streaming"; WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
wsrep::log::debug_level_streaming,
"Disabling streaming");
} }
fragment_unit_ = fragment_unit; fragment_unit_ = fragment_unit;
fragment_size_ = fragment_size; fragment_size_ = fragment_size;
@ -76,8 +80,10 @@ namespace wsrep
void enable(enum fragment_unit fragment_unit, size_t fragment_size) void enable(enum fragment_unit fragment_unit, size_t fragment_size)
{ {
wsrep::log_debug() << "Enabling streaming: " WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
<< fragment_unit << " " << fragment_size; wsrep::log::debug_level_streaming,
"Enabling streaming: "
<< fragment_unit << " " << fragment_size);
assert(fragment_size > 0); assert(fragment_size > 0);
fragment_unit_ = fragment_unit; fragment_unit_ = fragment_unit;
fragment_size_ = fragment_size; fragment_size_ = fragment_size;
@ -89,7 +95,9 @@ namespace wsrep
void disable() void disable()
{ {
wsrep::log_debug() << "Disabling streaming"; WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
wsrep::log::debug_level_streaming,
"Disabling streaming");
fragment_size_ = 0; fragment_size_ = 0;
} }

View File

@ -454,15 +454,15 @@ void wsrep::client_state::update_last_written_gtid(const wsrep::gtid& gtid)
void wsrep::client_state::debug_log_state(const char* context) const void wsrep::client_state::debug_log_state(const char* context) const
{ {
if (debug_log_level() >= 1) WSREP_LOG_DEBUG(debug_log_level(),
{ wsrep::log::debug_level_client_state,
wsrep::log_debug() << context context
<< "(" << id_.get() << "(" << id_.get()
<< "," << to_c_string(state_) << "," << to_c_string(state_)
<< "," << to_c_string(mode_) << "," << to_c_string(mode_)
<< "," << wsrep::to_string(current_error_) << "," << wsrep::to_string(current_error_)
<< ")"; << ")");
}
} }
void wsrep::client_state::state( void wsrep::client_state::state(

View File

@ -25,8 +25,19 @@ std::ostream& wsrep::log::os_ = std::cout;
static wsrep::default_mutex log_mutex_; static wsrep::default_mutex log_mutex_;
wsrep::mutex& wsrep::log::mutex_ = log_mutex_; wsrep::mutex& wsrep::log::mutex_ = log_mutex_;
wsrep::log::logger_fn_type wsrep::log::logger_fn_ = 0; wsrep::log::logger_fn_type wsrep::log::logger_fn_ = 0;
std::atomic_int wsrep::log::debug_log_level_(0);
void wsrep::log::logger_fn(wsrep::log::logger_fn_type logger_fn) void wsrep::log::logger_fn(wsrep::log::logger_fn_type logger_fn)
{ {
logger_fn_ = logger_fn; logger_fn_ = logger_fn;
} }
void wsrep::log::debug_log_level(int debug_log_level)
{
debug_log_level_.store(debug_log_level, std::memory_order_relaxed);
}
int wsrep::log::debug_log_level()
{
return debug_log_level_.load(std::memory_order_relaxed);
}

View File

@ -31,6 +31,7 @@
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Helpers // // Helpers //
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -168,10 +169,11 @@ static int apply_write_set(wsrep::server_state& server_state,
// may be delivered here. The message below has // may be delivered here. The message below has
// been intentionally turned into a debug message, // been intentionally turned into a debug message,
// rather than warning. // rather than warning.
wsrep::log_debug() WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
<< "Could not find applier context for " wsrep::log::debug_level_server_state,
<< ws_meta.server_id() "Could not find applier context for "
<< ": " << ws_meta.transaction_id(); << ws_meta.server_id()
<< ": " << ws_meta.transaction_id());
ret = high_priority_service.log_dummy_write_set( ret = high_priority_service.log_dummy_write_set(
ws_handle, ws_meta); ws_handle, ws_meta);
} }
@ -435,7 +437,9 @@ wsrep::seqno wsrep::server_state::desync_and_pause()
// communicate with the rest of the cluster. However, this // communicate with the rest of the cluster. However, this
// error can be tolerated because if the provider can be // error can be tolerated because if the provider can be
// paused succesfully below. // paused succesfully below.
wsrep::log_debug() << "Failed to desync server before pause"; WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
wsrep::log::debug_level_server_state,
"Failed to desync server before pause");
desync_successful = false; desync_successful = false;
} }
else else
@ -967,7 +971,9 @@ void wsrep::server_state::start_streaming_client(
wsrep::client_state* client_state) wsrep::client_state* client_state)
{ {
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
wsrep::log_debug() << "Start streaming client: " << client_state->id(); WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
wsrep::log::debug_level_server_state,
"Start streaming client: " << client_state->id());
if (streaming_clients_.insert( if (streaming_clients_.insert(
std::make_pair(client_state->id(), client_state)).second == false) std::make_pair(client_state->id(), client_state)).second == false)
{ {
@ -981,8 +987,10 @@ void wsrep::server_state::convert_streaming_client_to_applier(
wsrep::client_state* client_state) wsrep::client_state* client_state)
{ {
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
wsrep::log_debug() << "Convert streaming client to applier " WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
<< client_state->id(); wsrep::log::debug_level_server_state,
"Convert streaming client to applier "
<< client_state->id());
streaming_clients_map::iterator i( streaming_clients_map::iterator i(
streaming_clients_.find(client_state->id())); streaming_clients_.find(client_state->id()));
assert(i != streaming_clients_.end()); assert(i != streaming_clients_.end());
@ -1027,7 +1035,9 @@ void wsrep::server_state::stop_streaming_client(
wsrep::client_state* client_state) wsrep::client_state* client_state)
{ {
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
wsrep::log_debug() << "Stop streaming client: " << client_state->id(); WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
wsrep::log::debug_level_server_state,
"Stop streaming client: " << client_state->id());
streaming_clients_map::iterator i( streaming_clients_map::iterator i(
streaming_clients_.find(client_state->id())); streaming_clients_.find(client_state->id()));
assert(i != streaming_clients_.end()); assert(i != streaming_clients_.end());
@ -1157,9 +1167,11 @@ void wsrep::server_state::state(
assert(0); assert(0);
} }
wsrep::log_debug() << "server " << name_ << " state change: " WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
<< to_c_string(state_) << " -> " wsrep::log::debug_level_server_state,
<< to_c_string(state); "server " << name_ << " state change: "
<< to_c_string(state_) << " -> "
<< to_c_string(state));
state_hist_.push_back(state_); state_hist_.push_back(state_);
server_service_.log_state_change(state_, state); server_service_.log_state_change(state_, state);
state_ = state; state_ = state;
@ -1255,9 +1267,11 @@ void wsrep::server_state::close_orphaned_sr_transactions(
server_id_cmp(i->first.first)) == server_id_cmp(i->first.first)) ==
current_view_.members().end()) current_view_.members().end())
{ {
wsrep::log_debug() << "Removing SR fragments for " WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
<< i->first.first wsrep::log::debug_level_server_state,
<< ", " << i->first.second; "Removing SR fragments for "
<< i->first.first
<< ", " << i->first.second);
wsrep::id server_id(i->first.first); wsrep::id server_id(i->first.first);
wsrep::transaction_id transaction_id(i->first.second); wsrep::transaction_id transaction_id(i->first.second);
wsrep::high_priority_service* streaming_applier(i->second); wsrep::high_priority_service* streaming_applier(i->second);

View File

@ -29,14 +29,6 @@
#include <sstream> #include <sstream>
#include <memory> #include <memory>
#define WSREP_TC_LOG_DEBUG(level, msg) \
do { \
if (client_state_.debug_log_level() < level) \
{ } \
else wsrep::log_debug() << msg; \
} while (0)
namespace namespace
{ {
class storage_service_deleter class storage_service_deleter
@ -824,7 +816,9 @@ bool wsrep::transaction::bf_abort(
if (active() == false) if (active() == false)
{ {
WSREP_TC_LOG_DEBUG(1, "Transaction not active, skipping bf abort"); WSREP_LOG_DEBUG(client_state_.debug_log_level(),
wsrep::log::debug_level_transaction,
"Transaction not active, skipping bf abort");
} }
else else
{ {
@ -842,26 +836,31 @@ bool wsrep::transaction::bf_abort(
switch (status) switch (status)
{ {
case wsrep::provider::success: case wsrep::provider::success:
WSREP_TC_LOG_DEBUG(1, "Seqno " << bf_seqno WSREP_LOG_DEBUG(client_state_.debug_log_level(),
<< " succesfully BF aborted " << id_ wsrep::log::debug_level_transaction,
<< " victim_seqno " << victim_seqno); "Seqno " << bf_seqno
<< " succesfully BF aborted " << id_
<< " victim_seqno " << victim_seqno);
bf_abort_state_ = state(); bf_abort_state_ = state();
state(lock, s_must_abort); state(lock, s_must_abort);
ret = true; ret = true;
break; break;
default: default:
WSREP_TC_LOG_DEBUG(1, WSREP_LOG_DEBUG(client_state_.debug_log_level(),
"Seqno " << bf_seqno wsrep::log::debug_level_transaction,
<< " failed to BF abort " << id_ "Seqno " << bf_seqno
<< " with status " << status << " failed to BF abort " << id_
<< " victim_seqno " << victim_seqno); << " with status " << status
<< " victim_seqno " << victim_seqno);
break; break;
} }
break; break;
} }
default: default:
WSREP_TC_LOG_DEBUG(1, "BF abort not allowed in state " WSREP_LOG_DEBUG(client_state_.debug_log_level(),
<< wsrep::to_string(state())); wsrep::log::debug_level_transaction,
"BF abort not allowed in state "
<< wsrep::to_string(state()));
break; break;
} }
} }
@ -937,13 +936,13 @@ void wsrep::transaction::state(
wsrep::unique_lock<wsrep::mutex>& lock __attribute__((unused)), wsrep::unique_lock<wsrep::mutex>& lock __attribute__((unused)),
enum wsrep::transaction::state next_state) enum wsrep::transaction::state next_state)
{ {
if (client_state_.debug_log_level() >= 1) WSREP_LOG_DEBUG(client_state_.debug_log_level(),
{ wsrep::log::debug_level_transaction,
log_debug() << "client: " << client_state_.id().get() "client: " << client_state_.id().get()
<< " txc: " << id().get() << " txc: " << id().get()
<< " state: " << to_string(state_) << " state: " << to_string(state_)
<< " -> " << to_string(next_state); << " -> " << to_string(next_state));
}
assert(lock.owns_lock()); assert(lock.owns_lock());
// BF aborter is allowed to change the state to must abort and // BF aborter is allowed to change the state to must abort and
// further to aborting and aborted if the background rollbacker // further to aborting and aborted if the background rollbacker
@ -1524,8 +1523,10 @@ void wsrep::transaction::cleanup()
void wsrep::transaction::debug_log_state( void wsrep::transaction::debug_log_state(
const char* context) const const char* context) const
{ {
WSREP_TC_LOG_DEBUG( WSREP_LOG_DEBUG(
1, context client_state_.debug_log_level(),
wsrep::log::debug_level_transaction,
context
<< "\n server: " << server_id_ << "\n server: " << server_id_
<< ", client: " << int64_t(client_state_.id().get()) << ", client: " << int64_t(client_state_.id().get())
<< ", state: " << wsrep::to_c_string(client_state_.state()) << ", state: " << wsrep::to_c_string(client_state_.state())
@ -1554,8 +1555,10 @@ void wsrep::transaction::debug_log_state(
void wsrep::transaction::debug_log_key_append(const wsrep::key& key) void wsrep::transaction::debug_log_key_append(const wsrep::key& key)
{ {
WSREP_TC_LOG_DEBUG(2, "key_append" WSREP_LOG_DEBUG(client_state_.debug_log_level(),
<< "trx_id: " wsrep::log::debug_level_transaction,
<< int64_t(id().get()) "key_append: "
<< " append key: " << key); << "trx_id: "
<< int64_t(id().get())
<< " append key: " << key);
} }