More template for Hostgroup Managers

v2.x_pg_PrepStmtBase_240714
Rene Cannao 2 years ago
parent cbc50d4494
commit 404c5e70f3

@ -656,6 +656,13 @@ class Base_HostGroups_Manager {
public:
Base_HostGroups_Manager();
HGC * MyHGC_lookup(unsigned int);
SQLite3_result * execute_query(char *query, char **error);
void wrlock();
void wrunlock();
#ifdef DEBUG
bool is_locked = false;
#endif
friend class MySQL_HostGroups_Manager;
friend class PgSQL_HostGroups_Manager;
@ -1101,6 +1108,8 @@ class MySQL_HostGroups_Manager {
SQLite3_result* get_current_mysql_table(const string& name);
SQLite3_result * execute_query(char *query, char **error);
/**
* @brief Creates a resultset with the current full content of the target table.
* @param string The target table. Valid values are:

@ -898,11 +898,13 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager<MyHGC> {
MySQL_HostGroups_Manager();
~MySQL_HostGroups_Manager();
void init();
#if 0
void wrlock();
void wrunlock();
#ifdef DEBUG
bool is_locked = false;
#endif
#endif // 0
int servers_add(SQLite3_result *resultset);
/**
* @brief Generates a new global checksum for module 'mysql_servers_v2' using the provided hash.
@ -987,7 +989,7 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager<MyHGC> {
void save_incoming_mysql_table(SQLite3_result *, const string&);
SQLite3_result* get_current_mysql_table(const string& name);
SQLite3_result * execute_query(char *query, char **error);
//SQLite3_result * execute_query(char *query, char **error);
/**
* @brief Creates a resultset with the current full content of the target table.
* @param string The target table. Valid values are:

@ -691,8 +691,8 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager<PgSQL_HGC> {
PgSQL_HostGroups_Manager();
~PgSQL_HostGroups_Manager();
void init();
void wrlock();
void wrunlock();
//void wrlock();
//void wrunlock();
int servers_add(SQLite3_result *resultset);
/**
* @brief Generates a new global checksum for module 'pgsql_servers_v2' using the provided hash.
@ -773,7 +773,7 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager<PgSQL_HGC> {
void save_incoming_pgsql_table(SQLite3_result *, const string&);
SQLite3_result* get_current_pgsql_table(const string& name);
SQLite3_result * execute_query(char *query, char **error);
//SQLite3_result * execute_query(char *query, char **error);
/**
* @brief Creates a resultset with the current full content of the target table.
* @param string The target table. Valid values are:

@ -42,11 +42,17 @@ template Base_HostGroups_Manager<MyHGC>::Base_HostGroups_Manager();
template MyHGC * Base_HostGroups_Manager<MyHGC>::MyHGC_find(unsigned int);
template MyHGC * Base_HostGroups_Manager<MyHGC>::MyHGC_create(unsigned int);
template MyHGC * Base_HostGroups_Manager<MyHGC>::MyHGC_lookup(unsigned int);
template void Base_HostGroups_Manager<MyHGC>::wrlock();
template void Base_HostGroups_Manager<MyHGC>::wrunlock();
template Base_HostGroups_Manager<PgSQL_HGC>::Base_HostGroups_Manager();
template PgSQL_HGC * Base_HostGroups_Manager<PgSQL_HGC>::MyHGC_find(unsigned int);
template PgSQL_HGC * Base_HostGroups_Manager<PgSQL_HGC>::MyHGC_create(unsigned int);
template PgSQL_HGC * Base_HostGroups_Manager<PgSQL_HGC>::MyHGC_lookup(unsigned int);
template void Base_HostGroups_Manager<PgSQL_HGC>::wrlock();
template void Base_HostGroups_Manager<PgSQL_HGC>::wrunlock();
template SQLite3_result * Base_HostGroups_Manager<MyHGC>::execute_query(char*, char**);
#if 0
#define SAFE_SQLITE3_STEP(_stmt) do {\
@ -776,14 +782,18 @@ MySQL_HostGroups_Manager::~MySQL_HostGroups_Manager() {
pthread_mutex_destroy(&lock);
}
#endif // 0
// wrlock() is only required during commit()
void MySQL_HostGroups_Manager::wrlock() {
template <typename HGC>
void Base_HostGroups_Manager<HGC>::wrlock() {
pthread_mutex_lock(&lock);
#ifdef DEBUG
is_locked = true;
#endif
}
#if 0
void MySQL_HostGroups_Manager::p_update_mysql_error_counter(p_mysql_error_type err_type, unsigned int hid, char* address, uint16_t port, unsigned int code) {
p_hg_dyn_counter::metric metric = p_hg_dyn_counter::mysql_error;
if (err_type == p_mysql_error_type::proxysql) {
@ -814,15 +824,17 @@ void MySQL_HostGroups_Manager::p_update_mysql_error_counter(p_mysql_error_type e
pthread_mutex_unlock(&mysql_errors_mutex);
}
#endif // 0
void MySQL_HostGroups_Manager::wrunlock() {
template <typename HGC>
void Base_HostGroups_Manager<HGC>::wrunlock() {
#ifdef DEBUG
is_locked = false;
#endif
pthread_mutex_unlock(&lock);
}
#if 0
void MySQL_HostGroups_Manager::wait_servers_table_version(unsigned v, unsigned w) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
@ -923,6 +935,7 @@ int MySQL_HostGroups_Manager::servers_add(SQLite3_result *resultset) {
(*proxy_sqlite3_finalize)(statement32);
return 0;
}
#endif // 0
/**
* @brief Execute a SQL query and retrieve the resultset.
@ -937,7 +950,8 @@ int MySQL_HostGroups_Manager::servers_add(SQLite3_result *resultset) {
* @return A pointer to a SQLite3_result object representing the resultset obtained from the query execution. This
* pointer may be nullptr if the query execution fails or returns an empty result.
*/
SQLite3_result * MySQL_HostGroups_Manager::execute_query(char *query, char **error) {
template <typename HGC>
SQLite3_result * Base_HostGroups_Manager<HGC>::execute_query(char *query, char **error) {
int cols=0;
int affected_rows=0;
SQLite3_result *resultset=NULL;
@ -947,6 +961,7 @@ SQLite3_result * MySQL_HostGroups_Manager::execute_query(char *query, char **err
return resultset;
}
#if 0
/**
* @brief Calculate and update the checksum for a specified table in the database.
*

@ -759,14 +759,6 @@ MySQL_HostGroups_Manager::~MySQL_HostGroups_Manager() {
pthread_mutex_destroy(&lock);
}
// wrlock() is only required during commit()
void MySQL_HostGroups_Manager::wrlock() {
pthread_mutex_lock(&lock);
#ifdef DEBUG
is_locked = true;
#endif
}
void MySQL_HostGroups_Manager::p_update_mysql_error_counter(p_mysql_error_type err_type, unsigned int hid, char* address, uint16_t port, unsigned int code) {
p_hg_dyn_counter::metric metric = p_hg_dyn_counter::mysql_error;
if (err_type == p_mysql_error_type::proxysql) {
@ -798,14 +790,6 @@ void MySQL_HostGroups_Manager::p_update_mysql_error_counter(p_mysql_error_type e
pthread_mutex_unlock(&mysql_errors_mutex);
}
void MySQL_HostGroups_Manager::wrunlock() {
#ifdef DEBUG
is_locked = false;
#endif
pthread_mutex_unlock(&lock);
}
void MySQL_HostGroups_Manager::wait_servers_table_version(unsigned v, unsigned w) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
@ -907,29 +891,6 @@ int MySQL_HostGroups_Manager::servers_add(SQLite3_result *resultset) {
return 0;
}
/**
* @brief Execute a SQL query and retrieve the resultset.
*
* This function executes a SQL query using the provided query string and returns the resultset obtained from the
* database operation. It also provides an optional error parameter to capture any error messages encountered during
* query execution.
*
* @param query A pointer to a null-terminated string containing the SQL query to be executed.
* @param error A pointer to a char pointer where any error message encountered during query execution will be stored.
* Pass nullptr if error handling is not required.
* @return A pointer to a SQLite3_result object representing the resultset obtained from the query execution. This
* pointer may be nullptr if the query execution fails or returns an empty result.
*/
SQLite3_result * MySQL_HostGroups_Manager::execute_query(char *query, char **error) {
int cols=0;
int affected_rows=0;
SQLite3_result *resultset=NULL;
wrlock();
mydb->execute_statement(query, error , &cols , &affected_rows , &resultset);
wrunlock();
return resultset;
}
/**
* @brief Calculate and update the checksum for a specified table in the database.
*

@ -924,11 +924,6 @@ PgSQL_HostGroups_Manager::~PgSQL_HostGroups_Manager() {
pthread_mutex_destroy(&lock);
}
// wrlock() is only required during commit()
void PgSQL_HostGroups_Manager::wrlock() {
pthread_mutex_lock(&lock);
}
void PgSQL_HostGroups_Manager::p_update_pgsql_error_counter(p_pgsql_error_type err_type, unsigned int hid, char* address, uint16_t port, unsigned int code) {
PgSQL_p_hg_dyn_counter::metric metric = PgSQL_p_hg_dyn_counter::pgsql_error;
if (err_type == p_pgsql_error_type::proxysql) {
@ -960,11 +955,6 @@ void PgSQL_HostGroups_Manager::p_update_pgsql_error_counter(p_pgsql_error_type e
pthread_mutex_unlock(&pgsql_errors_mutex);
}
void PgSQL_HostGroups_Manager::wrunlock() {
pthread_mutex_unlock(&lock);
}
void PgSQL_HostGroups_Manager::wait_servers_table_version(unsigned v, unsigned w) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
@ -1066,16 +1056,6 @@ int PgSQL_HostGroups_Manager::servers_add(SQLite3_result *resultset) {
return 0;
}
SQLite3_result * PgSQL_HostGroups_Manager::execute_query(char *query, char **error) {
int cols=0;
int affected_rows=0;
SQLite3_result *resultset=NULL;
wrlock();
mydb->execute_statement(query, error , &cols , &affected_rows , &resultset);
wrunlock();
return resultset;
}
void PgSQL_HostGroups_Manager::CUCFT1(
SpookyHash& myhash, bool& init, const string& TableName, const string& ColumnName, uint64_t& raw_checksum
) {

Loading…
Cancel
Save