Initial work on template for HostGroups_Manager

v2.x_pg_PrepStmtBase_240714
Rene Cannao 2 years ago
parent e2362a9ed1
commit 4236d20ed6

@ -1,5 +1,6 @@
template <typename HGC> class BaseSrvList;
template <typename HGC> class BaseHGC;
template <typename HGC> class Base_HostGroups_Manager;
class MyHGC;
class PgSQL_HGC;
@ -634,7 +635,34 @@ struct srv_opts_t {
int64_t max_conns;
int32_t use_ssl;
};
#endif // 0
template <typename HGC>
class Base_HostGroups_Manager {
private:
SQLite3DB *admindb;
SQLite3DB *mydb;
pthread_mutex_t readonly_mutex;
std::set<std::string> read_only_set1;
std::set<std::string> read_only_set2;
pthread_mutex_t lock;
PtrArray *MyHostGroups;
std::unordered_map<unsigned int, HGC *>MyHostGroups_map;
HGC * MyHGC_find(unsigned int);
HGC * MyHGC_create(unsigned int);
public:
Base_HostGroups_Manager();
HGC * MyHGC_lookup(unsigned int);
friend class MySQL_HostGroups_Manager;
friend class PgSQL_HostGroups_Manager;
};
#if 0
class MySQL_HostGroups_Manager {
private:
SQLite3DB *admindb;
@ -1101,7 +1129,6 @@ class MySQL_HostGroups_Manager {
* @param lock When supplied the function calls 'wrlock()' and 'wrunlock()' functions for accessing the db.
*/
void update_table_mysql_servers_for_monitor(bool lock=false);
MyHGC * MyHGC_lookup(unsigned int);
void MyConn_add_to_pool(MySQL_Connection *);
/**

@ -548,15 +548,16 @@ struct srv_opts_t {
int32_t use_ssl;
};
class MySQL_HostGroups_Manager {
class MySQL_HostGroups_Manager : public Base_HostGroups_Manager<MyHGC> {
private:
#if 0
SQLite3DB *admindb;
SQLite3DB *mydb;
pthread_mutex_t readonly_mutex;
std::set<std::string> read_only_set1;
std::set<std::string> read_only_set2;
pthread_mutex_t lock;
#endif // 0
enum HGM_TABLES {
MYSQL_SERVERS_V2 = 0,
MYSQL_REPLICATION_HOSTGROUPS,
@ -671,15 +672,16 @@ class MySQL_HostGroups_Manager {
uint64_t hgsm_mysql_replication_hostgroups_checksum = 0;
#if 0
PtrArray *MyHostGroups;
std::unordered_map<unsigned int, MyHGC *>MyHostGroups_map;
#endif // 0
std::mutex Servers_SSL_Params_map_mutex;
std::unordered_map<std::string, MySQLServers_SslParams> Servers_SSL_Params_map;
#if 0
MyHGC * MyHGC_find(unsigned int);
MyHGC * MyHGC_create(unsigned int);
#endif // 0
void add(MySrvC *, unsigned int);
void purge_mysql_servers_table();
void generate_mysql_servers_table(int *_onlyhg=NULL);
@ -1014,7 +1016,6 @@ class MySQL_HostGroups_Manager {
* @param lock When supplied the function calls 'wrlock()' and 'wrunlock()' functions for accessing the db.
*/
void update_table_mysql_servers_for_monitor(bool lock=false);
MyHGC * MyHGC_lookup(unsigned int);
void MyConn_add_to_pool(MySQL_Connection *);
/**

@ -453,15 +453,16 @@ struct PgSQL_srv_opts_t {
int32_t use_ssl;
};
class PgSQL_HostGroups_Manager {
private:
class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager<PgSQL_HGC> {
#if 0
SQLite3DB *admindb;
SQLite3DB *mydb;
pthread_mutex_t readonly_mutex;
std::set<std::string> read_only_set1;
std::set<std::string> read_only_set2;
pthread_mutex_t lock;
#endif // 0
private:
enum HGM_TABLES {
PgSQL_SERVERS_V2 = 0,
PgSQL_REPLICATION_HOSTGROUPS,
@ -574,12 +575,13 @@ class PgSQL_HostGroups_Manager {
*/
uint64_t hgsm_pgsql_replication_hostgroups_checksum = 0;
#if 0
PtrArray *MyHostGroups;
std::unordered_map<unsigned int, PgSQL_HGC *>MyHostGroups_map;
PgSQL_HGC * MyHGC_find(unsigned int);
PgSQL_HGC * MyHGC_create(unsigned int);
#endif // 0
void add(PgSQL_SrvC *, unsigned int);
void purge_pgsql_servers_table();
@ -869,7 +871,6 @@ class PgSQL_HostGroups_Manager {
* @param lock When supplied the function calls 'wrlock()' and 'wrunlock()' functions for accessing the db.
*/
void update_table_pgsql_servers_for_monitor(bool lock=false);
PgSQL_HGC * MyHGC_lookup(unsigned int);
void MyConn_add_to_pool(PgSQL_Connection *);
/**

@ -38,6 +38,16 @@ using std::function;
#include "Base_HostGroups_Manager.h"
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 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);
#if 0
#define SAFE_SQLITE3_STEP(_stmt) do {\
do {\
@ -623,7 +633,17 @@ hg_metrics_map = std::make_tuple(
)
}
);
#endif // 0
template <typename HGC>
Base_HostGroups_Manager<HGC>::Base_HostGroups_Manager() {
pthread_mutex_init(&readonly_mutex, NULL);
pthread_mutex_init(&lock, NULL);
admindb=NULL; // initialized only if needed
mydb=new SQLite3DB();
}
#if 0
MySQL_HostGroups_Manager::MySQL_HostGroups_Manager() {
status.client_connections=0;
status.client_connections_aborted=0;
@ -2153,6 +2173,7 @@ SQLite3_result * MySQL_HostGroups_Manager::dump_table_mysql(const string& name)
return resultset;
}
#endif // 0
/**
* @brief Create a new MySQL host group container.
*
@ -2162,8 +2183,9 @@ SQLite3_result * MySQL_HostGroups_Manager::dump_table_mysql(const string& name)
* @param _hid The host group ID for the new container.
* @return A pointer to the newly created `MyHGC` instance.
*/
MyHGC * MySQL_HostGroups_Manager::MyHGC_create(unsigned int _hid) {
MyHGC *myhgc=new MyHGC(_hid);
template <typename HGC>
HGC * Base_HostGroups_Manager<HGC>::MyHGC_create(unsigned int _hid) {
HGC *myhgc=new HGC(_hid);
return myhgc;
}
@ -2177,11 +2199,12 @@ MyHGC * MySQL_HostGroups_Manager::MyHGC_create(unsigned int _hid) {
* @param _hid The host group ID to search for.
* @return A pointer to the found `MyHGC` instance if found; otherwise, a null pointer.
*/
MyHGC * MySQL_HostGroups_Manager::MyHGC_find(unsigned int _hid) {
template <typename HGC>
HGC * Base_HostGroups_Manager<HGC>::MyHGC_find(unsigned int _hid) {
if (MyHostGroups->len < 100) {
// for few HGs, we use the legacy search
for (unsigned int i=0; i<MyHostGroups->len; i++) {
MyHGC *myhgc=(MyHGC *)MyHostGroups->index(i);
HGC *myhgc=(HGC *)MyHostGroups->index(i);
if (myhgc->hid==_hid) {
return myhgc;
}
@ -2190,9 +2213,9 @@ MyHGC * MySQL_HostGroups_Manager::MyHGC_find(unsigned int _hid) {
// for a large number of HGs, we use the unordered_map
// this search is slower for a small number of HGs, therefore we use
// it only for large number of HGs
std::unordered_map<unsigned int, MyHGC *>::const_iterator it = MyHostGroups_map.find(_hid);
typename std::unordered_map<unsigned int, HGC *>::const_iterator it = MyHostGroups_map.find(_hid);
if (it != MyHostGroups_map.end()) {
MyHGC *myhgc = it->second;
HGC *myhgc = it->second;
return myhgc;
}
}
@ -2211,8 +2234,9 @@ MyHGC * MySQL_HostGroups_Manager::MyHGC_find(unsigned int _hid) {
* @return A pointer to the found or newly created `MyHGC` instance.
* @note The function assertion fails if a newly created container is not found.
*/
MyHGC * MySQL_HostGroups_Manager::MyHGC_lookup(unsigned int _hid) {
MyHGC *myhgc=NULL;
template <typename HGC>
HGC * Base_HostGroups_Manager<HGC>::MyHGC_lookup(unsigned int _hid) {
HGC *myhgc=NULL;
myhgc=MyHGC_find(_hid);
if (myhgc==NULL) {
myhgc=MyHGC_create(_hid);
@ -2225,6 +2249,7 @@ MyHGC * MySQL_HostGroups_Manager::MyHGC_lookup(unsigned int _hid) {
return myhgc;
}
#if 0
void MySQL_HostGroups_Manager::increase_reset_counter() {
wrlock();
status.myconnpoll_reset++;

@ -657,13 +657,17 @@ MySQL_HostGroups_Manager::MySQL_HostGroups_Manager() {
status.access_denied_max_user_connections=0;
status.select_for_update_or_equivalent=0;
status.auto_increment_delay_multiplex=0;
#if 0
pthread_mutex_init(&readonly_mutex, NULL);
#endif // 0
pthread_mutex_init(&Group_Replication_Info_mutex, NULL);
pthread_mutex_init(&Galera_Info_mutex, NULL);
pthread_mutex_init(&AWS_Aurora_Info_mutex, NULL);
#if 0
pthread_mutex_init(&lock, NULL);
admindb=NULL; // initialized only if needed
mydb=new SQLite3DB();
#endif // 0
#ifdef DEBUG
mydb->open((char *)"file:mem_mydb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
#else
@ -2265,6 +2269,7 @@ SQLite3_result * MySQL_HostGroups_Manager::dump_table_mysql(const string& name)
return resultset;
}
#if 0
/**
* @brief Create a new MySQL host group container.
*
@ -2310,7 +2315,6 @@ MyHGC * MySQL_HostGroups_Manager::MyHGC_find(unsigned int _hid) {
}
return NULL;
}
/**
* @brief Lookup or create a MySQL host group container by host group ID.
*
@ -2336,6 +2340,7 @@ MyHGC * MySQL_HostGroups_Manager::MyHGC_lookup(unsigned int _hid) {
MyHostGroups_map.emplace(_hid,myhgc);
return myhgc;
}
#endif // 0
void MySQL_HostGroups_Manager::increase_reset_counter() {
wrlock();

@ -836,10 +836,12 @@ PgSQL_HostGroups_Manager::PgSQL_HostGroups_Manager() {
status.access_denied_max_user_connections=0;
status.select_for_update_or_equivalent=0;
status.auto_increment_delay_multiplex=0;
#if 0
pthread_mutex_init(&readonly_mutex, NULL);
pthread_mutex_init(&lock, NULL);
admindb=NULL; // initialized only if needed
mydb=new SQLite3DB();
#endif // 0
#ifdef DEBUG
mydb->open((char *)"file:mem_mydb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
#else
@ -2057,7 +2059,7 @@ SQLite3_result * PgSQL_HostGroups_Manager::dump_table_pgsql(const string& name)
return resultset;
}
#if 0
PgSQL_HGC * PgSQL_HostGroups_Manager::MyHGC_create(unsigned int _hid) {
PgSQL_HGC *myhgc=new PgSQL_HGC(_hid);
return myhgc;
@ -2098,6 +2100,7 @@ PgSQL_HGC * PgSQL_HostGroups_Manager::MyHGC_lookup(unsigned int _hid) {
MyHostGroups_map.emplace(_hid,myhgc);
return myhgc;
}
#endif // 0
void PgSQL_HostGroups_Manager::increase_reset_counter() {
wrlock();

Loading…
Cancel
Save