From 1d30d40e9b47a4af422850f2c32b4bfab727475d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Mon, 14 Oct 2024 06:37:25 +0000 Subject: [PATCH] Added stats_mysql_eventslog_sync_buffer_to_disk Added new Admin variable stats_mysql_eventslog_sync_buffer_to_disk . This variable defines how frequently mysql query eventslog are automatically dumped to disk. --- include/ProxySQL_Statistics.hpp | 3 +++ include/proxysql_admin.h | 1 + lib/ProxySQL_Admin.cpp | 25 +++++++++++++++++++++++++ lib/ProxySQL_Statistics.cpp | 11 +++++++++++ 4 files changed, 40 insertions(+) diff --git a/include/ProxySQL_Statistics.hpp b/include/ProxySQL_Statistics.hpp index 7ab170ef1..18b792c5a 100644 --- a/include/ProxySQL_Statistics.hpp +++ b/include/ProxySQL_Statistics.hpp @@ -91,6 +91,7 @@ class ProxySQL_Statistics { unsigned long long next_timer_MySQL_Threads_Handler; unsigned long long next_timer_mysql_query_digest_to_disk; unsigned long long next_timer_system_cpu; + unsigned long long last_timer_mysql_dump_eventslog_to_disk = 0; #ifndef NOJEM unsigned long long next_timer_system_memory; #endif @@ -106,6 +107,7 @@ class ProxySQL_Statistics { int stats_mysql_query_cache; int stats_system_cpu; int stats_mysql_query_digest_to_disk; + int stats_mysql_eventslog_sync_buffer_to_disk; #ifndef NOJEM int stats_system_memory; #endif @@ -118,6 +120,7 @@ class ProxySQL_Statistics { bool MySQL_Threads_Handler_timetoget(unsigned long long); bool mysql_query_digest_to_disk_timetoget(unsigned long long); bool system_cpu_timetoget(unsigned long long); + bool MySQL_Logger_dump_eventslog_timetoget(unsigned long long); #ifndef NOJEM bool system_memory_timetoget(unsigned long long); #endif diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 81f7aae6e..2000787e7 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -255,6 +255,7 @@ class ProxySQL_Admin { int stats_mysql_connections; int stats_mysql_query_cache; int stats_mysql_query_digest_to_disk; + int stats_mysql_eventslog_sync_buffer_to_disk; int stats_system_cpu; int stats_system_memory; int mysql_show_processlist_extended; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 522deffca..0c28930bd 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -613,6 +613,7 @@ static char * admin_variables_names[]= { (char *)"stats_mysql_connection_pool", (char *)"stats_mysql_query_cache", (char *)"stats_mysql_query_digest_to_disk", + (char *)"stats_mysql_eventslog_sync_buffer_to_disk", (char *)"stats_system_cpu", (char *)"stats_system_memory", (char *)"mysql_ifaces", @@ -5838,6 +5839,14 @@ __end_while_pool: curtime2 = curtime2/1000; proxy_info("Automatically saved stats_mysql_query_digest to disk: %llums to write %d entries\n", curtime2-curtime1, r1); } + if (GloProxyStats->MySQL_Logger_dump_eventslog_timetoget(curtime)) { + unsigned long long curtime1=monotonic_time(); + int r1 = GloMyLogger->processEvents(nullptr, SPA->statsdb_disk); + unsigned long long curtime2=monotonic_time(); + curtime1 = curtime1/1000; + curtime2 = curtime2/1000; + proxy_info("Automatically saved history_mysql_query_events to disk: %llums to write %d entries\n", curtime2-curtime1, r1); + } if (GloProxyStats->system_cpu_timetoget(curtime)) { GloProxyStats->system_cpu_sets(); } @@ -6054,12 +6063,14 @@ ProxySQL_Admin::ProxySQL_Admin() : variables.stats_mysql_connections = 60; variables.stats_mysql_query_cache = 60; variables.stats_mysql_query_digest_to_disk = 0; + variables.stats_mysql_eventslog_sync_buffer_to_disk = 0; variables.stats_system_cpu = 60; variables.stats_system_memory = 60; GloProxyStats->variables.stats_mysql_connection_pool = 60; GloProxyStats->variables.stats_mysql_connections = 60; GloProxyStats->variables.stats_mysql_query_cache = 60; GloProxyStats->variables.stats_mysql_query_digest_to_disk = 0; + GloProxyStats->variables.stats_mysql_eventslog_sync_buffer_to_disk = 0; GloProxyStats->variables.stats_system_cpu = 60; #ifndef NOJEM GloProxyStats->variables.stats_system_memory = 60; @@ -8457,6 +8468,10 @@ char * ProxySQL_Admin::get_variable(char *name) { sprintf(intbuf,"%d",variables.stats_mysql_query_digest_to_disk); return strdup(intbuf); } + if (!strcasecmp(name,"stats_mysql_eventslog_sync_buffer_to_disk")) { + sprintf(intbuf,"%d",variables.stats_mysql_eventslog_sync_buffer_to_disk); + return strdup(intbuf); + } if (!strcasecmp(name,"stats_system_cpu")) { sprintf(intbuf,"%d",variables.stats_system_cpu); return strdup(intbuf); @@ -8762,6 +8777,16 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this return false; } } + if (!strcasecmp(name,"stats_mysql_eventslog_sync_buffer_to_disk")) { + int intv=atoi(value); + if (intv >= 0 && intv <= 24*3600) { + variables.stats_mysql_eventslog_sync_buffer_to_disk=intv; + GloProxyStats->variables.stats_mysql_eventslog_sync_buffer_to_disk=intv; + return true; + } else { + return false; + } + } if (!strcasecmp(name,"stats_system_cpu")) { int intv=atoi(value); if (intv >= 0 && intv <= 600) { diff --git a/lib/ProxySQL_Statistics.cpp b/lib/ProxySQL_Statistics.cpp index df350fd60..5836275f9 100644 --- a/lib/ProxySQL_Statistics.cpp +++ b/lib/ProxySQL_Statistics.cpp @@ -179,6 +179,17 @@ void ProxySQL_Statistics::drop_tables_defs(std::vector *tables_de } } +bool ProxySQL_Statistics::MySQL_Logger_dump_eventslog_timetoget(unsigned long long curtime) { + if (variables.stats_mysql_eventslog_sync_buffer_to_disk) { // only proceed if not zero + unsigned long long t = variables.stats_mysql_eventslog_sync_buffer_to_disk; // originally in seconds + t = t * 1000 * 1000; + if (curtime > last_timer_mysql_dump_eventslog_to_disk + t) { + last_timer_mysql_dump_eventslog_to_disk = curtime; + return true; + } + } + return false; +} bool ProxySQL_Statistics::MySQL_Threads_Handler_timetoget(unsigned long long curtime) { unsigned int i = (unsigned int)variables.stats_mysql_connections;