diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..afadf93b01 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,12 @@ +Checks: > + clang-analyzer-*, + bugprone-*, + performance-*, + modernize-use-nullptr, + modernize-use-override, + modernize-loop-convert, + modernize-pass-by-value, + readability-braces-around-statements +WarningsAsErrors: '' +HeaderFilterRegex: 'include/|lib/' +FormatStyle: none diff --git a/.gitignore b/.gitignore index 33787afecd..53f9daf9b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Internal Repos priv-infra/ +# Lint output (do not commit) +lint/ + # direnv .envrc.local diff --git a/Makefile b/Makefile index 7b916f99b6..e796f23e96 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,20 @@ ifndef GIT_VERSION_BASE $(error GIT_VERSION_BASE is not set) endif +.PHONY: lint lint-generate-cdb lint-run + +lint-generate-cdb: + @echo "Generating compile_commands.json (requires bear)" + ./scripts/lint/generate-compile-commands.sh + +lint-run: + @echo "Running local linters" + ./scripts/lint/run-local.sh + +lint: lint-generate-cdb lint-run + @echo "Done lint" + + ### RELEASE TIERS & FEATURE FLAGS: ### ProxySQL supports three distinct release tiers built from the same codebase. ### The tier is controlled by environment variables which enable feature guards diff --git a/compile_commands.events.json b/compile_commands.events.json new file mode 100644 index 0000000000..260facad0e Binary files /dev/null and b/compile_commands.events.json differ diff --git a/include/AI_Features_Manager.h b/include/AI_Features_Manager.h index 09c52ce2fa..65a31d249a 100644 --- a/include/AI_Features_Manager.h +++ b/include/AI_Features_Manager.h @@ -27,8 +27,8 @@ * @endcode */ -#ifndef __CLASS_AI_FEATURES_MANAGER_H -#define __CLASS_AI_FEATURES_MANAGER_H +#ifndef PROXYSQL_AI_FEATURES_MANAGER_H +#define PROXYSQL_AI_FEATURES_MANAGER_H #ifdef PROXYSQLGENAI diff --git a/include/AI_Vector_Storage.h b/include/AI_Vector_Storage.h index 7ccfd29871..1e75cf9636 100644 --- a/include/AI_Vector_Storage.h +++ b/include/AI_Vector_Storage.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_AI_VECTOR_STORAGE_H -#define __CLASS_AI_VECTOR_STORAGE_H +#ifndef PROXYSQL_AI_VECTOR_STORAGE_H +#define PROXYSQL_AI_VECTOR_STORAGE_H #ifdef PROXYSQLGENAI diff --git a/include/Anomaly_Detector.h b/include/Anomaly_Detector.h index fdfffc2257..1113398059 100644 --- a/include/Anomaly_Detector.h +++ b/include/Anomaly_Detector.h @@ -32,8 +32,8 @@ * @endcode */ -#ifndef __CLASS_ANOMALY_DETECTOR_H -#define __CLASS_ANOMALY_DETECTOR_H +#ifndef PROXYSQL_ANOMALY_DETECTOR_H +#define PROXYSQL_ANOMALY_DETECTOR_H #ifdef PROXYSQLGENAI diff --git a/include/Base_HostGroups_Manager.h b/include/Base_HostGroups_Manager.h index 22c8c6b439..bbff695a40 100644 --- a/include/Base_HostGroups_Manager.h +++ b/include/Base_HostGroups_Manager.h @@ -347,7 +347,7 @@ class BaseHGC { // MySQL Host Group Container bool connection_warming; bool configured; // this variable controls if attributes are configured or not. If not configured, they do not apply bool initialized; // this variable controls if attributes were ever configured or not. Used by reset_attributes() - nlohmann::json * ignore_session_variables_json = NULL; // the JSON format of ignore_session_variables + nlohmann::json * ignore_session_variables_json = nullptr; // the JSON format of ignore_session_variables } attributes; struct { int64_t weight; @@ -393,7 +393,7 @@ class Group_Replication_Info { char *comment; bool active; int writer_is_also_reader; - bool __active; + bool active_; bool need_converge; // this is set to true on LOAD MYSQL SERVERS TO RUNTIME . This ensure that checks wil take an action int current_num_writers; int current_num_backup_writers; @@ -415,7 +415,7 @@ class Galera_Info { char *comment; bool active; int writer_is_also_reader; - bool __active; + bool active_; bool need_converge; // this is set to true on LOAD MYSQL SERVERS TO RUNTIME . This ensure that checks wil take an action int current_num_writers; int current_num_backup_writers; @@ -444,7 +444,7 @@ class AWS_Aurora_Info { char * domain_name; char * comment; bool active; - bool __active; + bool active_; AWS_Aurora_Info(int w, int r, int _port, char *_end_addr, int maxl, int al, int minl, int lnc, int ci, int ct, bool _a, int wiar, int nrw, char *c); bool update(int r, int _port, char *_end_addr, int maxl, int al, int minl, int lnc, int ci, int ct, bool _a, int wiar, int nrw, char *c); ~AWS_Aurora_Info(); @@ -482,7 +482,7 @@ struct p_hg_counter { myhgm_myconnpool_reset, myhgm_myconnpool_destroy, auto_increment_delay_multiplex, - __size + SIZE_ }; }; @@ -490,12 +490,12 @@ struct p_hg_gauge { enum metric { server_connections_connected = 0, client_connections_connected, - __size + SIZE_ }; }; struct p_hg_dyn_counter { - enum metric { + enum metric : uint8_t { conn_pool_bytes_data_recv = 0, conn_pool_bytes_data_sent, connection_pool_conn_err, @@ -504,22 +504,22 @@ struct p_hg_dyn_counter { gtid_executed, proxysql_mysql_error, mysql_error, - __size + SIZE_ }; }; -enum class p_mysql_error_type { +enum class p_mysql_error_type : uint8_t { mysql, proxysql }; struct p_hg_dyn_gauge { - enum metric { + enum metric : uint8_t { connection_pool_conn_free = 0, connection_pool_conn_used, connection_pool_latency_us, connection_pool_status, - __size + SIZE_ }; }; @@ -550,7 +550,7 @@ enum READ_ONLY_SERVER_T { ROS_HOSTNAME = 0, ROS_PORT, ROS_READONLY, - ROS__SIZE + ROS_SIZE_ }; enum REPLICATION_LAG_SERVER_T { @@ -559,7 +559,7 @@ enum REPLICATION_LAG_SERVER_T { RLS_PORT, RLS_CURRENT_REPLICATION_LAG, RLS_OVERRIDE_REPLICATION_LAG, - RLS__SIZE + RLS_SIZE_ }; /** @@ -637,10 +637,10 @@ class MySQL_HostGroups_Manager { MYSQL_SERVERS_SSL_PARAMS, MYSQL_SERVERS, - __HGM_TABLES_SIZE + HGM_TABLES_SIZE_ }; - std::array table_resultset_checksum { {0} }; + std::array table_resultset_checksum { {0} }; class HostGroup_Server_Mapping { public: @@ -648,7 +648,7 @@ class MySQL_HostGroups_Manager { WRITER = 0, READER = 1, - __TYPE_SIZE + TYPE_SIZE_ }; struct Node { @@ -713,7 +713,7 @@ class MySQL_HostGroups_Manager { MySrvC* insert_HGM(unsigned int hostgroup_id, const MySrvC* srv); void remove_HGM(MySrvC* srv); - std::array, __TYPE_SIZE> mapping; // index 0 contains reader and 1 contains writer hostgroups + std::array, TYPE_SIZE_> mapping; // index 0 contains reader and 1 contains writer hostgroups int readonly_flag; MySQL_HostGroups_Manager* myHGM; }; @@ -915,12 +915,12 @@ class MySQL_HostGroups_Manager { ////////////////////////////////////////////////////// /// Prometheus metrics arrays - std::array p_counter_array {}; - std::array p_gauge_array {}; + std::array p_counter_array {}; + std::array p_gauge_array {}; // Prometheus dyn_metrics families arrays - std::array*, p_hg_dyn_counter::__size> p_dyn_counter_array {}; - std::array*, p_hg_dyn_gauge::__size> p_dyn_gauge_array {}; + std::array*, p_hg_dyn_counter::SIZE_> p_dyn_counter_array {}; + std::array*, p_hg_dyn_gauge::SIZE_> p_dyn_gauge_array {}; /// Prometheus connection_pool metrics std::map p_conn_pool_bytes_data_recv_map {}; diff --git a/include/ClickHouse_Authentication.hpp b/include/ClickHouse_Authentication.hpp index 76e4e4a0d7..6541d2b9c5 100644 --- a/include/ClickHouse_Authentication.hpp +++ b/include/ClickHouse_Authentication.hpp @@ -20,9 +20,9 @@ typedef struct _ch_account_details_t { bool fast_forward; int max_connections; int num_connections_used; - bool __frontend; // this is used only during the dump - bool __backend; // this is used only during the dump - bool __active; + bool frontend_; // this is used only during the dump + bool backend_; // this is used only during the dump + bool active_; } ch_account_details_t; struct ch_dup_account_details_t { @@ -79,7 +79,7 @@ class ClickHouse_Authentication { bool *fast_forward, int *max_connections, void **sha1_pass); ch_account_details_t lookup(char* username, enum cred_username_type usertype, const ch_dup_account_details_t& dup_details); int dump_all_users(ch_account_details_t ***, bool _complete = true); - int increase_frontend_user_connections(char *username, int *mc = NULL); + int increase_frontend_user_connections(char *username, int *mc = nullptr); void decrease_frontend_user_connections(char *username); void set_all_inactive(enum cred_username_type usertype); void remove_inactives(enum cred_username_type usertype); diff --git a/include/Command_Counter.h b/include/Command_Counter.h index c832a4ae74..940a1d3163 100644 --- a/include/Command_Counter.h +++ b/include/Command_Counter.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_COMMAND_COUNTER_H -#define __CLASS_COMMAND_COUNTER_H +#ifndef PROXYSQL_COMMAND_COUNTER_H +#define PROXYSQL_COMMAND_COUNTER_H class Command_Counter { public: @@ -60,4 +60,4 @@ class Command_Counter { } }; -#endif /* __CLASS_COMMAND_COUNTER_H */ +#endif /* PROXYSQL_COMMAND_COUNTER_H */ diff --git a/include/GenAI_Thread.h b/include/GenAI_Thread.h index 2bbbb68e00..fc80cce2e0 100644 --- a/include/GenAI_Thread.h +++ b/include/GenAI_Thread.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_GENAI_THREAD_H -#define __CLASS_GENAI_THREAD_H +#ifndef PROXYSQL_GENAI_THREAD_H +#define PROXYSQL_GENAI_THREAD_H #ifdef PROXYSQLGENAI diff --git a/include/LLM_Bridge.h b/include/LLM_Bridge.h index 902b12e5e7..e5b6cbf4bd 100644 --- a/include/LLM_Bridge.h +++ b/include/LLM_Bridge.h @@ -25,8 +25,8 @@ * @endcode */ -#ifndef __CLASS_LLM_BRIDGE_H -#define __CLASS_LLM_BRIDGE_H +#ifndef PROXYSQL_LLM_BRIDGE_H +#define PROXYSQL_LLM_BRIDGE_H #ifdef PROXYSQLGENAI @@ -334,4 +334,4 @@ class LLM_Bridge { #endif /* PROXYSQLGENAI */ -#endif // __CLASS_LLM_BRIDGE_H +#endif /* PROXYSQL_LLM_BRIDGE_H */ diff --git a/include/MCP_Thread.h b/include/MCP_Thread.h index fc082e1452..47e08c67e0 100644 --- a/include/MCP_Thread.h +++ b/include/MCP_Thread.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MCP_THREAD_H -#define __CLASS_MCP_THREAD_H +#ifndef PROXYSQL_MCP_THREAD_H +#define PROXYSQL_MCP_THREAD_H #ifdef PROXYSQLGENAI diff --git a/include/MySQL_Authentication.hpp b/include/MySQL_Authentication.hpp index 1da4d56506..3c1da76c5b 100644 --- a/include/MySQL_Authentication.hpp +++ b/include/MySQL_Authentication.hpp @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_AUTHENTICATION_H -#define __CLASS_MYSQL_AUTHENTICATION_H +#ifndef PROXYSQL_MYSQL_AUTHENTICATION_H +#define PROXYSQL_MYSQL_AUTHENTICATION_H #include "proxysql.h" #include "cpp.h" @@ -22,9 +22,9 @@ typedef struct _account_details_t { int max_connections; int num_connections_used; int num_connections_used_addl_pass; - bool __frontend; // this is used only during the dump - bool __backend; // this is used only during the dump - bool __active; + bool frontend_; // this is used only during the dump + bool backend_; // this is used only during the dump + bool active_; char *attributes = nullptr; char *comment = nullptr; } account_details_t; diff --git a/include/MySQL_Data_Stream.h b/include/MySQL_Data_Stream.h index 337a1a7432..97784959ba 100644 --- a/include/MySQL_Data_Stream.h +++ b/include/MySQL_Data_Stream.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_DATA_STREAM_H -#define __CLASS_MYSQL_DATA_STREAM_H +#ifndef PROXYSQL_MYSQL_DATA_STREAM_H +#define PROXYSQL_MYSQL_DATA_STREAM_H #include "proxysql.h" #include "cpp.h" @@ -287,4 +287,4 @@ class MySQL_Data_Stream void get_client_myds_info_json(nlohmann::json&); }; -#endif /* __CLASS_MYSQL_DATA_STREAM_H */ +#endif /* PROXYSQL_MYSQL_DATA_STREAM_H */ diff --git a/include/MySQL_HostGroups_Manager.h b/include/MySQL_HostGroups_Manager.h index 0ba8c6cf85..629ca94b4e 100644 --- a/include/MySQL_HostGroups_Manager.h +++ b/include/MySQL_HostGroups_Manager.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_HOSTGROUPS_MANAGER_H -#define __CLASS_MYSQL_HOSTGROUPS_MANAGER_H +#ifndef PROXYSQL_MYSQL_HOSTGROUPS_MANAGER_H +#define PROXYSQL_MYSQL_HOSTGROUPS_MANAGER_H #include "proxysql.h" #include "cpp.h" #include "proxysql_gtid.h" @@ -177,10 +177,13 @@ class MySrvConnList { int find_idx(MySQL_Connection *c) { //for (unsigned int i=0; ilen; i++) { - MySQL_Connection *conn = NULL; + MySQL_Connection *conn = nullptr; conn = (MySQL_Connection *)conns->index(i); if (conn==c) { - return (unsigned int)i; + // 'find_idx' returns an int; cast the unsigned loop index to int + // to avoid unsigned->signed narrowing warnings and keep the + // sentinel return value of -1 for "not found". + return static_cast(i); } } return -1; @@ -303,7 +306,7 @@ class Group_Replication_Info { char *comment; bool active; int writer_is_also_reader; - bool __active; + bool active_; bool need_converge; // this is set to true on LOAD MYSQL SERVERS TO RUNTIME . This ensure that checks wil take an action int current_num_writers; int current_num_backup_writers; @@ -312,6 +315,8 @@ class Group_Replication_Info { Group_Replication_Info(int w, int b, int r, int o, int mw, int mtb, bool _a, int _w, char *c); bool update(int b, int r, int o, int mw, int mtb, bool _a, int _w, char *c); ~Group_Replication_Info(); + Group_Replication_Info(const Group_Replication_Info&) = delete; + Group_Replication_Info& operator=(const Group_Replication_Info&) = delete; }; class Galera_Info { @@ -325,7 +330,7 @@ class Galera_Info { char *comment; bool active; int writer_is_also_reader; - bool __active; + bool active_; bool need_converge; // this is set to true on LOAD MYSQL SERVERS TO RUNTIME . This ensure that checks wil take an action int current_num_writers; int current_num_backup_writers; @@ -334,6 +339,8 @@ class Galera_Info { Galera_Info(int w, int b, int r, int o, int mw, int mtb, bool _a, int _w, char *c); bool update(int b, int r, int o, int mw, int mtb, bool _a, int _w, char *c); ~Galera_Info(); + Galera_Info(const Galera_Info&) = delete; + Galera_Info& operator=(const Galera_Info&) = delete; }; class AWS_Aurora_Info { @@ -354,10 +361,12 @@ class AWS_Aurora_Info { char * domain_name; char * comment; bool active; - bool __active; + bool active_; AWS_Aurora_Info(int w, int r, int _port, char *_end_addr, int maxl, int al, int minl, int lnc, int ci, int ct, bool _a, int wiar, int nrw, char *c); bool update(int r, int _port, char *_end_addr, int maxl, int al, int minl, int lnc, int ci, int ct, bool _a, int wiar, int nrw, char *c); ~AWS_Aurora_Info(); + AWS_Aurora_Info(const AWS_Aurora_Info&) = delete; + AWS_Aurora_Info& operator=(const AWS_Aurora_Info&) = delete; }; struct p_hg_counter { @@ -393,7 +402,7 @@ struct p_hg_counter { myhgm_myconnpool_reset, myhgm_myconnpool_destroy, auto_increment_delay_multiplex, - __size + SIZE_ }; }; @@ -403,12 +412,12 @@ struct p_hg_gauge { client_connections_connected, client_connections_connected_prim, client_connections_connected_addl, - __size + SIZE_ }; }; struct p_hg_dyn_counter { - enum metric { + enum metric : uint8_t { conn_pool_bytes_data_recv = 0, conn_pool_bytes_data_sent, connection_pool_conn_err, @@ -417,22 +426,22 @@ struct p_hg_dyn_counter { gtid_executed, proxysql_mysql_error, mysql_error, - __size + SIZE_ }; }; -enum class p_mysql_error_type { +enum class p_mysql_error_type : uint8_t { mysql, proxysql }; struct p_hg_dyn_gauge { - enum metric { + enum metric : uint8_t { connection_pool_conn_free = 0, connection_pool_conn_used, connection_pool_latency_us, connection_pool_status, - __size + SIZE_ }; }; @@ -463,7 +472,7 @@ enum READ_ONLY_SERVER_T { ROS_HOSTNAME = 0, ROS_PORT, ROS_READONLY, - ROS__SIZE + ROS_SIZE_ }; enum REPLICATION_LAG_SERVER_T { @@ -472,7 +481,7 @@ enum REPLICATION_LAG_SERVER_T { RLS_PORT, RLS_CURRENT_REPLICATION_LAG, RLS_OVERRIDE_REPLICATION_LAG, - RLS__SIZE + RLS_SIZE_ }; /** @@ -516,10 +525,10 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager { MYSQL_SERVERS_SSL_PARAMS, MYSQL_SERVERS, - __HGM_TABLES_SIZE + HGM_TABLES_SIZE_ }; - std::array table_resultset_checksum { {0} }; + std::array table_resultset_checksum { {0} }; class HostGroup_Server_Mapping { public: @@ -527,11 +536,11 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager { WRITER = 0, READER = 1, - __TYPE_SIZE + TYPE_SIZE_ }; struct Node { - MySrvC* srv = NULL; + MySrvC* srv = nullptr; unsigned int reader_hostgroup_id = -1; unsigned int writer_hostgroup_id = -1; //MySerStatus server_status = MYSQL_SERVER_STATUS_OFFLINE_HARD; @@ -592,7 +601,7 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager { MySrvC* insert_HGM(unsigned int hostgroup_id, const MySrvC* srv); void remove_HGM(MySrvC* srv); - std::array, __TYPE_SIZE> mapping; // index 0 contains reader and 1 contains writer hostgroups + std::array, TYPE_SIZE_> mapping; // index 0 contains reader and 1 contains writer hostgroups int readonly_flag; MySQL_HostGroups_Manager* myHGM; }; @@ -801,12 +810,12 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager { ////////////////////////////////////////////////////// /// Prometheus metrics arrays - std::array p_counter_array {}; - std::array p_gauge_array {}; + std::array p_counter_array {}; + std::array p_gauge_array {}; // Prometheus dyn_metrics families arrays - std::array*, p_hg_dyn_counter::__size> p_dyn_counter_array {}; - std::array*, p_hg_dyn_gauge::__size> p_dyn_gauge_array {}; + std::array*, p_hg_dyn_counter::SIZE_> p_dyn_counter_array {}; + std::array*, p_hg_dyn_gauge::SIZE_> p_dyn_gauge_array {}; /// Prometheus connection_pool metrics std::map p_conn_pool_bytes_data_recv_map {}; @@ -1007,7 +1016,7 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager { void drop_all_idle_connections(); int get_multiple_idle_connections(int, unsigned long long, MySQL_Connection **, int); - SQLite3_result * SQL3_Connection_Pool(bool _reset, int *hid = NULL); + SQLite3_result * SQL3_Connection_Pool(bool _reset, int *hid = nullptr); SQLite3_result * SQL3_Free_Connections(); void push_MyConn_to_pool(MySQL_Connection *, bool _lock=true); @@ -1132,4 +1141,4 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager { }; -#endif /* __CLASS_MYSQL_HOSTGROUPS_MANAGER_H */ +#endif /* PROXYSQL_MYSQL_HOSTGROUPS_MANAGER_H */ diff --git a/include/MySQL_LDAP_Authentication.hpp b/include/MySQL_LDAP_Authentication.hpp index 95114f4877..732ba13da2 100644 --- a/include/MySQL_LDAP_Authentication.hpp +++ b/include/MySQL_LDAP_Authentication.hpp @@ -2,11 +2,11 @@ #define CLASS_MYSQL_LDAP_AUTHENTICATION_H struct LDAP_USER_FIELD_IDX { - enum index { + enum index : uint8_t { USERNAME = 0, FRONTEND_CONNECTIONS = 1, FRONTED_MAX_CONNECTIONS = 2, - __SIZE + SIZE_ }; }; @@ -17,25 +17,25 @@ class MySQL_LDAP_Authentication { enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward, int *max_connections, void **sha1_pass, char **attributes, - char **backend_username) {return NULL;}; + char **backend_username) {return nullptr;}; - virtual int increase_frontend_user_connections(char *username, int *max_connections = NULL) { return 0; }; + virtual int increase_frontend_user_connections(char *username, int *max_connections = nullptr) { return 0; }; virtual void decrease_frontend_user_connections(char *username) {}; virtual std::unique_ptr dump_all_users() { return 0; }; virtual void wrlock() {}; virtual void wrunlock() {}; - virtual char **get_variables_list() {return NULL;} + virtual char **get_variables_list() {return nullptr;} virtual bool has_variable(const char *name) {return false;}; - virtual char * get_variable(char *name) {return NULL;}; + virtual char * get_variable(char *name) {return nullptr;}; virtual bool set_variable(char *name, char *value) {return false;}; virtual void load_mysql_ldap_mapping(SQLite3_result *result) {}; - virtual SQLite3_result * dump_table_mysql_ldap_mapping() { return NULL; }; - virtual SQLite3_result * dump_table_pgsql_ldap_mapping() { return NULL; }; + virtual SQLite3_result * dump_table_mysql_ldap_mapping() { return nullptr; }; + virtual SQLite3_result * dump_table_pgsql_ldap_mapping() { return nullptr; }; virtual uint64_t get_ldap_mapping_runtime_checksum() { return 0; }; - virtual SQLite3_result * SQL3_getStats() { return NULL; } + virtual SQLite3_result * SQL3_getStats() { return nullptr; } virtual void print_version() {}; }; diff --git a/include/MySQL_Logger.hpp b/include/MySQL_Logger.hpp index 88aa130a09..4f2ec25432 100644 --- a/include/MySQL_Logger.hpp +++ b/include/MySQL_Logger.hpp @@ -19,7 +19,7 @@ class LogBufferThreadContext; class MySQL_Logger; struct p_ml_counter { - enum metric { + enum metric : uint8_t { memory_copy_count = 0, disk_copy_count, get_all_events_calls_count, @@ -31,14 +31,14 @@ struct p_ml_counter { total_events_copied_to_disk, circular_buffer_events_added_count, circular_buffer_events_dropped_count, - __size + SIZE_ }; }; struct p_ml_gauge { - enum metric { + enum metric : uint8_t { circular_buffer_events_size, - __size + SIZE_ }; }; @@ -392,8 +392,8 @@ class MySQL_Logger { * @brief Structure holding the exposed Prometheus metrics for MySQL event logger. */ struct { - std::array p_counter_array {}; - std::array p_gauge_array {}; + std::array p_counter_array {}; + std::array p_gauge_array {}; prometheus::Counter* p_queries_logged_total { nullptr }; } prom_metrics; diff --git a/include/MySQL_Monitor.hpp b/include/MySQL_Monitor.hpp index 7df88a4213..19ef6db2db 100644 --- a/include/MySQL_Monitor.hpp +++ b/include/MySQL_Monitor.hpp @@ -85,9 +85,9 @@ A single AWS_Aurora_monitor_node will have a AWS_Aurora_status_entry per check. class AWS_Aurora_replica_host_status_entry { public: - char * server_id = NULL; - char * session_id = NULL; - char * last_update_timestamp = NULL; + char * server_id = nullptr; + char * session_id = nullptr; + char * last_update_timestamp = nullptr; float replica_lag_ms = 0.0; // originally a double unsigned int estimated_lag_ms = 0; float cpu = 0.0; @@ -122,7 +122,7 @@ class AWS_Aurora_monitor_node { ~AWS_Aurora_monitor_node(); bool add_entry(AWS_Aurora_status_entry *ase); // return true if status changed AWS_Aurora_status_entry *last_entry() { - if (idx_last_entry == -1) return NULL; + if (idx_last_entry == -1) return nullptr; return (last_entries[idx_last_entry]); } }; @@ -154,7 +154,7 @@ class Galera_monitor_node { ~Galera_monitor_node(); bool add_entry(unsigned long long _st, unsigned long long _ct, long long _tb, bool _pp, bool _ro, int _local_state, bool _desync, bool _reject, bool _sst_donor_reject, bool _pxc_maint_mode, char *_error); // return true if status changed Galera_status_entry_t *last_entry() { - if (idx_last_entry == -1) return NULL; + if (idx_last_entry == -1) return nullptr; return (&last_entries[idx_last_entry]); } }; @@ -353,7 +353,7 @@ class WorkItem { }; struct p_mon_counter { - enum metric { + enum metric : uint8_t { mysql_monitor_workers_started, mysql_monitor_connect_check_ok, mysql_monitor_connect_check_err, @@ -366,15 +366,15 @@ struct p_mon_counter { mysql_monitor_dns_cache_queried, mysql_monitor_dns_cache_lookup_success, mysql_monitor_dns_cache_record_updated, - __size + SIZE_ }; }; struct p_mon_gauge { - enum metric { + enum metric : uint8_t { mysql_monitor_workers, mysql_monitor_workers_aux, - __size + SIZE_ }; }; @@ -410,7 +410,7 @@ class DNS_Cache { public: DNS_Cache() : enabled(true) { - int rc = pthread_rwlock_init(&rwlock_, NULL); + int rc = pthread_rwlock_init(&rwlock_, nullptr); assert(rc == 0); } @@ -454,8 +454,8 @@ struct DNS_Resolve_Data { class MySQL_Monitor { public: - static std::string dns_lookup(const std::string& hostname, bool return_hostname_if_lookup_fails = true, size_t* ip_count = NULL); - static std::string dns_lookup(const char* hostname, bool return_hostname_if_lookup_fails = true, size_t* ip_count = NULL); + static std::string dns_lookup(const std::string& hostname, bool return_hostname_if_lookup_fails = true, size_t* ip_count = nullptr); + static std::string dns_lookup(const char* hostname, bool return_hostname_if_lookup_fails = true, size_t* ip_count = nullptr); static bool update_dns_cache_from_mysql_conn(const MYSQL* mysql); static void trigger_dns_cache_update(); @@ -501,8 +501,8 @@ class MySQL_Monitor { std::atomic_bool force_dns_cache_update; struct { /// Prometheus metrics arrays - std::array p_counter_array {}; - std::array p_gauge_array {}; + std::array p_counter_array {}; + std::array p_gauge_array {}; } metrics; void p_update_metrics(); std::unique_ptr*>> queue; diff --git a/include/MySQL_PreparedStatement.h b/include/MySQL_PreparedStatement.h index af3776fcb3..8b7a64008e 100644 --- a/include/MySQL_PreparedStatement.h +++ b/include/MySQL_PreparedStatement.h @@ -86,13 +86,10 @@ class stmt_execute_metadata_t { my_bool *is_nulls; unsigned long *lengths; void *pkt; - stmt_execute_metadata_t() { - size = 0; - stmt_id = 0; - binds=NULL; - is_nulls=NULL; - lengths=NULL; - pkt=NULL; + stmt_execute_metadata_t() + : size(0), stmt_id(0), flags(0), num_params(0), + binds(nullptr), is_nulls(nullptr), lengths(nullptr), pkt(nullptr) + { } ~stmt_execute_metadata_t() { if (binds) diff --git a/include/MySQL_Protocol.h b/include/MySQL_Protocol.h index 16a2e682da..16b1a4e3c7 100644 --- a/include/MySQL_Protocol.h +++ b/include/MySQL_Protocol.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_PROTOCOL_H -#define __CLASS_MYSQL_PROTOCOL_H +#ifndef PROXYSQL_MYSQL_PROTOCOL_H +#define PROXYSQL_MYSQL_PROTOCOL_H #include "proxysql.h" #include "cpp.h" @@ -142,7 +142,9 @@ class MySQL_Protocol { uint16_t prot_status; bool more_data_needed; MySQL_Data_Stream *get_myds() { return *myds; } - MySQL_Protocol() { + MySQL_Protocol() + : userinfo(nullptr), sess(nullptr), myds(nullptr), current_PreStmt(nullptr) + { sent_auth_plugin_id = AUTH_MYSQL_NATIVE_PASSWORD; auth_plugin_id = AUTH_UNKNOWN_PLUGIN; prot_status=0; @@ -244,4 +246,4 @@ class MySQL_Protocol { bool verify_user_attributes(int calling_line, const char *calling_func, const unsigned char *user); bool user_attributes_has_spiffe(int calling_line, const char *calling_func, const unsigned char *user); }; -#endif /* __CLASS_MYSQL_PROTOCOL_H */ +#endif /* PROXYSQL_MYSQL_PROTOCOL_H */ diff --git a/include/MySQL_Query_Cache.h b/include/MySQL_Query_Cache.h index 276683b2a3..b55a679c4d 100644 --- a/include/MySQL_Query_Cache.h +++ b/include/MySQL_Query_Cache.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_QUERY_CACHE_H -#define __CLASS_MYSQL_QUERY_CACHE_H +#ifndef PROXYSQL_MYSQL_QUERY_CACHE_H +#define PROXYSQL_MYSQL_QUERY_CACHE_H #include "proxysql.h" #include "cpp.h" @@ -23,4 +23,4 @@ class MySQL_Query_Cache : public Query_Cache { //void* purgeHash_thread(void*); }; -#endif /* __CLASS_MYSQL_QUERY_CACHE_H */ +#endif /* PROXYSQL_MYSQL_QUERY_CACHE_H */ diff --git a/include/MySQL_Query_Processor.h b/include/MySQL_Query_Processor.h index ae98733009..c63d1de226 100644 --- a/include/MySQL_Query_Processor.h +++ b/include/MySQL_Query_Processor.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_QUERY_PROCESSOR_H -#define __CLASS_MYSQL_QUERY_PROCESSOR_H +#ifndef PROXYSQL_MYSQL_QUERY_PROCESSOR_H +#define PROXYSQL_MYSQL_QUERY_PROCESSOR_H #include "proxysql.h" #include "cpp.h" #include "QP_rule_text.h" @@ -12,7 +12,7 @@ typedef struct _MySQL_Query_processor_Rule_t : public QP_rule_t { class MySQL_Query_Processor_Output : public Query_Processor_Output { public: - MySQL_Query_Processor_Output() = default; +MySQL_Query_Processor_Output() : Query_Processor_Output(), min_gtid(nullptr), gtid_from_hostgroup(-1) {} ~MySQL_Query_Processor_Output() = default; void init() { @@ -98,4 +98,4 @@ class MySQL_Query_Processor : public Query_Processor { friend class Query_Processor; }; -#endif /* __CLASS_MYSQL_QUERY_PROCESSOR_H */ +#endif /* PROXYSQL_MYSQL_QUERY_PROCESSOR_H */ diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index 00cac16190..33fe271d8f 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -4,8 +4,8 @@ */ #ifdef CLASS_BASE_SESSION_H -#ifndef __CLASS_MYSQL_SESSION_H -#define __CLASS_MYSQL_SESSION_H +#ifndef PROXYSQL_MYSQL_SESSION_H +#define PROXYSQL_MYSQL_SESSION_H #include #include @@ -521,7 +521,7 @@ class MySQL_Session: public Base_Session friend class Base_Session; @@ -611,6 +614,8 @@ class KillArgs { KillArgs(char *u, char *p, char *h, unsigned int P, unsigned int _hid, unsigned long i, int kt, int _use_ssl, MySQL_Thread* _mt, char *ip); ~KillArgs(); const char* get_host_address() const; + KillArgs(const KillArgs&) = delete; + KillArgs& operator=(const KillArgs&) = delete; private: char* ip_addr; @@ -618,5 +623,5 @@ class KillArgs { void * kill_query_thread(void *arg); -#endif /* __CLASS_MYSQL_SESSION_ H */ +#endif /* PROXYSQL_MYSQL_SESSION_H */ #endif // CLASS_BASE_SESSION_H diff --git a/include/MySQL_Set_Stmt_Parser.h b/include/MySQL_Set_Stmt_Parser.h index fd2e77db11..a61048f69a 100644 --- a/include/MySQL_Set_Stmt_Parser.h +++ b/include/MySQL_Set_Stmt_Parser.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_SET_STMT_PARSER_H -#define __CLASS_MYSQL_SET_STMT_PARSER_H +#ifndef PROXYSQL_MYSQL_SET_STMT_PARSER_H +#define PROXYSQL_MYSQL_SET_STMT_PARSER_H #include #include @@ -52,4 +52,4 @@ class MySQL_Set_Stmt_Parser { ~MySQL_Set_Stmt_Parser(); }; -#endif /* __CLASS_MYSQL_SET_STMT_PARSER_H */ +#endif /* PROXYSQL_MYSQL_SET_STMT_PARSER_H */ diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index c7fa1a8174..9078641fd1 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -1,6 +1,6 @@ -#ifndef __CLASS_MYSQL_THREAD_H -#define __CLASS_MYSQL_THREAD_H -#define ____CLASS_STANDARD_MYSQL_THREAD_H +#ifndef PROXYSQL_MYSQL_THREAD_H +#define PROXYSQL_MYSQL_THREAD_H +#define PROXYSQL_STANDARD_MYSQL_THREAD_H #include "prometheus/counter.h" #include "prometheus/gauge.h" @@ -24,9 +24,9 @@ #define MY_EPOLL_THREAD_MAXEVENTS 128 */ -#define ADMIN_HOSTGROUP -2 -#define STATS_HOSTGROUP -3 -#define SQLITE_HOSTGROUP -4 +#define ADMIN_HOSTGROUP (-2) +#define STATS_HOSTGROUP (-3) +#define SQLITE_HOSTGROUP (-4) #define MYSQL_DEFAULT_SESSION_TRACK_GTIDS "OFF" @@ -297,7 +297,7 @@ struct p_th_counter { mysql_killed_backend_connections, mysql_killed_backend_queries, client_host_error_killed_connections, - __size + SIZE_ }; }; @@ -327,7 +327,7 @@ struct p_th_gauge { mysql_monitor_replication_lag_interval, mysql_monitor_replication_lag_timeout, mysql_monitor_history, - __size + SIZE_ }; }; @@ -618,8 +618,8 @@ class MySQL_Threads_Handler unsigned int mirror_sessions_current; int threads_initialized = 0; /// Prometheus metrics arrays - std::array p_counter_array {}; - std::array p_gauge_array {}; + std::array p_counter_array {}; + std::array p_gauge_array {}; } status_variables; std::atomic bootstrapping_listeners; @@ -762,4 +762,4 @@ class MySQL_Threads_Handler }; -#endif /* __CLASS_MYSQL_THREAD_H */ +#endif /* PROXYSQL_MYSQL_THREAD_H */ diff --git a/include/PgSQL_Authentication.h b/include/PgSQL_Authentication.h index 9b053c714e..172a1ac44d 100644 --- a/include/PgSQL_Authentication.h +++ b/include/PgSQL_Authentication.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PGSQL_AUTHENTICATION_H -#define __CLASS_PGSQL_AUTHENTICATION_H +#ifndef PROXYSQL_PGSQL_AUTHENTICATION_H +#define PROXYSQL_PGSQL_AUTHENTICATION_H #include "proxysql.h" #include "cpp.h" @@ -28,9 +28,9 @@ typedef struct _pgsql_account_details_t { bool use_ssl; bool transaction_persistent; bool fast_forward; - bool __frontend; // this is used only during the dump - bool __backend; // this is used only during the dump - bool __active; + bool frontend_; // this is used only during the dump + bool backend_; // this is used only during the dump + bool active_; } pgsql_account_details_t; @@ -113,4 +113,4 @@ class PgSQL_Authentication { SQLite3_result* get_current_pgsql_users(); }; -#endif /* __CLASS_PGSQL_AUTHENTICATION_H */ +#endif /* PROXYSQL_PGSQL_AUTHENTICATION_H */ diff --git a/include/PgSQL_Backend.h b/include/PgSQL_Backend.h index a4cea94dcd..044173b6b6 100644 --- a/include/PgSQL_Backend.h +++ b/include/PgSQL_Backend.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PGSQL_BACKEND_H -#define __CLASS_PGSQL_BACKEND_H +#ifndef PROXYSQL_PGSQL_BACKEND_H +#define PROXYSQL_PGSQL_BACKEND_H #include "proxysql.h" #include "cpp.h" @@ -22,4 +22,4 @@ class PgSQL_Backend void reset(); //< A method that resets and releases resources associated with this backend instance }; -#endif /* __CLASS_PGSQLL_BACKEND_H */ +#endif /* PROXYSQL_PGSQL_BACKEND_H */ diff --git a/include/PgSQL_Connection.h b/include/PgSQL_Connection.h index 9a5365800b..77c1133a50 100644 --- a/include/PgSQL_Connection.h +++ b/include/PgSQL_Connection.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PGSQL_CONNECTION_H -#define __CLASS_PGSQL_CONNECTION_H +#ifndef PROXYSQL_PGSQL_CONNECTION_H +#define PROXYSQL_PGSQL_CONNECTION_H #include "libpq-fe.h" #include "proxysql.h" #include "cpp.h" @@ -740,4 +740,4 @@ class PgSQL_Backend_Kill_Args { void* PgSQL_backend_kill_thread(void* arg); -#endif /* __CLASS_PGSQL_CONNECTION_H */ +#endif /* PROXYSQL_PGSQL_CONNECTION_H */ diff --git a/include/PgSQL_Data_Stream.h b/include/PgSQL_Data_Stream.h index 2ba766d3ba..8b747b15aa 100644 --- a/include/PgSQL_Data_Stream.h +++ b/include/PgSQL_Data_Stream.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PGSQL_DATA_STREAM_H -#define __CLASS_PGSQL_DATA_STREAM_H +#ifndef PROXYSQL_PGSQL_DATA_STREAM_H +#define PROXYSQL_PGSQL_DATA_STREAM_H #include "proxysql.h" #include "cpp.h" @@ -269,4 +269,4 @@ class PgSQL_Data_Stream void reset_connection(); }; -#endif /* __CLASS_PGSQL_DATA_STREAM_H */ +#endif /* PROXYSQL_PGSQL_DATA_STREAM_H */ diff --git a/include/PgSQL_Error_Helper.h b/include/PgSQL_Error_Helper.h index 5ae88da5f8..d76794a0c3 100644 --- a/include/PgSQL_Error_Helper.h +++ b/include/PgSQL_Error_Helper.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PGSQL_ERROR_HELPER_H -#define __CLASS_PGSQL_ERROR_HELPER_H +#ifndef PROXYSQL_PGSQL_ERROR_HELPER_H +#define PROXYSQL_PGSQL_ERROR_HELPER_H #include @@ -380,7 +380,7 @@ struct PgSQL_ErrorInfo { PGSQL_ERROR_CLASS type = PGSQL_ERROR_CLASS::ERRCLASS_UNKNOWN_ERROR; PGSQL_ERROR_CATEGORY category = PGSQL_ERROR_CATEGORY::ERRCATEGORY_UNKNOWN_CATEGORY; char sqlstate[5 + 1] = {}; // 5 bytes for SQLSTATE + 1 for null terminator - PgSQL_ErrorInfo_Ext* ext_info = NULL; + PgSQL_ErrorInfo_Ext* ext_info = nullptr; std::string message; }; @@ -669,4 +669,4 @@ class PgSQL_Error_Helper { #define PGSQL_GET_ERROR_CODE_STR(ENUM_CODE) PgSQL_Error_Helper::get_error_code(PGSQL_ERROR_CODES::ENUM_CODE) -#endif /* __CLASS_PGSQL_ERROR_HELPER_H */ +#endif /* PROXYSQL_PGSQL_ERROR_HELPER_H */ diff --git a/include/PgSQL_HostGroups_Manager.h b/include/PgSQL_HostGroups_Manager.h index 73a9e67db3..195a04359d 100644 --- a/include/PgSQL_HostGroups_Manager.h +++ b/include/PgSQL_HostGroups_Manager.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PGSQL_HOSTGROUPS_MANAGER_H -#define __CLASS_PGSQL_HOSTGROUPS_MANAGER_H +#ifndef PROXYSQL_PGSQL_HOSTGROUPS_MANAGER_H +#define PROXYSQL_PGSQL_HOSTGROUPS_MANAGER_H #include "proxysql.h" #include "cpp.h" #include "proxysql_gtid.h" @@ -146,7 +146,7 @@ class PgSQL_SrvConnList { int find_idx(PgSQL_Connection *c) { //for (unsigned int i=0; ilen; i++) { - PgSQL_Connection *conn = NULL; + PgSQL_Connection *conn = nullptr; conn = (PgSQL_Connection *)conns->index(i); if (conn==c) { return (unsigned int)i; @@ -287,7 +287,7 @@ struct PgSQL_p_hg_counter { pghgm_pgconnpool_reset, pghgm_pgconnpool_destroy, auto_increment_delay_multiplex, - __size + SIZE_ }; }; @@ -295,12 +295,12 @@ struct PgSQL_p_hg_gauge { enum metric { server_connections_connected = 0, client_connections_connected, - __size + SIZE_ }; }; struct PgSQL_p_hg_dyn_counter { - enum metric { + enum metric : uint8_t { conn_pool_bytes_data_recv = 0, conn_pool_bytes_data_sent, connection_pool_conn_err, @@ -309,22 +309,22 @@ struct PgSQL_p_hg_dyn_counter { gtid_executed, proxysql_pgsql_error, pgsql_error, - __size + SIZE_ }; }; -enum class p_pgsql_error_type { +enum class p_pgsql_error_type : uint8_t { pgsql, proxysql }; struct PgSQL_p_hg_dyn_gauge { - enum metric { + enum metric : uint8_t { connection_pool_conn_free = 0, connection_pool_conn_used, connection_pool_latency_us, connection_pool_status, - __size + SIZE_ }; }; @@ -355,7 +355,7 @@ enum PgSQL_READ_ONLY_SERVER_T { PG_ROS_HOSTNAME = 0, PG_ROS_PORT, PG_ROS_READONLY, - PG_ROS__SIZE + PG_ROS_SIZE_ }; enum PgSQL_REPLICATION_LAG_SERVER_T { @@ -363,7 +363,7 @@ enum PgSQL_REPLICATION_LAG_SERVER_T { PG_RLS_ADDRESS, PG_RLS_PORT, PG_RLS_CURRENT_REPLICATION_LAG, - PG_RLS__SIZE + PG_RLS_SIZE_ }; /** @@ -407,10 +407,10 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager { PgSQL_SERVERS_SSL_PARAMS, PgSQL_SERVERS, - __HGM_TABLES_SIZE + HGM_TABLES_SIZE_ }; - std::array table_resultset_checksum { {0} }; + std::array table_resultset_checksum { {0} }; class HostGroup_Server_Mapping { public: @@ -418,11 +418,11 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager { WRITER = 0, READER = 1, - __TYPE_SIZE + TYPE_SIZE_ }; struct Node { - PgSQL_SrvC* srv = NULL; + PgSQL_SrvC* srv = nullptr; unsigned int reader_hostgroup_id = -1; unsigned int writer_hostgroup_id = -1; //MySerStatus server_status = PgSQL_SERVER_STATUS_OFFLINE_HARD; @@ -483,7 +483,7 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager { PgSQL_SrvC* insert_HGM(unsigned int hostgroup_id, const PgSQL_SrvC* srv); void remove_HGM(PgSQL_SrvC* srv); - std::array, __TYPE_SIZE> mapping; // index 0 contains reader and 1 contains writer hostgroups + std::array, TYPE_SIZE_> mapping; // index 0 contains reader and 1 contains writer hostgroups int readonly_flag; PgSQL_HostGroups_Manager* myHGM; }; @@ -639,12 +639,12 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager { ////////////////////////////////////////////////////// /// Prometheus metrics arrays - std::array p_counter_array {}; - std::array p_gauge_array {}; + std::array p_counter_array {}; + std::array p_gauge_array {}; // Prometheus dyn_metrics families arrays - std::array*, PgSQL_p_hg_dyn_counter::__size> p_dyn_counter_array {}; - std::array*, PgSQL_p_hg_dyn_gauge::__size> p_dyn_gauge_array {}; + std::array*, PgSQL_p_hg_dyn_counter::SIZE_> p_dyn_counter_array {}; + std::array*, PgSQL_p_hg_dyn_gauge::SIZE_> p_dyn_gauge_array {}; /// Prometheus connection_pool metrics std::map p_conn_pool_bytes_data_recv_map {}; @@ -829,7 +829,7 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager { void drop_all_idle_connections(); int get_multiple_idle_connections(int, unsigned long long, PgSQL_Connection **, int); - SQLite3_result * SQL3_Connection_Pool(bool _reset, int *hid = NULL); + SQLite3_result * SQL3_Connection_Pool(bool _reset, int *hid = nullptr); SQLite3_result * SQL3_Free_Connections(); void push_MyConn_to_pool(PgSQL_Connection *, bool _lock=true); @@ -864,4 +864,4 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager { }; -#endif /* __CLASS_PGSQL_HOSTGROUPS_MANAGER_H */ +#endif /* PROXYSQL_PGSQL_HOSTGROUPS_MANAGER_H */ diff --git a/include/PgSQL_Logger.hpp b/include/PgSQL_Logger.hpp index ec08ac5b2d..b3e7414773 100644 --- a/include/PgSQL_Logger.hpp +++ b/include/PgSQL_Logger.hpp @@ -20,7 +20,7 @@ class LogBufferThreadContext; * @brief Counter metric indices for PostgreSQL advanced query logging. */ struct p_pl_counter { - enum metric { + enum metric : uint8_t { memory_copy_count = 0, disk_copy_count, get_all_events_calls_count, @@ -32,17 +32,14 @@ struct p_pl_counter { total_events_copied_to_disk, circular_buffer_events_added_count, circular_buffer_events_dropped_count, - __size + SIZE_ }; }; -/** - * @brief Gauge metric indices for PostgreSQL advanced query logging. - */ struct p_pl_gauge { - enum metric { + enum metric : uint8_t { circular_buffer_events_size, - __size + SIZE_ }; }; @@ -272,8 +269,8 @@ class PgSQL_Logger { struct { std::atomic total_queries_logged { 0 }; prometheus::Counter* p_queries_logged_total { nullptr }; - std::array p_counter_array {}; - std::array p_gauge_array {}; + std::array p_counter_array {}; + std::array p_gauge_array {}; } prom_metrics; #ifdef PROXYSQL_LOGGER_PTHREAD_MUTEX pthread_mutex_t wmutex; diff --git a/include/PgSQL_Protocol.h b/include/PgSQL_Protocol.h index fd34f017e3..16895ef8c2 100644 --- a/include/PgSQL_Protocol.h +++ b/include/PgSQL_Protocol.h @@ -1,5 +1,5 @@ -#ifndef __POSTGRES_PROTOCOL_H -#define __POSTGRES_PROTOCOL_H +#ifndef PROXYSQL_PGSQL_PROTOCOL_H +#define PROXYSQL_PGSQL_PROTOCOL_H #include "proxysql.h" #include "gen_utils.h" diff --git a/include/PgSQL_Query_Cache.h b/include/PgSQL_Query_Cache.h index 7210400035..61eb279b48 100644 --- a/include/PgSQL_Query_Cache.h +++ b/include/PgSQL_Query_Cache.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PGSQL_QUERY_CACHE_H -#define __CLASS_PGSQL_QUERY_CACHE_H +#ifndef PROXYSQL_PGSQL_QUERY_CACHE_H +#define PROXYSQL_PGSQL_QUERY_CACHE_H #include "proxysql.h" #include "cpp.h" @@ -19,4 +19,4 @@ class PgSQL_Query_Cache : public Query_Cache { //void* purgeHash_thread(void*); }; -#endif /* __CLASS_PGSQL_QUERY_CACHE_H */ +#endif /* PROXYSQL_PGSQL_QUERY_CACHE_H */ diff --git a/include/PgSQL_Query_Processor.h b/include/PgSQL_Query_Processor.h index 352b86e5af..ca05e4a450 100644 --- a/include/PgSQL_Query_Processor.h +++ b/include/PgSQL_Query_Processor.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PGSQL_QUERY_PROCESSOR_H -#define __CLASS_PGSQL_QUERY_PROCESSOR_H +#ifndef PROXYSQL_PGSQL_QUERY_PROCESSOR_H +#define PROXYSQL_PGSQL_QUERY_PROCESSOR_H #include "proxysql.h" #include "cpp.h" #include "QP_rule_text.h" @@ -42,4 +42,4 @@ class PgSQL_Query_Processor : public Query_Processor { friend class Query_Processor; }; -#endif /* __CLASS_PGSQL_QUERY_PROCESSOR_H */ +#endif /* PROXYSQL_PGSQL_QUERY_PROCESSOR_H */ diff --git a/include/PgSQL_Session.h b/include/PgSQL_Session.h index da6eb47d50..53e36628f5 100644 --- a/include/PgSQL_Session.h +++ b/include/PgSQL_Session.h @@ -1,7 +1,7 @@ #ifdef CLASS_BASE_SESSION_H -#ifndef __CLASS_PGSQL_SESSION_H -#define __CLASS_PGSQL_SESSION_H +#ifndef PROXYSQL_PGSQL_SESSION_H +#define PROXYSQL_PGSQL_SESSION_H #include #include @@ -570,7 +570,7 @@ class PgSQL_Session : public Base_Session #include @@ -39,4 +39,4 @@ class PgSQL_Set_Stmt_Parser { static void unquote_if_quoted(std::string& v); }; -#endif /* __CLASS_PGSQL_SET_STMT_PARSER_H */ +#endif /* PROXYSQL_PGSQL_SET_STMT_PARSER_H */ diff --git a/include/PgSQL_Thread.h b/include/PgSQL_Thread.h index a991212e55..b66b9a18db 100644 --- a/include/PgSQL_Thread.h +++ b/include/PgSQL_Thread.h @@ -1,6 +1,6 @@ -#ifndef __CLASS_PGSQL_THREAD_H -#define __CLASS_PGSQL_THREAD_H -#define ____CLASS_STANDARD_PGSQL_THREAD_H +#ifndef PROXYSQL_PGSQL_THREAD_H +#define PROXYSQL_PGSQL_THREAD_H +#define PROXYSQL_STANDARD_PGSQL_THREAD_H #include #include @@ -41,9 +41,9 @@ constexpr const char* AUTHENTICATION_METHOD_STR[] = { #define MY_EPOLL_THREAD_MAXEVENTS 128 */ -#define ADMIN_HOSTGROUP -2 -#define STATS_HOSTGROUP -3 -#define SQLITE_HOSTGROUP -4 +#define ADMIN_HOSTGROUP (-2) +#define STATS_HOSTGROUP (-3) +#define SQLITE_HOSTGROUP (-4) #define MYSQL_DEFAULT_COLLATION_CONNECTION "" @@ -1731,4 +1731,4 @@ class PgSQL_Threads_Handler }; -#endif /* __CLASS_PGSQL_THREAD_H */ +#endif /* PROXYSQL_PGSQL_THREAD_H */ diff --git a/include/ProxySQL_Cluster.hpp b/include/ProxySQL_Cluster.hpp index 174de64ed9..fb65982df3 100644 --- a/include/ProxySQL_Cluster.hpp +++ b/include/ProxySQL_Cluster.hpp @@ -169,29 +169,29 @@ class ProxySQL_Node_Entry { }; struct p_cluster_nodes_counter { - enum metric { - __size + enum metric : uint8_t { + SIZE_ }; }; struct p_cluster_nodes_gauge { - enum metric { - __size + enum metric : uint8_t { + SIZE_ }; }; struct p_cluster_nodes_dyn_counter { - enum metric { + enum metric : uint8_t { proxysql_servers_checksums_version_total, proxysql_servers_metrics_uptime_s, proxysql_servers_metrics_queries, proxysql_servers_metrics_client_conns_created, - __size + SIZE_ }; }; struct p_cluster_nodes_dyn_gauge { - enum metric { + enum metric : uint8_t { proxysql_servers_checksums_epoch, proxysql_servers_checksums_updated_at, proxysql_servers_checksums_changed_at, @@ -200,7 +200,7 @@ struct p_cluster_nodes_dyn_gauge { proxysql_servers_metrics_response_time_ms, proxysql_servers_metrics_last_check_ms, proxysql_servers_metrics_client_conns_connected, - __size + SIZE_ }; }; @@ -221,8 +221,8 @@ class ProxySQL_Cluster_Nodes { void remove_inactives(); uint64_t generate_hash(char *_hostname, uint16_t _port); struct { - std::array*, p_cluster_nodes_dyn_counter::__size> p_dyn_counter_array {}; - std::array*, p_cluster_nodes_dyn_gauge::__size> p_dyn_gauge_array {}; + std::array*, p_cluster_nodes_dyn_counter::SIZE_> p_dyn_counter_array {}; + std::array*, p_cluster_nodes_dyn_gauge::SIZE_> p_dyn_gauge_array {}; // proxysql_servers_checksum std::map p_proxysql_servers_checksum_version {}; @@ -265,7 +265,7 @@ class ProxySQL_Cluster_Nodes { }; struct p_cluster_counter { - enum metric { + enum metric : uint8_t { pulled_mysql_query_rules_success = 0, pulled_mysql_query_rules_failure, @@ -320,13 +320,13 @@ struct p_cluster_counter { sync_delayed_admin_variables_version_one, sync_delayed_ldap_variables_version_one, - __size + SIZE_ }; }; struct p_cluster_gauge { - enum metric { - __size + enum metric : uint8_t { + SIZE_ }; }; @@ -338,10 +338,10 @@ struct cluster_metrics_map_idx { }; struct variable_type { - enum type { + enum type : uint8_t { mysql, admin, - __size + SIZE_ }; }; @@ -395,8 +395,8 @@ class ProxySQL_Cluster { char* cluster_username; char* cluster_password; struct { - std::array p_counter_array{}; - std::array p_gauge_array{}; + std::array p_counter_array{}; + std::array p_gauge_array{}; } metrics; int fetch_and_store(MYSQL* conn, const fetch_query& f_query, MYSQL_RES** result); friend class ProxySQL_Node_Entry; diff --git a/include/ProxySQL_Poll.h b/include/ProxySQL_Poll.h index 8dbcfc9215..fafeb30a4b 100644 --- a/include/ProxySQL_Poll.h +++ b/include/ProxySQL_Poll.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PROXYSQL_POLL -#define __CLASS_PROXYSQL_POLL +#ifndef PROXYSQL_POLL_H +#define PROXYSQL_POLL_H //#include "MySQL_Data_Stream.h" @@ -20,6 +20,8 @@ class iface_info { free(address); close(fd); } + iface_info(const iface_info&) = delete; + iface_info& operator=(const iface_info&) = delete; }; template diff --git a/include/Query_Cache.h b/include/Query_Cache.h index 4ca64e3273..4294f6ab94 100644 --- a/include/Query_Cache.h +++ b/include/Query_Cache.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_QUERY_CACHE_H -#define __CLASS_QUERY_CACHE_H +#ifndef PROXYSQL_QUERY_CACHE_H +#define PROXYSQL_QUERY_CACHE_H #include "btree_map.h" #include "proxysql.h" #include "cpp.h" @@ -15,7 +15,7 @@ #define DEFAULT_purge_threshold_pct_max 90 struct p_qc_counter { - enum metric { + enum metric : uint8_t { query_cache_count_get = 0, query_cache_count_get_ok, query_cache_count_set, @@ -23,14 +23,14 @@ struct p_qc_counter { query_cache_bytes_out, query_cache_purged, query_cache_entries, - __size + SIZE_ }; }; struct p_qc_gauge { - enum metric { + enum metric : uint8_t { query_cache_memory_bytes = 0, - __size + SIZE_ }; }; @@ -211,9 +211,9 @@ class Query_Cache { void purgeHash(uint64_t QCnow_ms, unsigned int curr_pct); struct { - std::array p_counter_array{}; - std::array p_gauge_array{}; + std::array p_counter_array{}; + std::array p_gauge_array{}; } metrics; }; -#endif /* __CLASS_QUERY_CACHE_H */ +#endif /* PROXYSQL_QUERY_CACHE_H */ diff --git a/include/Servers_SslParams.h b/include/Servers_SslParams.h index 006d33090a..3371b4271d 100644 --- a/include/Servers_SslParams.h +++ b/include/Servers_SslParams.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_SERVERS_SSL_PARAMS_H -#define __CLASS_SERVERS_SSL_PARAMS_H +#ifndef PROXYSQL_SERVERS_SSL_PARAMS_H +#define PROXYSQL_SERVERS_SSL_PARAMS_H #include @@ -24,39 +24,17 @@ class Servers_SslParams { Servers_SslParams(string _h, int _p, string _u, string ca, string cert, string key, string capath, string crl, string crlpath, string cipher, string tls, - string c) { - hostname = _h; - port = _p; - username = _u; - ssl_ca = ca; - ssl_cert = cert; - ssl_key = key; - ssl_capath = capath; - ssl_crl = crl; - ssl_crlpath = crlpath; - ssl_cipher = cipher; - tls_version = tls; - comment = c; - MapKey = ""; - } + string c) + : hostname(_h), port(_p), username(_u), ssl_ca(ca), ssl_cert(cert), + ssl_key(key), ssl_capath(capath), ssl_crl(crl), ssl_crlpath(crlpath), + ssl_cipher(cipher), tls_version(tls), comment(c), MapKey("") {} Servers_SslParams(char * _h, int _p, char * _u, char * ca, char * cert, char * key, char * capath, char * crl, char * crlpath, char * cipher, char * tls, - char * c) { - hostname = string(_h); - port = _p; - username = string(_u); - ssl_ca = string(ca); - ssl_cert = string(cert); - ssl_key = string(key); - ssl_capath = string(capath); - ssl_crl = string(crl); - ssl_crlpath = string(crlpath); - ssl_cipher = string(cipher); - tls_version = string(tls); - comment = string(c); - MapKey = ""; - } + char * c) + : hostname(_h), port(_p), username(_u), ssl_ca(ca), ssl_cert(cert), + ssl_key(key), ssl_capath(capath), ssl_crl(crl), ssl_crlpath(crlpath), + ssl_cipher(cipher), tls_version(tls), comment(c), MapKey("") {} Servers_SslParams(string _h, int _p, string _u) : Servers_SslParams(_h, _p, _u, "", "", "", "", "", "", "", "", "") {} virtual ~Servers_SslParams() = default; diff --git a/include/StatCounters.h b/include/StatCounters.h index c64f310974..b2619a97ec 100644 --- a/include/StatCounters.h +++ b/include/StatCounters.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_STAT_COUNTERS_H -#define __CLASS_STAT_COUNTERS_H +#ifndef PROXYSQL_STAT_COUNTERS_H +#define PROXYSQL_STAT_COUNTERS_H #include "proxysql_atomic.h" class StatCounters { @@ -71,5 +71,5 @@ class StatCounters { return ret; } }; -#endif /* __CLASS_STAT_COUNTERS_H */ +#endif /* PROXYSQL_STAT_COUNTERS_H */ diff --git a/include/gen_utils.h b/include/gen_utils.h index 8556fd468a..9983d7081e 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PTR_ARRAY_H -#define __CLASS_PTR_ARRAY_H +#ifndef PROXYSQL_PTR_ARRAY_H +#define PROXYSQL_PTR_ARRAY_H #include #include @@ -146,21 +146,24 @@ class PtrArray { } void shrink() { unsigned int new_size=l_near_pow_2(len+1); - pdata=(void **)realloc(pdata,new_size*sizeof(void *)); - size=new_size; + void *new_pdata = realloc(pdata, new_size * sizeof(void *)); + if (new_pdata) { + pdata = (void **)new_pdata; + size = new_size; + } } public: unsigned int len; unsigned int size; void **pdata; - PtrArray(unsigned int __size=0) { + explicit PtrArray(unsigned int sz=0) { len=0; pdata=NULL; size=0; - if (__size) { - expand(__size); + if (sz) { + expand(sz); } - size=__size; + size=sz; } ~PtrArray() { if (pdata) ( free(pdata) ); @@ -240,7 +243,7 @@ class PtrSizeArray { unsigned int len; unsigned int size; PtrSize_t *pdata; - PtrSizeArray(unsigned int __size=0); + explicit PtrSizeArray(unsigned int sz=0); ~PtrSizeArray(); void add(void *p, unsigned int s) { @@ -374,7 +377,7 @@ class FixedSizeQueue : public std::queue { } }; -#endif /* __CLASS_PTR_ARRAY_H */ +#endif /* PROXYSQL_PTR_ARRAY_H */ #ifdef CLOCK_MONOTONIC_RAW @@ -383,8 +386,8 @@ class FixedSizeQueue : public std::queue { #define PROXYSQL_CLOCK_MONOTONIC CLOCK_MONOTONIC #endif -#ifndef __GEN_FUNCTIONS -#define __GEN_FUNCTIONS +#ifndef PROXYSQL_GEN_FUNCTIONS +#define PROXYSQL_GEN_FUNCTIONS #ifdef __APPLE__ #include @@ -553,4 +556,4 @@ inline constexpr char* fast_uint32toa(uint32_t value, char* out) noexcept { return p; } -#endif /* __GEN_FUNCTIONS */ +#endif /* PROXYSQL_GEN_FUNCTIONS */ diff --git a/include/log_utils.h b/include/log_utils.h index a333aa77e6..c395ac0c90 100644 --- a/include/log_utils.h +++ b/include/log_utils.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_LOG_UTILS_H -#define __CLASS_LOG_UTILS_H +#ifndef PROXYSQL_LOG_UTILS_H +#define PROXYSQL_LOG_UTILS_H #include #include @@ -218,4 +218,4 @@ bool flush_and_rotate( */ prometheus::Counter* get_logger_queries_logged_counter(const std::string& protocol); -#endif /* __CLASS_LOG_UTILS_H */ +#endif /* PROXYSQL_LOG_UTILS_H */ diff --git a/include/mysql_backend.h b/include/mysql_backend.h index 4b8860e901..f830b645ec 100644 --- a/include/mysql_backend.h +++ b/include/mysql_backend.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_BACKEND_H -#define __CLASS_MYSQL_BACKEND_H +#ifndef PROXYSQL_MYSQL_BACKEND_H +#define PROXYSQL_MYSQL_BACKEND_H #include "proxysql.h" #include "cpp.h" @@ -22,4 +22,4 @@ class MySQL_Backend void reset(); }; -#endif /* __CLASS_MYSQL_BACKEND_H */ +#endif /* PROXYSQL_MYSQL_BACKEND_H */ diff --git a/include/mysql_connection.h b/include/mysql_connection.h index d3d2d21598..ca6320e916 100644 --- a/include/mysql_connection.h +++ b/include/mysql_connection.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_MYSQL_CONNECTION_H -#define __CLASS_MYSQL_CONNECTION_H +#ifndef PROXYSQL_MYSQL_CONNECTION_H +#define PROXYSQL_MYSQL_CONNECTION_H #include "proxysql.h" #include "cpp.h" @@ -276,4 +276,4 @@ class MySQL_Connection { void get_mysql_info_json(nlohmann::json&); void get_backend_conn_info_json(nlohmann::json&); }; -#endif /* __CLASS_MYSQL_CONNECTION_H */ +#endif /* PROXYSQL_MYSQL_CONNECTION_H */ diff --git a/include/prometheus_helpers.h b/include/prometheus_helpers.h index d8ab904c6d..ef6149268e 100644 --- a/include/prometheus_helpers.h +++ b/include/prometheus_helpers.h @@ -1,5 +1,5 @@ -#ifndef __PROXYSQL_PROMETHEUS_HELPERS_H -#define __PROXYSQL_PROMETHEUS_HELPERS_H +#ifndef PROXYSQL_PROMETHEUS_HELPERS_H +#define PROXYSQL_PROMETHEUS_HELPERS_H #include "prometheus/counter.h" #include "prometheus/gauge.h" @@ -19,7 +19,7 @@ using prometheus::Gauge; * @tparam map_idx_enum The enum holding the types of elements contained in the 'metrics_map' argument. * This enum must contain an element '::counters'. * @tparam counters_enum The counters enum, holding all the identifiers of the metrics - * to be initialized in the 'counter_array' argument. It must contains a '::__size' element. + * to be initialized in the 'counter_array' argument. It must contains a '::SIZE_' element. * @tparam metrics_map The type of the metrics map, it should be a 'tuple' holding the following elements: * { * int: metric_identifier, @@ -33,7 +33,7 @@ using prometheus::Gauge; template void init_prometheus_counter_array( const metrics_map& map, - std::array& counter_array + std::array& counter_array ) { for (const auto& metric : std::get(map)) { const auto& tg_metric = std::get<0>(metric); @@ -77,7 +77,7 @@ void init_prometheus_counter_array( * @tparam map_idx_enum The enum holding the types of elements contained in the 'metrics_map' argument. * This enum must contain an element '::gauges'. * @tparam gauges_enum The counters enum, holding all the identifiers of the metrics - * to be initialized in the 'gauge_array' argument. It must contains a '::__size' element. + * to be initialized in the 'gauge_array' argument. It must contains a '::SIZE_' element. * @tparam metrics_map The type of the metrics map, it should be a 'tuple' holding the following elements: * { * int: metric_identifier, @@ -91,7 +91,7 @@ void init_prometheus_counter_array( template void init_prometheus_gauge_array( const metrics_map& map, - std::array& gauge_array + std::array& gauge_array ) { for (const auto& metric : std::get(map)) { const auto& tg_metric = std::get<0>(metric); @@ -135,7 +135,7 @@ void init_prometheus_gauge_array( * @tparam map_idx_enum The enum holding the types of elements contained in the 'metrics_map' argument. * This enum must contain an element '::dyn_counters'. * @tparam dyn_counter_enum The counters enum, holding all the identifiers of the metrics - * to be initialized in the 'dyn_counter_array' argument. It must contains a '::__size' element. + * to be initialized in the 'dyn_counter_array' argument. It must contains a '::SIZE_' element. * @tparam metrics_map The type of the metrics map, it should be a 'tuple' holding the following elements: * { * int: metric_identifier, @@ -149,7 +149,7 @@ void init_prometheus_gauge_array( template void init_prometheus_dyn_counter_array( const metrics_map& map, - std::array*, dyn_counter_enum::__size>& dyn_counter_array + std::array*, dyn_counter_enum::SIZE_>& dyn_counter_array ) { for (const auto& metric : std::get(map)) { const auto& tg_metric = std::get<0>(metric); @@ -191,7 +191,7 @@ void init_prometheus_dyn_counter_array( * @tparam map_idx_enum The enum holding the types of elements contained in the 'metrics_map' argument. * This enum must contain an element '::dyn_gauges'. * @tparam dyn_gauge_enum The 'dyn_gauges' enum, holding all the identifiers of the metrics - * to be initialized in the 'dyn_gauge_array' argument. It must contains a '::__size' element. + * to be initialized in the 'dyn_gauge_array' argument. It must contains a '::SIZE_' element. * @tparam metrics_map The type of the metrics map, it should be a 'tuple' holding the following elements: * { * int: metric_identifier, @@ -205,7 +205,7 @@ void init_prometheus_dyn_counter_array( template void init_prometheus_dyn_gauge_array( const metrics_map& map, - std::array*, gauges_enum::__size>& dyn_gauge_array + std::array*, gauges_enum::SIZE_>& dyn_gauge_array ) { for (const auto& metric : std::get(map)) { const auto& tg_metric = std::get<0>(metric); @@ -337,4 +337,4 @@ inline void p_inc_map_counter( } } -#endif /* __PROXYSQL_PROMETHEUS_HELPERS_H */ +#endif /* PROXYSQL_PROMETHEUS_HELPERS_H */ diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 87dba5016e..ad8ba70cd9 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_PROXYSQL_ADMIN_H -#define __CLASS_PROXYSQL_ADMIN_H +#ifndef PROXYSQL_ADMIN_H +#define PROXYSQL_ADMIN_H #include "prometheus/exposer.h" #include "prometheus/counter.h" @@ -19,9 +19,9 @@ #include "proxysql_typedefs.h" #include "query_digest_topk.h" -#define PROCESSLIST_MAX_QUERY_LEN_DEFAULT 2 * 1024 * 1024 // 2 MiB -#define PROCESSLIST_MAX_QUERY_LEN_MIN 1 * 1024 // 1 KiB -#define PROCESSLIST_MAX_QUERY_LEN_MAX 32 * 1024 * 1024 // 32 MiB +#define PROCESSLIST_MAX_QUERY_LEN_DEFAULT (2 * 1024 * 1024) // 2 MiB +#define PROCESSLIST_MAX_QUERY_LEN_MIN (1 * 1024) // 1 KiB +#define PROCESSLIST_MAX_QUERY_LEN_MAX (32 * 1024 * 1024) // 32 MiB typedef struct { uint32_t hash; uint32_t key; } t_symstruct; class ProxySQL_Config; @@ -65,15 +65,15 @@ class ProxySQL_External_Scheduler { }; struct p_admin_counter { - enum metric { + enum metric : uint8_t { uptime = 0, jemalloc_allocated, - __size + SIZE_ }; }; struct p_admin_gauge { - enum metric { + enum metric : uint8_t { // memory metrics connpool_memory_bytes = 0, sqlite3_memory_bytes, @@ -105,20 +105,20 @@ struct p_admin_gauge { version_info, mysql_listener_paused, pgsql_listener_paused, - __size + SIZE_ }; }; struct p_admin_dyn_counter { - enum metric { - __size + enum metric : uint8_t { + SIZE_ }; }; struct p_admin_dyn_gauge { - enum metric { + enum metric : uint8_t { proxysql_servers_clients_status_last_seen_at = 0, - __size + SIZE_ }; }; @@ -439,9 +439,9 @@ class ProxySQL_Admin { unsigned long long last_p_memory_metrics_ts; struct { - std::array p_counter_array {}; - std::array p_gauge_array {}; - std::array*, p_admin_dyn_gauge::__size> p_dyn_gauge_array {}; + std::array p_counter_array {}; + std::array p_gauge_array {}; + std::array*, p_admin_dyn_gauge::SIZE_> p_dyn_gauge_array {}; std::map p_proxysql_servers_clients_status_map {}; } metrics; @@ -1000,4 +1000,4 @@ class ProxySQL_Admin { void flush_pgsql_stats(); // Reset PostgreSQL statistics only #endif // DEBUG }; -#endif /* __CLASS_PROXYSQL_ADMIN_H */ +#endif /* PROXYSQL_ADMIN_H */ diff --git a/include/proxysql_config.h b/include/proxysql_config.h index 26d6014d49..1f7521c100 100644 --- a/include/proxysql_config.h +++ b/include/proxysql_config.h @@ -1,5 +1,5 @@ -#ifndef __PROXYSQL_CONFIG_H__ -#define __PROXYSQL_CONFIG_H__ +#ifndef PROXYSQL_CONFIG_H +#define PROXYSQL_CONFIG_H #include #include diff --git a/include/proxysql_coredump.h b/include/proxysql_coredump.h index 2843de9acb..b531ce4482 100644 --- a/include/proxysql_coredump.h +++ b/include/proxysql_coredump.h @@ -1,5 +1,5 @@ -#ifndef __PROXYSQL_COREDUMP_H -#define __PROXYSQL_COREDUMP_H +#ifndef PROXYSQL_COREDUMP_H +#define PROXYSQL_COREDUMP_H #include #define S1(x) #x @@ -24,4 +24,4 @@ void proxy_coredump_generate(); }\ } -#endif // __PROXYSQL_COREDUMP_H +#endif /* PROXYSQL_COREDUMP_H */ diff --git a/include/proxysql_debug.h b/include/proxysql_debug.h index 569f92e00f..50233c4a36 100644 --- a/include/proxysql_debug.h +++ b/include/proxysql_debug.h @@ -1,5 +1,5 @@ -#ifndef __PROXYSQL_DEBUG_H -#define __PROXYSQL_DEBUG_H +#ifndef PROXYSQL_DEBUG_H +#define PROXYSQL_DEBUG_H #include #include @@ -171,7 +171,7 @@ class Timer { #define ASSERT_SQLITE_OK(rc, db) \ do { \ - if (rc!=SQLITE_OK) { \ + if ((rc)!=SQLITE_OK) { \ proxy_error( \ "SQLite3 error. Shutting down rc=%d msg='%s'\n", \ rc, db ? (*proxy_sqlite3_errmsg)(db->get_db()) : NULL_DB_MSG); \ @@ -181,7 +181,7 @@ class Timer { #define ASSERT_SQLITE3_OK(rc, db) \ do { \ - if (rc!=SQLITE_OK) { \ + if ((rc)!=SQLITE_OK) { \ proxy_error( \ "SQLite3 error. Shutting down rc=%d msg='%s'\n", \ rc, db ? (*proxy_sqlite3_errmsg)(db) : NULL_DB_MSG); \ @@ -190,9 +190,9 @@ class Timer { } while(0) struct p_debug_dyn_counter { - enum metric { + enum metric : uint8_t { proxysql_message_count = 0, - __size + SIZE_ }; }; diff --git a/include/proxysql_macros.h b/include/proxysql_macros.h index 4d1e4f376f..5aa3f55d70 100644 --- a/include/proxysql_macros.h +++ b/include/proxysql_macros.h @@ -1,10 +1,10 @@ #ifndef PROXYSQL_MACROS_H #define PROXYSQL_MACROS_H -#define strdup_null(__c) ( __c ? strdup(__c) : __c ) +#define strdup_null(__c) ( (__c) ? strdup(__c) : (__c) ) #define char_malloc (char *)malloc -#define free_null(__c) { if(__c) { free(__c); __c=NULL; } } +#define free_null(__c) { if(__c) { free(__c); (__c)=NULL; } } -#define itostr(__s, __i) { __s=char_malloc(32); sprintf(__s, "%lld", __i); } +#define itostr(__s, __i) { (__s)=char_malloc(32); sprintf(__s, "%lld", (__i)); } // fast memory copy forward . Use this instead of memcpy for small buffers #define MEM_COPY_FWD(dst_p, src_p, bytes) \ @@ -53,8 +53,8 @@ // copy 4 bytes #define Copy4B(x,y) \ do { \ - uint32_t *a=(uint32_t *)x; \ - *a=*((uint32_t *)y); \ + uint32_t *a=(uint32_t *)(x); \ + *a=*((uint32_t *)(y)); \ } while(0) #ifndef PROXYSQL_LIKELY diff --git a/include/proxysql_restapi.h b/include/proxysql_restapi.h index 532d3e1b7c..5749a32bd5 100644 --- a/include/proxysql_restapi.h +++ b/include/proxysql_restapi.h @@ -1,5 +1,5 @@ -#ifndef __PROXYSQL_RESTAPI_H__ -#define __PROXYSQL_RESTAPI_H__ +#ifndef PROXYSQL_RESTAPI_H +#define PROXYSQL_RESTAPI_H #include "proxy_defines.h" #include "proxysql.h" @@ -40,4 +40,4 @@ class ProxySQL_Restapi { void save_restapi_runtime_to_database(bool); }; -#endif // #ifndef __PROXYSQL_RESTAPI_H__ +#endif /* PROXYSQL_RESTAPI_H */ diff --git a/include/proxysql_sslkeylog.h b/include/proxysql_sslkeylog.h index 21c5d15e93..7d212e1210 100644 --- a/include/proxysql_sslkeylog.h +++ b/include/proxysql_sslkeylog.h @@ -14,8 +14,8 @@ * @see https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format */ -#ifndef __PROXYSQL_SSLKEYLOG_H -#define __PROXYSQL_SSLKEYLOG_H +#ifndef PROXYSQL_SSLKEYLOG_H +#define PROXYSQL_SSLKEYLOG_H #include "proxysql.h" /** @@ -118,4 +118,4 @@ void proxysql_keylog_write_line_callback(const SSL* ssl, const char* line); */ void proxysql_keylog_set_pgsql_callback(); -#endif // __PROXYSQL_SSLKEYLOG_H +#endif /* PROXYSQL_SSLKEYLOG_H */ diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index 3e4bbb67da..c4c0727dfe 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -357,13 +357,13 @@ struct pgsql_variable_st { const char* alias[2]; // alias for the variable }; -#define IS_PGTRACKED_VAR_OPTION_SET(opt, flag) ((opt & flag) == flag) -#define IS_PGTRACKED_VAR_OPTION_UNSET(opt, flag) ((opt & flag) == 0) +#define IS_PGTRACKED_VAR_OPTION_SET(opt, flag) (((opt) & (flag)) == (flag)) +#define IS_PGTRACKED_VAR_OPTION_UNSET(opt, flag) (((opt) & (flag)) == 0) -#define IS_PGTRACKED_VAR_OPTION_SET_QUOTE(opt) IS_PGTRACKED_VAR_OPTION_SET(opt.options, PGTRACKED_VAR_OPT_QUOTE) -#define IS_PGTRACKED_VAR_OPTION_SET_SET_TRANSACTION(opt) IS_PGTRACKED_VAR_OPTION_SET(opt.options, PGTRACKED_VAR_OPT_SET_TRANSACTION) -#define IS_PGTRACKED_VAR_OPTION_SET_PARAM_STATUS(opt) IS_PGTRACKED_VAR_OPTION_SET(opt.options, PGTRACKED_VAR_OPT_PARAM_STATUS) -#define IS_PGTRACKED_VAR_OPTION_SET_NO_STRIP_VALUE(opt) IS_PGTRACKED_VAR_OPTION_SET(opt.options, PGTRACKED_VAR_OPT_NO_STRIP_VALUE) +#define IS_PGTRACKED_VAR_OPTION_SET_QUOTE(opt) IS_PGTRACKED_VAR_OPTION_SET((opt).options, PGTRACKED_VAR_OPT_QUOTE) +#define IS_PGTRACKED_VAR_OPTION_SET_SET_TRANSACTION(opt) IS_PGTRACKED_VAR_OPTION_SET((opt).options, PGTRACKED_VAR_OPT_SET_TRANSACTION) +#define IS_PGTRACKED_VAR_OPTION_SET_PARAM_STATUS(opt) IS_PGTRACKED_VAR_OPTION_SET((opt).options, PGTRACKED_VAR_OPT_PARAM_STATUS) +#define IS_PGTRACKED_VAR_OPTION_SET_NO_STRIP_VALUE(opt) IS_PGTRACKED_VAR_OPTION_SET((opt).options, PGTRACKED_VAR_OPT_NO_STRIP_VALUE) inline bool variable_name_exists(const pgsql_variable_st& var, const char* variable_name) { diff --git a/include/proxysql_utils.h b/include/proxysql_utils.h index 0ac6cab5ca..7937635f76 100644 --- a/include/proxysql_utils.h +++ b/include/proxysql_utils.h @@ -1,5 +1,5 @@ -#ifndef __PROXYSQL_UTILS_H -#define __PROXYSQL_UTILS_H +#ifndef PROXYSQL_UTILS_H +#define PROXYSQL_UTILS_H #include #include diff --git a/include/query_digest_topk.h b/include/query_digest_topk.h index 0e2325bce8..c32b779dd8 100644 --- a/include/query_digest_topk.h +++ b/include/query_digest_topk.h @@ -1,5 +1,5 @@ -#ifndef __PROXYSQL_QUERY_DIGEST_TOPK_H -#define __PROXYSQL_QUERY_DIGEST_TOPK_H +#ifndef PROXYSQL_QUERY_DIGEST_TOPK_H +#define PROXYSQL_QUERY_DIGEST_TOPK_H #include #include diff --git a/include/query_processor.h b/include/query_processor.h index 71b3ee8f4a..daa89ea350 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_QUERY_PROCESSOR_H -#define __CLASS_QUERY_PROCESSOR_H +#ifndef PROXYSQL_QUERY_PROCESSOR_H +#define PROXYSQL_QUERY_PROCESSOR_H #include #include #include "proxysql.h" @@ -185,7 +185,7 @@ class Query_Processor_Output { l_free(sizeof(Query_Processor_Output),ptr); } Query_Processor_Output() { - //init(); + init(); } ~Query_Processor_Output() { //destroy(); @@ -480,4 +480,4 @@ class Query_Processor { friend Web_Interface_plugin; }; -#endif /* __CLASS_QUERY_PROCESSOR_H */ +#endif /* PROXYSQL_QUERY_PROCESSOR_H */ diff --git a/include/sqlite3db.h b/include/sqlite3db.h index 2693b59e93..37807ad7f5 100644 --- a/include/sqlite3db.h +++ b/include/sqlite3db.h @@ -1,5 +1,5 @@ -#ifndef __CLASS_SQLITE3DB_H -#define __CLASS_SQLITE3DB_H +#ifndef PROXYSQL_SQLITE3DB_H +#define PROXYSQL_SQLITE3DB_H #include #include "sqlite3.h" #undef swap @@ -247,4 +247,4 @@ class SQLite3DB { static void LoadPlugin(const char *); }; -#endif /* __CLASS_SQLITE3DB_H */ +#endif /* PROXYSQL_SQLITE3DB_H */ diff --git a/lib/ClickHouse_Authentication.cpp b/lib/ClickHouse_Authentication.cpp index ae41665f6f..e21485e6ff 100644 --- a/lib/ClickHouse_Authentication.cpp +++ b/lib/ClickHouse_Authentication.cpp @@ -48,7 +48,7 @@ void ClickHouse_Authentication::set_all_inactive(enum cred_username_type usertyp unsigned int i; for (i=0; ilen; i++) { ch_account_details_t *ado=(ch_account_details_t *)cg.cred_array->index(i); - ado->__active=false; + ado->active_=false; } #ifdef PROXYSQL_AUTH_PTHREAD_MUTEX pthread_rwlock_unlock(&cg.lock); @@ -68,7 +68,7 @@ void ClickHouse_Authentication::remove_inactives(enum cred_username_type usertyp __loop_remove_inactives: for (i=0; ilen; i++) { ch_account_details_t *ado=(ch_account_details_t *)cg.cred_array->index(i); - if (ado->__active==false) { + if (ado->active_==false) { del(ado->username,usertype,false); goto __loop_remove_inactives; // we aren't sure how the underlying structure changes, so we jump back to 0 } @@ -129,7 +129,7 @@ bool ClickHouse_Authentication::add(char * username, char * password, enum cred_ ad->transaction_persistent=transaction_persistent; ad->fast_forward=fast_forward; ad->max_connections=max_connections; - ad->__active=true; + ad->active_=true; if (new_ad) { cg.bt_map.insert(std::make_pair(hash1,ad)); cg.cred_array->add(ad); @@ -180,8 +180,8 @@ int ClickHouse_Authentication::dump_all_users(ch_account_details_t ***ads, bool ad->schema_locked=ado->schema_locked; ad->transaction_persistent=ado->transaction_persistent; ad->fast_forward=ado->fast_forward; - ad->__frontend=1; - ad->__backend=0; + ad->frontend_=1; + ad->backend_=0; } _ads[idx_]=ad; idx_++; @@ -201,8 +201,8 @@ int ClickHouse_Authentication::dump_all_users(ch_account_details_t ***ads, bool ad->transaction_persistent=ado->transaction_persistent; ad->fast_forward=ado->fast_forward; ad->max_connections=ado->max_connections; - ad->__frontend=0; - ad->__backend=1; + ad->frontend_=0; + ad->backend_=1; _ads[idx_]=ad; idx_++; } diff --git a/lib/MySQL_Authentication.cpp b/lib/MySQL_Authentication.cpp index 59e4719dd1..cb571623dd 100644 --- a/lib/MySQL_Authentication.cpp +++ b/lib/MySQL_Authentication.cpp @@ -23,10 +23,6 @@ void free_account_details(account_details_t& ad) { free(ad.sha1_pass); ad.sha1_pass=NULL; } - if (ad.password) { - free(ad.password); - ad.password = nullptr; - } if (ad.clear_text_password[PASSWORD_TYPE::PRIMARY]) { free(ad.clear_text_password[PASSWORD_TYPE::PRIMARY]); ad.clear_text_password[PASSWORD_TYPE::PRIMARY] = nullptr; @@ -89,7 +85,7 @@ void MySQL_Authentication::set_all_inactive(enum cred_username_type usertype) { unsigned int i; for (i=0; ilen; i++) { account_details_t *ado=(account_details_t *)cg.cred_array->index(i); - ado->__active=false; + ado->active_=false; } #ifdef PROXYSQL_AUTH_PTHREAD_MUTEX pthread_rwlock_unlock(&cg.lock); @@ -109,7 +105,7 @@ void MySQL_Authentication::remove_inactives(enum cred_username_type usertype) { __loop_remove_inactives: for (i=0; ilen; i++) { account_details_t *ado=(account_details_t *)cg.cred_array->index(i); - if (ado->__active==false) { + if (ado->active_==false) { del(ado->username,usertype,false); goto __loop_remove_inactives; // we aren't sure how the underlying structure changes, so we jump back to 0 } @@ -255,7 +251,7 @@ bool MySQL_Authentication::add(char * username, char * password, enum cred_usern ad->transaction_persistent=transaction_persistent; ad->fast_forward=fast_forward; ad->max_connections=max_connections; - ad->__active=true; + ad->active_=true; if (new_ad) { cg.bt_map.insert(std::make_pair(hash1,ad)); cg.cred_array->add(ad); @@ -362,8 +358,8 @@ int MySQL_Authentication::dump_all_users(account_details_t ***ads, bool _complet ad->schema_locked=ado->schema_locked; ad->transaction_persistent=ado->transaction_persistent; ad->fast_forward=ado->fast_forward; - ad->__frontend=1; - ad->__backend=0; + ad->frontend_=1; + ad->backend_=0; } _ads[idx_]=ad; idx_++; @@ -387,8 +383,8 @@ int MySQL_Authentication::dump_all_users(account_details_t ***ads, bool _complet ad->transaction_persistent=ado->transaction_persistent; ad->fast_forward=ado->fast_forward; ad->max_connections=ado->max_connections; - ad->__frontend=0; - ad->__backend=1; + ad->frontend_=0; + ad->backend_=1; _ads[idx_]=ad; idx_++; } @@ -820,15 +816,15 @@ static pair extract_accounts_details(MYSQL_RES* resultset, acc_details->username = row[0]; acc_details->password = row[1] ? row[1] : const_cast(""); - acc_details->__active = true; + acc_details->active_ = true; acc_details->use_ssl = strcmp(row[2], "1") == 0 ? true : false; acc_details->default_hostgroup = atoi(row[3]); acc_details->default_schema = row[4] ? row[4] : const_cast(""); acc_details->schema_locked = strcmp(row[5], "1") == 0 ? true : false; acc_details->transaction_persistent = strcmp(row[6], "1") == 0 ? true : false; acc_details->fast_forward = strcmp(row[7], "1") == 0 ? true : false; - acc_details->__backend = strcmp(row[8], "1") == 0 ? true : false; - acc_details->__frontend = strcmp(row[9], "1") == 0 ? true : false; + acc_details->backend_ = strcmp(row[8], "1") == 0 ? true : false; + acc_details->frontend_ = strcmp(row[9], "1") == 0 ? true : false; acc_details->max_connections = atoi(row[10]); acc_details->attributes = row[11] ? row[11] : const_cast(""); acc_details->comment = row[12] ? row[12] : const_cast(""); diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index d626addfc1..59ce982001 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -1048,10 +1048,10 @@ void MySQL_HostGroups_Manager::update_hostgroup_manager_mappings() { if (itr == hostgroup_server_mapping.end()) { std::unique_ptr server_mapping(new HostGroup_Server_Mapping(this)); - fetched_server_mapping = server_mapping.get(); hostgroup_server_mapping.insert( std::pair> { server_id, std::move(server_mapping) } ); + fetched_server_mapping = hostgroup_server_mapping.at(server_id).get(); } else { fetched_server_mapping = itr->second.get(); } @@ -1877,7 +1877,7 @@ void MySQL_HostGroups_Manager::generate_mysql_servers_table(int *_onlyhg) { st=(char *)"SHUNNED"; break; } - fprintf(stderr,"HID: %d , address: %s , port: %d , gtid_port: %d , weight: %ld , status: %s , max_connections: %ld , max_replication_lag: %u , use_ssl: %u , max_latency_ms: %u , comment: %s\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, mysrvc->gtid_port, mysrvc->weight, st, mysrvc->max_connections, mysrvc->max_replication_lag, mysrvc->use_ssl, mysrvc->max_latency_us*1000, mysrvc->comment); + fprintf(stderr,"HID: %u , address: %s , port: %d , gtid_port: %d , weight: %ld , status: %s , max_connections: %ld , max_replication_lag: %u , use_ssl: %d , max_latency_ms: %u , comment: %s\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, mysrvc->gtid_port, mysrvc->weight, st, mysrvc->max_connections, mysrvc->max_replication_lag, mysrvc->use_ssl, mysrvc->max_latency_us*1000, mysrvc->comment); } lst->add(mysrvc); if (lst->len==32) { @@ -2018,7 +2018,7 @@ void MySQL_HostGroups_Manager::generate_mysql_group_replication_hostgroups_table for (std::map::iterator it1 = Group_Replication_Info_Map.begin() ; it1 != Group_Replication_Info_Map.end(); ++it1) { Group_Replication_Info *info=NULL; info=it1->second; - info->__active=false; + info->active_=false; } for (std::vector::iterator it = incoming_group_replication_hostgroups->rows.begin() ; it != incoming_group_replication_hostgroups->rows.end(); ++it) { SQLite3_row *r=*it; @@ -2066,7 +2066,7 @@ void MySQL_HostGroups_Manager::generate_mysql_group_replication_hostgroups_table // remove missing ones for (auto it3 = Group_Replication_Info_Map.begin(); it3 != Group_Replication_Info_Map.end(); ) { Group_Replication_Info *info=it3->second; - if (info->__active==false) { + if (info->active_==false) { delete info; it3 = Group_Replication_Info_Map.erase(it3); } else { @@ -2117,7 +2117,7 @@ void MySQL_HostGroups_Manager::generate_mysql_galera_hostgroups_table() { for (std::map::iterator it1 = Galera_Info_Map.begin() ; it1 != Galera_Info_Map.end(); ++it1) { Galera_Info *info=NULL; info=it1->second; - info->__active=false; + info->active_=false; } for (std::vector::iterator it = incoming_galera_hostgroups->rows.begin() ; it != incoming_galera_hostgroups->rows.end(); ++it) { SQLite3_row *r=*it; @@ -2165,7 +2165,7 @@ void MySQL_HostGroups_Manager::generate_mysql_galera_hostgroups_table() { // remove missing ones for (auto it3 = Galera_Info_Map.begin(); it3 != Galera_Info_Map.end(); ) { Galera_Info *info=it3->second; - if (info->__active==false) { + if (info->active_==false) { delete info; it3 = Galera_Info_Map.erase(it3); } else { @@ -2335,7 +2335,7 @@ void MySQL_HostGroups_Manager::push_MyConn_to_pool(MySQL_Connection *c, bool _lo } // If the largest query length exceeds the threshold, destroy the connection - if (c->largest_query_length > (unsigned int)GloMTH->variables.threshold_query_length) { + if (GloMTH && c->largest_query_length > (unsigned int)GloMTH->variables.threshold_query_length) { proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Destroying MySQL_Connection %p, server %s:%d with status %d . largest_query_length = %lu\n", c, mysrvc->address, mysrvc->port, (int)mysrvc->get_status(), c->largest_query_length); delete c; goto __exit_push_MyConn_to_pool; @@ -3578,8 +3578,9 @@ void MySQL_HostGroups_Manager::read_only_action_v2(const std::listsecond.get(); - if (!host_server_mapping) - assert(0); + if (!host_server_mapping) { + continue; + } const std::vector& writer_map = host_server_mapping->get(HostGroup_Server_Mapping::Type::WRITER); @@ -3988,7 +3989,7 @@ Group_Replication_Info::Group_Replication_Info(int w, int b, int r, int o, int m current_num_backup_writers=0; current_num_readers=0; current_num_offline=0; - __active=true; + active_=true; need_converge=true; } @@ -4001,7 +4002,7 @@ Group_Replication_Info::~Group_Replication_Info() { bool Group_Replication_Info::update(int b, int r, int o, int mw, int mtb, bool _a, int _w, char *c) { bool ret=false; - __active=true; + active_=true; if (backup_writer_hostgroup!=b) { backup_writer_hostgroup=b; ret=true; @@ -4681,7 +4682,7 @@ Galera_Info::Galera_Info(int w, int b, int r, int o, int mw, int mtb, bool _a, i current_num_backup_writers=0; current_num_readers=0; current_num_offline=0; - __active=true; + active_=true; need_converge=true; } @@ -4694,7 +4695,7 @@ Galera_Info::~Galera_Info() { bool Galera_Info::update(int b, int r, int o, int mw, int mtb, bool _a, int _w, char *c) { bool ret=false; - __active=true; + active_=true; if (backup_writer_hostgroup!=b) { backup_writer_hostgroup=b; ret=true; @@ -4988,13 +4989,14 @@ void MySQL_HostGroups_Manager::update_galera_set_read_only(char *_hostname, int mydb->execute("DELETE FROM mysql_servers_incoming"); mydb->execute("INSERT INTO mysql_servers_incoming SELECT hostgroup_id, hostname, port, gtid_port, weight, status, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM mysql_servers"); q=(char *)"UPDATE OR IGNORE mysql_servers_incoming SET hostgroup_id=%d WHERE hostname='%s' AND port=%d AND hostgroup_id in (%d, %d, %d)"; - query=(char *)malloc(strlen(q)+strlen(_hostname)+512); + size_t qsz = strlen(q)+strlen(_hostname)+512; + query=(char *)malloc(qsz); sprintf(query, q, info->reader_hostgroup, _hostname, _port, info->writer_hostgroup, info->backup_writer_hostgroup, info->offline_hostgroup); mydb->execute(query); //free(query); - q=(char *)"DELETE FROM mysql_servers_incoming WHERE hostname='%s' AND port=%d AND hostgroup_id in (%d, %d, %d)"; + q="DELETE FROM mysql_servers_incoming WHERE hostname='%s' AND port=%d AND hostgroup_id in (%d, %d, %d)"; //query=(char *)malloc(strlen(q)+strlen(_hostname)+64); - sprintf(query,q,_hostname,_port, info->offline_hostgroup, info->backup_writer_hostgroup, info->writer_hostgroup, info->writer_hostgroup); + snprintf(query, qsz, q, _hostname, _port, info->offline_hostgroup, info->backup_writer_hostgroup, info->writer_hostgroup); mydb->execute(query); //free(query); q=(char *)"UPDATE mysql_servers_incoming SET status=0 WHERE hostname='%s' AND port=%d AND hostgroup_id=%d"; @@ -5697,6 +5699,8 @@ class MySQL_Errors_stats { } free(pta); } + MySQL_Errors_stats(const MySQL_Errors_stats&) = delete; + MySQL_Errors_stats& operator=(const MySQL_Errors_stats&) = delete; }; void MySQL_HostGroups_Manager::add_mysql_errors(int hostgroup, char *hostname, int port, char *username, char *address, char *schemaname, int err_no, char *last_error) { @@ -5800,7 +5804,7 @@ AWS_Aurora_Info::AWS_Aurora_Info(int w, int r, int _port, char *_end_addr, int m writer_is_also_reader=wiar; new_reader_weight=nrw; active=_a; - __active=true; + active_=true; //need_converge=true; aurora_port = _port; domain_name = strdup(_end_addr); @@ -5819,7 +5823,7 @@ AWS_Aurora_Info::~AWS_Aurora_Info() { bool AWS_Aurora_Info::update(int r, int _port, char *_end_addr, int maxl, int al, int minl, int lnc, int ci, int ct, bool _a, int wiar, int nrw, char *c) { bool ret=false; - __active=true; + active_=true; if (reader_hostgroup!=r) { reader_hostgroup=r; ret=true; @@ -6174,7 +6178,7 @@ void MySQL_HostGroups_Manager::generate_mysql_aws_aurora_hostgroups_table() { for (std::map::iterator it1 = AWS_Aurora_Info_Map.begin() ; it1 != AWS_Aurora_Info_Map.end(); ++it1) { AWS_Aurora_Info *info=NULL; info=it1->second; - info->__active=false; + info->active_=false; } for (std::vector::iterator it = incoming_aws_aurora_hostgroups->rows.begin() ; it != incoming_aws_aurora_hostgroups->rows.end(); ++it) { SQLite3_row *r=*it; @@ -6232,7 +6236,7 @@ void MySQL_HostGroups_Manager::generate_mysql_aws_aurora_hostgroups_table() { // remove missing ones for (auto it3 = AWS_Aurora_Info_Map.begin(); it3 != AWS_Aurora_Info_Map.end(); ) { AWS_Aurora_Info *info=it3->second; - if (info->__active==false) { + if (info->active_==false) { delete info; it3 = AWS_Aurora_Info_Map.erase(it3); } else { diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index 7b3274aa2f..1c027ee7ec 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1172,9 +1172,9 @@ void ch_account_to_my(account_details_t& account, ch_account_details_t& ch_accou account.num_connections_used_addl_pass = 0; // Assuming no additional password used account.clear_text_password[0] = nullptr; // No clear text passwords by default account.clear_text_password[1] = nullptr; - account.__frontend = ch_account.__frontend; // Copy frontend flag - account.__backend = ch_account.__backend; // Copy backend flag - account.__active = ch_account.__active; // Copy active flag + account.frontend_ = ch_account.frontend_; // Copy frontend flag + account.backend_ = ch_account.backend_; // Copy backend flag + account.active_ = ch_account.active_; // Copy active flag account.attributes = nullptr; // No attributes by default account.comment = nullptr; // No comment by default } diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 5ef07a0a51..623c0461da 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -202,9 +202,9 @@ KillArgs::KillArgs(char* u, char* p, char* h, unsigned int P, unsigned int _hid, } KillArgs::KillArgs(char* u, char* p, char* h, unsigned int P, unsigned int _hid, unsigned long i, int kt, int _use_ssl, MySQL_Thread *_mt, char *ip) { - username=strdup(u); - password=strdup(p); - hostname=strdup(h); + username=u ? strdup(u) : nullptr; + password=p ? strdup(p) : nullptr; + hostname=h ? strdup(h) : nullptr; ip_addr = NULL; if (ip) ip_addr = strdup(ip); @@ -363,7 +363,9 @@ extern MySQL_Threads_Handler *GloMTH; * @brief Default constructor. * Initializes all member variables to their default values. */ -Query_Info::Query_Info() { +Query_Info::Query_Info() + : sess(nullptr), mysql_stmt(nullptr), stmt_meta(nullptr), stmt_global_id(0) +{ MyComQueryCmd=MYSQL_COM_QUERY___NONE; QueryPointer=NULL; QueryLength=0; @@ -2658,7 +2660,7 @@ bool MySQL_Session::handler_again___status_SETTING_GENERIC_VARIABLE(int *_rc, co break; } } - if (idx != SQL_NAME_LAST_LOW_WM) { + if (idx >= 0 && idx < SQL_NAME_LAST_HIGH_WM) { myconn->var_absent[idx] = true; myds->myconn->async_free_result(); @@ -3347,7 +3349,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C string nqn = string((char *)CurrentQuery.QueryPointer,l); char *err_msg = (char *)"Session trying to reach HG %d while locked on HG %d . Rejecting query: %s"; char *buf = (char *)malloc(strlen(err_msg)+strlen(nqn.c_str())+strlen(end)+64); - sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str(), end); + sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str()); client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,9005,(char *)"HY000",buf, true); thread->status_variables.stvar[st_var_hostgroup_locked_queries]++; RequestEnd(NULL, 9005, buf); @@ -3520,7 +3522,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C string nqn = string((char *)CurrentQuery.stmt_info->query,l); char *err_msg = (char *)"Session trying to reach HG %d while locked on HG %d . Rejecting query: %s"; char *buf = (char *)malloc(strlen(err_msg)+strlen(nqn.c_str())+strlen(end)+64); - sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str(), end); + sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str()); client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,9005,(char *)"HY000",buf, true); thread->status_variables.stvar[st_var_hostgroup_locked_queries]++; RequestEnd(NULL, 9005, buf); @@ -5392,7 +5394,7 @@ int MySQL_Session::get_pkts_from_client(bool& wrong_pass, PtrSize_t& pkt) { string nqn = string((char *)CurrentQuery.QueryPointer,l); char *err_msg = (char *)"Session trying to reach HG %d while locked on HG %d . Rejecting query: %s"; char *buf = (char *)malloc(strlen(err_msg)+strlen(nqn.c_str())+strlen(end)+64); - sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str(), end); +sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str()); client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,9005,(char *)"HY000",buf, true); thread->status_variables.stvar[st_var_hostgroup_locked_queries]++; RequestEnd(NULL, 9005, buf); @@ -9570,10 +9572,10 @@ char* MySQL_Session::get_current_query(int max_length) { if (query_len > 0) { res = (char *) malloc(query_len + 1); - if (trunc_query) { - // for truncated queries, add three dots at the end - memcpy(res, query_ptr, query_len - 3); - memcpy(res + (query_len - 3), "...", 3); + if (trunc_query && query_len >= 4) { + size_t cp_len = (size_t)query_len - 3; + memcpy(res, query_ptr, cp_len); + memcpy(res + cp_len, "...", 3); } else { strncpy(res, query_ptr, query_len); } diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 93f6059079..bf99265344 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -6117,7 +6117,7 @@ unsigned long long MySQL_Threads_Handler::get_status_variable( } } #endif // IDLE_THREADS - if (m_idx != p_th_counter::__size) { + if (m_idx != p_th_counter::SIZE_) { const auto& cur_val = status_variables.p_counter_array[m_idx]->Value(); double final_val = 0; @@ -6158,7 +6158,7 @@ unsigned long long MySQL_Threads_Handler::get_status_variable( } } #endif // IDLE_THREADS - if (m_idx != p_th_gauge::__size) { + if (m_idx != p_th_gauge::SIZE_) { double final_val = 0; if (conv != 0) { diff --git a/lib/PgSQL_Authentication.cpp b/lib/PgSQL_Authentication.cpp index 102bc3f65d..0abdae0e3c 100644 --- a/lib/PgSQL_Authentication.cpp +++ b/lib/PgSQL_Authentication.cpp @@ -54,7 +54,7 @@ void PgSQL_Authentication::set_all_inactive(enum cred_username_type usertype) { unsigned int i; for (i=0; ilen; i++) { pgsql_account_details_t *ado=(pgsql_account_details_t *)cg.cred_array->index(i); - ado->__active=false; + ado->active_=false; } #ifdef PROXYSQL_AUTH_PTHREAD_MUTEX pthread_rwlock_unlock(&cg.lock); @@ -74,7 +74,7 @@ void PgSQL_Authentication::remove_inactives(enum cred_username_type usertype) { __loop_remove_inactives: for (i=0; ilen; i++) { pgsql_account_details_t *ado=(pgsql_account_details_t *)cg.cred_array->index(i); - if (ado->__active==false) { + if (ado->active_==false) { del(ado->username,usertype,false); goto __loop_remove_inactives; // we aren't sure how the underlying structure changes, so we jump back to 0 } @@ -201,7 +201,7 @@ bool PgSQL_Authentication::add(char * username, char * password, enum cred_usern ad->transaction_persistent=transaction_persistent; ad->fast_forward=fast_forward; ad->max_connections=max_connections; - ad->__active=true; + ad->active_=true; if (new_ad) { cg.bt_map.insert(std::make_pair(hash1,ad)); cg.cred_array->add(ad); @@ -297,8 +297,8 @@ int PgSQL_Authentication::dump_all_users(pgsql_account_details_t***ads, bool _co ad->comment=strdup(ado->comment); ad->transaction_persistent=ado->transaction_persistent; ad->fast_forward=ado->fast_forward; - ad->__frontend=1; - ad->__backend=0; + ad->frontend_=1; + ad->backend_=0; } _ads[idx_]=ad; idx_++; @@ -318,8 +318,8 @@ int PgSQL_Authentication::dump_all_users(pgsql_account_details_t***ads, bool _co ad->transaction_persistent=ado->transaction_persistent; ad->fast_forward=ado->fast_forward; ad->max_connections=ado->max_connections; - ad->__frontend=0; - ad->__backend=1; + ad->frontend_=0; + ad->backend_=1; _ads[idx_]=ad; idx_++; } @@ -653,13 +653,13 @@ static pair extract_accounts_details(MYSQL_RES* result acc_details->username = row[0]; acc_details->password = row[1] ? row[1] : const_cast(""); - acc_details->__active = true; + acc_details->active_ = true; acc_details->use_ssl = strcmp(row[2], "1") == 0 ? true : false; acc_details->default_hostgroup = atoi(row[3]); acc_details->transaction_persistent = strcmp(row[4], "1") == 0 ? true : false; acc_details->fast_forward = strcmp(row[5], "1") == 0 ? true : false; - acc_details->__backend = strcmp(row[6], "1") == 0 ? true : false; - acc_details->__frontend = strcmp(row[7], "1") == 0 ? true : false; + acc_details->backend_ = strcmp(row[6], "1") == 0 ? true : false; + acc_details->frontend_ = strcmp(row[7], "1") == 0 ? true : false; acc_details->max_connections = atoi(row[8]); acc_details->attributes = row[9] ? row[9] : const_cast(""); acc_details->comment = row[10] ? row[10] : const_cast(""); diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 8ac1b0309b..a977373b15 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -6747,7 +6747,7 @@ void ProxySQL_Admin::save_mysql_users_runtime_to_database(bool _runtime) { sqlite3_stmt *statement1=NULL; if (ads[i]->default_hostgroup >= 0) { - if (ad->__frontend) { + if (ad->frontend_) { statement1=f_statement1; } else { statement1=b_statement1; @@ -6830,13 +6830,13 @@ void ProxySQL_Admin::save_pgsql_users_runtime_to_database(bool _runtime) { /* char *q=NULL; if (_runtime==false) { - if (ad->__frontend) { + if (ad->frontend_) { q=qf; } else { q=qb; } } else { // _runtime==true - if (ad->__frontend) { + if (ad->frontend_) { q=qfr; statement1=f_statement1; } else { @@ -6845,7 +6845,7 @@ void ProxySQL_Admin::save_pgsql_users_runtime_to_database(bool _runtime) { } } */ - if (ad->__frontend) { + if (ad->frontend_) { statement1 = f_statement1; } else { @@ -7068,13 +7068,13 @@ void ProxySQL_Admin::save_clickhouse_users_runtime_to_database(bool _runtime) { if (ads[i]->default_hostgroup >= 0) { char *q=NULL; if (_runtime==false) { - if (ad->__frontend) { + if (ad->frontend_) { q=qf; } else { q=qb; } } else { // _runtime==true - if (ad->__frontend) { + if (ad->frontend_) { q=qfr; statement1=f_statement1; } else { diff --git a/lib/debug.cpp b/lib/debug.cpp index c5b1a77803..842f92d477 100644 --- a/lib/debug.cpp +++ b/lib/debug.cpp @@ -341,7 +341,7 @@ const std::tuple debug_metrics_map = std::make_tuple( ); std::map p_proxysql_messages_map {}; -std::array*, p_debug_dyn_counter::__size> p_debug_dyn_counter_array {}; +std::array*, p_debug_dyn_counter::SIZE_> p_debug_dyn_counter_array {}; std::mutex msg_stats_mutex {}; const int ProxySQL_MSG_STATS_FIELD_NUM = 7; diff --git a/scripts/lint/generate-compile-commands.sh b/scripts/lint/generate-compile-commands.sh new file mode 100755 index 0000000000..77b5b4c707 --- /dev/null +++ b/scripts/lint/generate-compile-commands.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail +# Generate compile_commands.json by wrapping make with Bear. +# Usage: ./generate-compile-commands.sh + +BUILD_CMD=${1:-"make -j$(nproc)"} + +if ! command -v bear >/dev/null 2>&1; then + echo "bear is required. Install it (e.g. apt install bear)" >&2 + exit 1 +fi + +echo "Running: bear -- ${BUILD_CMD}" +rm -f compile_commands.json +bear -- ${BUILD_CMD} +echo "compile_commands.json generated" diff --git a/scripts/lint/normalize-clang-tidy.py b/scripts/lint/normalize-clang-tidy.py new file mode 100755 index 0000000000..dcbf7289d6 --- /dev/null +++ b/scripts/lint/normalize-clang-tidy.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 +""" +normalize-clang-tidy.py + +Normalize clang-tidy outputs (export-fixes YAML or textual stderr/stdout) +and emit lines in the form: + + :: - + +Only diagnostics whose canonical file path is under /include/ or +/lib/ are emitted. This prevents diagnostics originating from +deps/ (e.g., include/../deps/...) from slipping through. +""" + +import sys +import os +import re +import yaml +import subprocess + + +def get_repo_root(): + try: + out = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], stderr=subprocess.DEVNULL) + return os.path.realpath(out.decode().strip()) + except Exception: + return os.path.realpath(os.getcwd()) + + +def canonical_path(path, repo_root): + if not path: + return None + # Ignore placeholders like or + if path.startswith("<") and path.endswith(">"): + return None + if os.path.isabs(path): + return os.path.realpath(path) + # If relative, interpret relative to repo root + return os.path.realpath(os.path.join(repo_root, path)) + + +def is_in_repo_include_or_lib(cpath, repo_root): + if not cpath: + return False + inc = os.path.realpath(os.path.join(repo_root, "include")) + lib = os.path.realpath(os.path.join(repo_root, "lib")) + try: + # os.path.commonpath raises ValueError if paths are on different drives + common_inc = os.path.commonpath([cpath, inc]) + if common_inc == inc: + return True + except Exception: + pass + try: + common_lib = os.path.commonpath([cpath, lib]) + if common_lib == lib: + return True + except Exception: + pass + return False + + +def offset_to_line(cpath, offset): + try: + with open(cpath, 'rb') as fh: + data = fh.read() + # offset is a byte offset; count newlines before it + return data[:offset].count(b"\n") + 1 + except Exception: + return 0 + + +def main(): + if len(sys.argv) != 2: + print("Usage: normalize-clang-tidy.py ") + return 2 + + path = sys.argv[1] + if not os.path.exists(path): + # Nothing to normalize + return 0 + + repo_root = get_repo_root() + content = open(path, 'r', errors='ignore').read() + diagnostics = set() + + # Try parsing as export-fixes YAML first + try: + data = yaml.safe_load(content) + if isinstance(data, dict) and 'Diagnostics' in data: + for diag in data.get('Diagnostics', []): + msg = diag.get('DiagnosticMessage', {}) or {} + raw_file = msg.get('FilePath') + cpath = canonical_path(raw_file, repo_root) + if not cpath: + continue + if not is_in_repo_include_or_lib(cpath, repo_root): + continue + offset = msg.get('FileOffset', None) + if offset is None: + line_no = msg.get('FileLine', 0) or 0 + else: + line_no = offset_to_line(cpath, int(offset)) + check = diag.get('CheckName') or diag.get('DiagnosticName') or '' + message = (msg.get('Message') or '').strip() + diagnostics.add(f"{cpath}:{line_no}: {check} - {message}") + else: + # Not the expected YAML structure; fall back to textual parsing + raise ValueError("not yaml diagnostics") + except Exception: + # Fallback: parse clang-tidy textual output lines + # Typical clang-tidy message format: + # /path/to/file:123:45: warning: message [check-name] + pat = re.compile(r"(?P[^:]+):(?P\d+):(?P\d+:)?\s*(?Pwarning|error|note):?\s*(?P.*)\s*\[(?P[^\]]+)\]$") + for line in content.splitlines(): + m = pat.match(line) + if not m: + continue + raw_file = m.group('file') + cpath = canonical_path(raw_file, repo_root) + if not cpath: + continue + if not is_in_repo_include_or_lib(cpath, repo_root): + continue + line_no = m.group('line') + check = m.group('check') + message = m.group('msg').strip() + diagnostics.add(f"{cpath}:{line_no}: {check} - {message}") + + for l in sorted(diagnostics): + print(l) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/scripts/lint/normalize-cppcheck.py b/scripts/lint/normalize-cppcheck.py new file mode 100755 index 0000000000..3851220dcb --- /dev/null +++ b/scripts/lint/normalize-cppcheck.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import sys +import re +import os + +""" +Normalize cppcheck stderr output. Produce lines like: +:: - +""" + +path = sys.argv[1] if len(sys.argv) > 1 else None +data = '' +if path and os.path.exists(path): + data = open(path).read() +else: + data = sys.stdin.read() + +lines = [] +for raw in data.splitlines(): + # cppcheck prints: [path:line]: (id) message + m = re.match(r"\[(?P[^:]+):(?P\d+)\] (?P[^:]+): (?P.*)", raw) + if m: + lines.append(f"{m.group('file')}:{m.group('line')}: {m.group('id').strip()} - {m.group('msg').strip()}") + +for l in sorted(set(lines)): + print(l) diff --git a/scripts/lint/run-local.sh b/scripts/lint/run-local.sh new file mode 100755 index 0000000000..47fc4a4d31 --- /dev/null +++ b/scripts/lint/run-local.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Runs clang-tidy and cppcheck for the initial scope (lib/ and include/) +# Expectation: compile_commands.json exists in repo root (generated by generate-compile-commands.sh) + +CLANG_TIDY_BIN=${CLANG_TIDY_BIN:-clang-tidy} +CPPCHECK_BIN=${CPPCHECK_BIN:-cppcheck} + +if [ ! -f compile_commands.json ]; then + echo "compile_commands.json not found. Run scripts/lint/generate-compile-commands.sh first." >&2 + exit 1 +fi + +mkdir -p lint +echo "Running clang-tidy per-file (this runs each source file one at a time)..." + +## Accept optional file arguments. If files are provided as arguments, lint only those. +if [ "$#" -gt 0 ]; then + FILES=("$@") +else + # Build list of C/C++ source files under lib tracked by git + FILES=() + while IFS= read -r f; do + case "$f" in + *.cpp|*.cc|*.cxx|*.c) + FILES+=("$f") ;; + esac + done < <(git ls-files lib) +fi + +if [ ${#FILES[@]} -eq 0 ]; then + echo "No source files found to lint under lib/" >&2 +else + TMPD=$(mktemp -d) + # Compute an anchored header-filter that limits diagnostics to files inside + # this repository's include/ and lib/ directories. Use an absolute path so + # headers in deps/ that happen to contain '/include/' don't match. + REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo "$(pwd)") + HEADER_FILTER="^${REPO_ROOT}/(include|lib)/" + echo "Using clang-tidy header-filter: ${HEADER_FILTER}" + n=0 + total=${#FILES[@]} + for f in "${FILES[@]}"; do + n=$((n+1)) + echo "[$n/$total] clang-tidy $f" + # Capture textual diagnostics per-file; still write export-fixes when available + ${CLANG_TIDY_BIN} -p . -checks='clang-analyzer-*,bugprone-*,performance-*,modernize-*,readability-*' --header-filter="${HEADER_FILTER}" --export-fixes="${TMPD}/ct-${n}.yaml" "$f" 2> "${TMPD}/ct-${n}.stderr" || true + done + + echo "Merging per-file clang-tidy fixes into lint/clang-tidy-fixes.yaml" + # Merge all per-file YAMLs into a single Diagnostics list. Missing or empty files are ignored. + python3 - "${TMPD}" <<'PY' +import sys, yaml, glob +tmp = sys.argv[1] +out = [] +for p in sorted(glob.glob(tmp + '/*.yaml')): + try: + data = yaml.safe_load(open(p)) + except Exception: + continue + if not data: + continue + out.extend(data.get('Diagnostics', [])) +yaml.safe_dump({'Diagnostics': out}, open('lint/clang-tidy-fixes.yaml', 'w')) +PY + + # Keep per-file stderr outputs around until after normalization so we can + # fall back to parsing textual diagnostics when export-fixes is empty. + # We'll clean up TMPD after normalization below. +fi + +echo "Running cppcheck..." +${CPPCHECK_BIN} --enable=warning,performance,portability,style --std=c++17 --project=compile_commands.json --inline-suppr 2> lint/cppcheck-output.txt || true + +echo "Normalizing outputs..." +# If export-fixes YAML produced diagnostics use that; otherwise merge textual stderr outputs +if [ -f lint/clang-tidy-fixes.yaml ]; then + python3 scripts/lint/normalize-clang-tidy.py lint/clang-tidy-fixes.yaml > lint/clang-tidy.txt || true +else + # Merge all per-file stderr clang-tidy outputs if present + if ls ${TMPD:-/dev/null}/ct-*.stderr >/dev/null 2>&1; then + cat ${TMPD}/ct-*.stderr > lint/clang-tidy-raw.txt || true + python3 scripts/lint/normalize-clang-tidy.py lint/clang-tidy-raw.txt > lint/clang-tidy.txt || true + else + # Nothing found + : + fi +fi + +# Clean up temporary directory created for per-file clang-tidy runs +if [ -n "${TMPD:-}" ] && [ -d "${TMPD}" ]; then + rm -rf "${TMPD}" +fi +python3 scripts/lint/normalize-cppcheck.py lint/cppcheck-output.txt > lint/cppcheck.txt || true + +echo "Local lint run complete. Reports written to lint/clang-tidy.txt and lint/cppcheck.txt"