Adding documentation on in memory eventslog

v2.x-logging_mem
René Cannaò 2 years ago
parent 1d30d40e9b
commit 28982a4e0a

@ -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<MySQL_Event*>::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);
};

@ -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

@ -179,12 +179,12 @@ void ProxySQL_Statistics::drop_tables_defs(std::vector<table_def_t *> *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;
}
}

Loading…
Cancel
Save