Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-26971: JSON file interface to wsrep node state.
Integration with status reporter in wsrep-lib. Status reporter reports changes in wsrep state and logged errors/ warnings to a json file which then can be read and interpreted by an external monitoring tool. Rationale: until the server is fully initialized it is unaccessible by client and the only source of information is an error log which is not machine-friendly. Since wsrep node can spend a very long time in initialization phase (state transfer), it may be a very long time that automatic tools can't easily monitor its liveness and progression. New variable: wsrep_status_file specifies the output file name. If not set, no file is created and no reporting is done. Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
- Loading branch information
Showing
16 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* Copyright 2021 Codership Oy <info@codership.com> | ||
This program 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; version 2 of the License. | ||
This program 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 this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
|
||
#include "wsrep_status.h" | ||
|
||
mysql_mutex_t LOCK_wsrep_status; | ||
|
||
#ifdef HAVE_PSI_INTERFACE | ||
PSI_mutex_key key_LOCK_wsrep_status; | ||
#endif | ||
|
||
Wsrep_mutex* Wsrep_status::m_mutex = 0; | ||
wsrep::reporter* Wsrep_status::m_instance = 0; | ||
|
||
void Wsrep_status::report_log_msg(wsrep::reporter::log_level const level, | ||
const char* const tag, size_t const tag_len, | ||
const char* const buf, size_t const buf_len, | ||
double const tstamp) | ||
{ | ||
if (!Wsrep_status::m_instance) return; | ||
|
||
Wsrep_status::m_instance->report_log_msg(level, | ||
std::string(tag, tag_len) + std::string(buf, buf_len), | ||
tstamp); | ||
} | ||
|
||
void Wsrep_status::init_once(const std::string& file_name) | ||
{ | ||
if (file_name.length() > 0 && m_instance == 0) | ||
{ | ||
mysql_mutex_init(key_LOCK_wsrep_status, &LOCK_wsrep_status, | ||
MY_MUTEX_INIT_FAST); | ||
m_mutex = new Wsrep_mutex(LOCK_wsrep_status); | ||
m_instance = new wsrep::reporter(*m_mutex, file_name, 4); | ||
} | ||
} | ||
|
||
void Wsrep_status::destroy() | ||
{ | ||
if (m_instance) | ||
{ | ||
delete m_instance; | ||
m_instance= 0; | ||
delete m_mutex; | ||
m_mutex= 0; | ||
mysql_mutex_destroy(&LOCK_wsrep_status); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright 2021 Codership Oy <info@codership.com> | ||
This program 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; version 2 of the License. | ||
This program 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 this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
|
||
#ifndef WSREP_STATUS_H | ||
#define WSREP_STATUS_H | ||
|
||
/* wsrep-lib */ | ||
#include "wsrep/reporter.hpp" | ||
|
||
/* implementation */ | ||
#include "wsrep_mutex.h" | ||
|
||
class Wsrep_status | ||
{ | ||
public: | ||
static void init_once(const std::string& file_name); | ||
static void destroy(); | ||
|
||
static void report_state(enum wsrep::server_state::state const state, | ||
float const progress = wsrep::reporter::indefinite) | ||
{ | ||
if (!Wsrep_status::m_instance) return; | ||
|
||
Wsrep_status::m_instance->report_state(state, progress); | ||
} | ||
|
||
static void report_log_msg(wsrep::reporter::log_level level, | ||
const char* tag, size_t tag_len, | ||
const char* buf, size_t buf_len, | ||
double const tstamp = wsrep::reporter::undefined); | ||
// { | ||
// if (!Wsrep_status::m_instance) return; | ||
// | ||
// Wsrep_status::m_instance->report_log_msg(level, msg, tstamp); | ||
// } | ||
|
||
static bool is_instance_initialized() | ||
{ | ||
return m_instance; | ||
} | ||
|
||
private: | ||
Wsrep_status(const std::string& file_name); | ||
|
||
static Wsrep_mutex* m_mutex; | ||
static wsrep::reporter* m_instance; | ||
}; | ||
|
||
#endif /* WSREP_STATUS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters