mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-10-20 23:12:32 +03:00
WIP: New wsrep-lib informative assert
Example: 2023-08-31 8:26:32 1 [ERROR] WSREP: Assertion: '(0 && (state() == s_preparing || (is_xa() && state() == s_replaying) || (ret && (state() == s_must_abort || state() == s_must_replay || state() == s_cert_failed || state() == s_aborted))))' failed in: /home/jan/work/mariadb/10.4/wsrep-lib/src/transaction.cpp:387 Info: ::before_prepare_leave : ret=0 error=success state=preparing
This commit is contained in:
79
include/wsrep/assert.hpp
Normal file
79
include/wsrep/assert.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Codership Oy <info@codership.com>
|
||||
*
|
||||
* This file is part of wsrep-lib.
|
||||
*
|
||||
* Wsrep-lib is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Wsrep-lib is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef WSREP_ASSERT_HPP
|
||||
#define WSREP_ASSERT_HPP
|
||||
|
||||
/** @file assert.hpp
|
||||
*
|
||||
* Wsrep library informative assert.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/**
|
||||
* Function to do informative assert with actual file name,
|
||||
* line and formatted info text.
|
||||
*
|
||||
* @param expr Assertion expression string
|
||||
* @param file File name string
|
||||
* @param line File line number
|
||||
* @param info Formatted info text
|
||||
*
|
||||
*/
|
||||
void wsrep_info_assert(const char* expr, const char* file, const int line, const char* info);
|
||||
|
||||
/**
|
||||
* Function to create informative text from format
|
||||
* and variable number of parameters
|
||||
*
|
||||
* @param format strict
|
||||
* @param ... variable number of parameters
|
||||
*
|
||||
* @retval Formated informative text
|
||||
*
|
||||
*/
|
||||
char* wsrep_info_assert_text(const char* format, ...);
|
||||
|
||||
/**
|
||||
* Macro for informative assert. First actual expression
|
||||
* is printed and then informative text provided by
|
||||
* developer.
|
||||
*
|
||||
* @param exp assertion expression
|
||||
* @param p Informative text format and parameters
|
||||
*
|
||||
* usage : WSREP_INFO_ASSERT((EXPR), (format, format_param,...))
|
||||
* example : WSREP_INFO_ASSERT(0, ("This is always false=%d", 0));
|
||||
*
|
||||
*/
|
||||
#ifdef NDEBUG
|
||||
#define WSREP_INFO_ASSERT(exp, p) (__ASSERT_VOID_CAST (0))
|
||||
#else
|
||||
#define WSREP_INFO_ASSERT(exp, p) do { \
|
||||
if (__builtin_expect((!(exp)), false)) \
|
||||
{ \
|
||||
wsrep_info_assert(#exp, __FILE__, __LINE__, \
|
||||
wsrep_info_assert_text p); \
|
||||
assert(exp); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif // NDEBUG
|
||||
|
||||
#endif // WSREP_ASSERT_HPP
|
@@ -4,6 +4,7 @@
|
||||
|
||||
add_library(wsrep-lib
|
||||
allowlist_service_v1.cpp
|
||||
assert.cpp
|
||||
client_state.cpp
|
||||
config_service_v1.cpp
|
||||
event_service_v1.cpp
|
||||
|
73
src/assert.cpp
Normal file
73
src/assert.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Codership Oy <info@codership.com>
|
||||
*
|
||||
* This file is part of wsrep-lib.
|
||||
*
|
||||
* Wsrep-lib is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Wsrep-lib is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file assert.cpp
|
||||
*
|
||||
* Wsrep library informative assert.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "wsrep/logger.hpp"
|
||||
|
||||
/**
|
||||
* Function to create informative text from format
|
||||
* and variable number of parameters
|
||||
*
|
||||
* @param format text format strict
|
||||
* @param ... variable number of parameters
|
||||
*
|
||||
* @retval Formated informative text
|
||||
*
|
||||
*/
|
||||
#define WSREP_MAX_INFO_BUF 1024
|
||||
|
||||
char* wsrep_info_assert_text(const char* format, ...)
|
||||
{
|
||||
static char wsrep_buf[WSREP_MAX_INFO_BUF];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
int n= vsnprintf(wsrep_buf, WSREP_MAX_INFO_BUF,(char *)format, ap);
|
||||
if (n >= WSREP_MAX_INFO_BUF)
|
||||
{
|
||||
wsrep::log_debug() << "wsrep_info_assert_text too long and truncated"
|
||||
<< " used length: " << WSREP_MAX_INFO_BUF
|
||||
<< " needed lenght: " << n;
|
||||
}
|
||||
va_end(ap);
|
||||
return wsrep_buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to do informative assert with actual file name,
|
||||
* line and formatted info text. Function will not return.
|
||||
*
|
||||
* @param file File name string
|
||||
* @param line File line number
|
||||
* @param info Formatted info text
|
||||
*
|
||||
*/
|
||||
void wsrep_info_assert(const char* expr, const char* file, const int line, const char* info)
|
||||
{
|
||||
wsrep::log_error() << "Assertion: '" << expr << "' failed in: " << file << ":" << line
|
||||
<< " Info: " << info;
|
||||
}
|
@@ -27,6 +27,7 @@
|
||||
#include "wsrep/compiler.hpp"
|
||||
#include "wsrep/server_service.hpp"
|
||||
#include "wsrep/client_service.hpp"
|
||||
#include "wsrep/assert.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
@@ -346,10 +347,14 @@ int wsrep::transaction::before_prepare(
|
||||
ret = certify_commit(lock);
|
||||
}
|
||||
|
||||
assert((ret == 0 && state() == s_preparing) ||
|
||||
WSREP_INFO_ASSERT(((ret == 0 && state() == s_preparing) ||
|
||||
(state() == s_must_abort ||
|
||||
state() == s_must_replay ||
|
||||
state() == s_cert_failed));
|
||||
state() == s_cert_failed)),
|
||||
("::before_prepare : ret=%d error=%s state=%s\n",
|
||||
ret,
|
||||
to_c_string(client_state_.current_error()),
|
||||
to_c_string(state())));
|
||||
|
||||
if (ret)
|
||||
{
|
||||
@@ -379,12 +384,17 @@ int wsrep::transaction::before_prepare(
|
||||
break;
|
||||
}
|
||||
|
||||
assert(state() == s_preparing ||
|
||||
WSREP_INFO_ASSERT((state() == s_preparing ||
|
||||
(is_xa() && state() == s_replaying) ||
|
||||
(ret && (state() == s_must_abort ||
|
||||
state() == s_must_replay ||
|
||||
state() == s_cert_failed ||
|
||||
state() == s_aborted)));
|
||||
state() == s_aborted))),
|
||||
("::before_prepare_leave : ret=%d error=%s state=%s\n",
|
||||
ret,
|
||||
to_c_string(client_state_.current_error()),
|
||||
to_c_string(state())));
|
||||
|
||||
debug_log_state("before_prepare_leave");
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user