mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-28 20:02:00 +03:00
Debug log level implementation
Debug log will now filter output based on debug level that is enabled.
This commit is contained in:
@ -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
|
||||
{
|
||||
if (debug_log_level() >= 1)
|
||||
{
|
||||
wsrep::log_debug() << context
|
||||
<< "(" << id_.get()
|
||||
<< "," << to_c_string(state_)
|
||||
<< "," << to_c_string(mode_)
|
||||
<< "," << wsrep::to_string(current_error_)
|
||||
<< ")";
|
||||
}
|
||||
WSREP_LOG_DEBUG(debug_log_level(),
|
||||
wsrep::log::debug_level_client_state,
|
||||
context
|
||||
<< "(" << id_.get()
|
||||
<< "," << to_c_string(state_)
|
||||
<< "," << to_c_string(mode_)
|
||||
<< "," << wsrep::to_string(current_error_)
|
||||
<< ")");
|
||||
|
||||
}
|
||||
|
||||
void wsrep::client_state::state(
|
||||
|
@ -25,8 +25,19 @@ std::ostream& wsrep::log::os_ = std::cout;
|
||||
static wsrep::default_mutex log_mutex_;
|
||||
wsrep::mutex& wsrep::log::mutex_ = log_mutex_;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Helpers //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -168,10 +169,11 @@ static int apply_write_set(wsrep::server_state& server_state,
|
||||
// may be delivered here. The message below has
|
||||
// been intentionally turned into a debug message,
|
||||
// rather than warning.
|
||||
wsrep::log_debug()
|
||||
<< "Could not find applier context for "
|
||||
<< ws_meta.server_id()
|
||||
<< ": " << ws_meta.transaction_id();
|
||||
WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
|
||||
wsrep::log::debug_level_server_state,
|
||||
"Could not find applier context for "
|
||||
<< ws_meta.server_id()
|
||||
<< ": " << ws_meta.transaction_id());
|
||||
ret = high_priority_service.log_dummy_write_set(
|
||||
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
|
||||
// error can be tolerated because if the provider can be
|
||||
// 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;
|
||||
}
|
||||
else
|
||||
@ -967,7 +971,9 @@ void wsrep::server_state::start_streaming_client(
|
||||
wsrep::client_state* client_state)
|
||||
{
|
||||
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(
|
||||
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::unique_lock<wsrep::mutex> lock(mutex_);
|
||||
wsrep::log_debug() << "Convert streaming client to applier "
|
||||
<< client_state->id();
|
||||
WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
|
||||
wsrep::log::debug_level_server_state,
|
||||
"Convert streaming client to applier "
|
||||
<< client_state->id());
|
||||
streaming_clients_map::iterator i(
|
||||
streaming_clients_.find(client_state->id()));
|
||||
assert(i != streaming_clients_.end());
|
||||
@ -1027,7 +1035,9 @@ void wsrep::server_state::stop_streaming_client(
|
||||
wsrep::client_state* client_state)
|
||||
{
|
||||
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_.find(client_state->id()));
|
||||
assert(i != streaming_clients_.end());
|
||||
@ -1157,9 +1167,11 @@ void wsrep::server_state::state(
|
||||
assert(0);
|
||||
}
|
||||
|
||||
wsrep::log_debug() << "server " << name_ << " state change: "
|
||||
<< to_c_string(state_) << " -> "
|
||||
<< to_c_string(state);
|
||||
WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
|
||||
wsrep::log::debug_level_server_state,
|
||||
"server " << name_ << " state change: "
|
||||
<< to_c_string(state_) << " -> "
|
||||
<< to_c_string(state));
|
||||
state_hist_.push_back(state_);
|
||||
server_service_.log_state_change(state_, state);
|
||||
state_ = state;
|
||||
@ -1255,9 +1267,11 @@ void wsrep::server_state::close_orphaned_sr_transactions(
|
||||
server_id_cmp(i->first.first)) ==
|
||||
current_view_.members().end())
|
||||
{
|
||||
wsrep::log_debug() << "Removing SR fragments for "
|
||||
<< i->first.first
|
||||
<< ", " << i->first.second;
|
||||
WSREP_LOG_DEBUG(wsrep::log::debug_log_level(),
|
||||
wsrep::log::debug_level_server_state,
|
||||
"Removing SR fragments for "
|
||||
<< i->first.first
|
||||
<< ", " << i->first.second);
|
||||
wsrep::id server_id(i->first.first);
|
||||
wsrep::transaction_id transaction_id(i->first.second);
|
||||
wsrep::high_priority_service* streaming_applier(i->second);
|
||||
|
@ -29,14 +29,6 @@
|
||||
#include <sstream>
|
||||
#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
|
||||
{
|
||||
class storage_service_deleter
|
||||
@ -824,7 +816,9 @@ bool wsrep::transaction::bf_abort(
|
||||
|
||||
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
|
||||
{
|
||||
@ -842,26 +836,31 @@ bool wsrep::transaction::bf_abort(
|
||||
switch (status)
|
||||
{
|
||||
case wsrep::provider::success:
|
||||
WSREP_TC_LOG_DEBUG(1, "Seqno " << bf_seqno
|
||||
<< " succesfully BF aborted " << id_
|
||||
<< " victim_seqno " << victim_seqno);
|
||||
WSREP_LOG_DEBUG(client_state_.debug_log_level(),
|
||||
wsrep::log::debug_level_transaction,
|
||||
"Seqno " << bf_seqno
|
||||
<< " succesfully BF aborted " << id_
|
||||
<< " victim_seqno " << victim_seqno);
|
||||
bf_abort_state_ = state();
|
||||
state(lock, s_must_abort);
|
||||
ret = true;
|
||||
break;
|
||||
default:
|
||||
WSREP_TC_LOG_DEBUG(1,
|
||||
"Seqno " << bf_seqno
|
||||
<< " failed to BF abort " << id_
|
||||
<< " with status " << status
|
||||
<< " victim_seqno " << victim_seqno);
|
||||
WSREP_LOG_DEBUG(client_state_.debug_log_level(),
|
||||
wsrep::log::debug_level_transaction,
|
||||
"Seqno " << bf_seqno
|
||||
<< " failed to BF abort " << id_
|
||||
<< " with status " << status
|
||||
<< " victim_seqno " << victim_seqno);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
WSREP_TC_LOG_DEBUG(1, "BF abort not allowed in state "
|
||||
<< wsrep::to_string(state()));
|
||||
WSREP_LOG_DEBUG(client_state_.debug_log_level(),
|
||||
wsrep::log::debug_level_transaction,
|
||||
"BF abort not allowed in state "
|
||||
<< wsrep::to_string(state()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -937,13 +936,13 @@ void wsrep::transaction::state(
|
||||
wsrep::unique_lock<wsrep::mutex>& lock __attribute__((unused)),
|
||||
enum wsrep::transaction::state next_state)
|
||||
{
|
||||
if (client_state_.debug_log_level() >= 1)
|
||||
{
|
||||
log_debug() << "client: " << client_state_.id().get()
|
||||
WSREP_LOG_DEBUG(client_state_.debug_log_level(),
|
||||
wsrep::log::debug_level_transaction,
|
||||
"client: " << client_state_.id().get()
|
||||
<< " txc: " << id().get()
|
||||
<< " state: " << to_string(state_)
|
||||
<< " -> " << to_string(next_state);
|
||||
}
|
||||
<< " -> " << to_string(next_state));
|
||||
|
||||
assert(lock.owns_lock());
|
||||
// BF aborter is allowed to change the state to must abort and
|
||||
// further to aborting and aborted if the background rollbacker
|
||||
@ -1524,8 +1523,10 @@ void wsrep::transaction::cleanup()
|
||||
void wsrep::transaction::debug_log_state(
|
||||
const char* context) const
|
||||
{
|
||||
WSREP_TC_LOG_DEBUG(
|
||||
1, context
|
||||
WSREP_LOG_DEBUG(
|
||||
client_state_.debug_log_level(),
|
||||
wsrep::log::debug_level_transaction,
|
||||
context
|
||||
<< "\n server: " << server_id_
|
||||
<< ", client: " << int64_t(client_state_.id().get())
|
||||
<< ", 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)
|
||||
{
|
||||
WSREP_TC_LOG_DEBUG(2, "key_append"
|
||||
<< "trx_id: "
|
||||
<< int64_t(id().get())
|
||||
<< " append key: " << key);
|
||||
WSREP_LOG_DEBUG(client_state_.debug_log_level(),
|
||||
wsrep::log::debug_level_transaction,
|
||||
"key_append: "
|
||||
<< "trx_id: "
|
||||
<< int64_t(id().get())
|
||||
<< " append key: " << key);
|
||||
}
|
||||
|
Reference in New Issue
Block a user