diff --git a/include/MySQL_Logger.hpp b/include/MySQL_Logger.hpp index 6373e9c63..50ae406f3 100644 --- a/include/MySQL_Logger.hpp +++ b/include/MySQL_Logger.hpp @@ -163,7 +163,32 @@ class MySQL_Logger { void wrlock(); void wrunlock(); MySQL_Logger_CircularBuffer * MyLogCB; + /** + * @brief Inserts a batch of MySQL events into a specified SQLite table. + * @param db A pointer to the SQLite3DB object representing the database connection. + * @param tableName The name of the SQLite table to insert into. + * @param numEvents The number of events to insert. + * @param begin An iterator pointing to the beginning of the range of MySQL_Event* in the vector to insert. + * @return 0 if the insertion was successful, a negative error code otherwise. + * + * This function inserts a batch of MySQL events into the specified SQLite table using bulk insert techniques for efficiency. + * It handles the conversion of MySQL_Event data to a format suitable for SQLite insertion. Error handling includes logging of errors. + * The function uses a prepared statement for bulk insertion. + * The function assumes that the provided events have been allocated with `new` and will not be deleted by this function. + */ void insertMysqlEventsIntoDb(SQLite3DB * db, const std::string& tableName, size_t numEvents, std::vector::const_iterator begin); + /** + * @brief Processes and inserts MySQL events into in-memory and/or on-disk SQLite databases. + * @param statsdb A pointer to the SQLite3DB object for the in-memory database (can be nullptr). + * @param statsdb_disk A pointer to the SQLite3DB object for the on-disk database (can be nullptr). + * @return The number of events processed. Returns a negative value if an error occurs. + * + * This function retrieves events from the circular buffer, handles in-memory table size limits, and inserts them into the specified SQLite databases. + * If either statsdb or statsdb_disk is nullptr, events are only written to the other database. + * It handles in-memory table size limits by deleting existing entries if necessary. + * The function ensures that the in-memory table size does not exceed a predefined limit (`eventslog_table_memory_size`). + * The function assumes ownership of the MySQL_Event pointers and deletes them after processing. + */ int processEvents(SQLite3DB * statsdb , SQLite3DB * statsdb_disk); }; diff --git a/include/ProxySQL_Statistics.hpp b/include/ProxySQL_Statistics.hpp index 18b792c5a..30ae1673e 100644 --- a/include/ProxySQL_Statistics.hpp +++ b/include/ProxySQL_Statistics.hpp @@ -120,7 +120,16 @@ 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); + /** + * @brief Checks if it's time to dump the events log to disk based on the configured interval. + * @param currentTimeMicros The current time in microseconds. + * @return True if it's time to dump the events log, false otherwise. + * + * This function checks if the current time exceeds the last dump time plus the configured dump interval. + * The dump interval is retrieved from the ProxySQL configuration. If the dump interval is 0, no dumping is performed. + */ + bool MySQL_Logger_dump_eventslog_timetoget(unsigned long long currentTimeMicros); + #ifndef NOJEM bool system_memory_timetoget(unsigned long long); #endif diff --git a/lib/ProxySQL_Statistics.cpp b/lib/ProxySQL_Statistics.cpp index 5836275f9..d584f11ad 100644 --- a/lib/ProxySQL_Statistics.cpp +++ b/lib/ProxySQL_Statistics.cpp @@ -179,12 +179,12 @@ void ProxySQL_Statistics::drop_tables_defs(std::vector *tables_de } } -bool ProxySQL_Statistics::MySQL_Logger_dump_eventslog_timetoget(unsigned long long curtime) { +bool ProxySQL_Statistics::MySQL_Logger_dump_eventslog_timetoget(unsigned long long currentTimeMicros) { 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; + if (currentTimeMicros > last_timer_mysql_dump_eventslog_to_disk + t) { + last_timer_mysql_dump_eventslog_to_disk = currentTimeMicros; return true; } }