Skip to content

Commit 4d99265

Browse files
authored
Merge pull request #4833 from sysown/v3.0-flush_debug
PROXYSQL FLUSH LOGS forces debug database flush
2 parents a9a3583 + 8bb1f9c commit 4d99265

19 files changed

+684
-284
lines changed

lib/MySQL_Session.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -4042,6 +4042,17 @@ int MySQL_Session::get_pkts_from_client(bool& wrong_pass, PtrSize_t& pkt) {
40424042
}
40434043
switch ((enum_mysql_command)c) {
40444044
case _MYSQL_COM_QUERY:
4045+
{
4046+
const char* schemaname { client_myds->myconn->userinfo->schemaname };
4047+
const char* recv_query { static_cast<char*>(pkt.ptr) + 5 };
4048+
const uint32_t recv_query_sz { pkt.size - 5 };
4049+
4050+
proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Processing received query"
4051+
" session=%p session_type=%d schemaname=%s query=%.*s\n",
4052+
this, session_type, schemaname ? schemaname : "", recv_query_sz, recv_query
4053+
);
4054+
}
4055+
40454056
__sync_add_and_fetch(&thread->status_variables.stvar[st_var_queries],1);
40464057
if (session_type == PROXYSQL_SESSION_MYSQL) {
40474058
bool rc_break=false;
@@ -4849,7 +4860,6 @@ int MySQL_Session::handler() {
48494860
case PROCESSING_STMT_PREPARE:
48504861
case PROCESSING_STMT_EXECUTE:
48514862
case PROCESSING_QUERY:
4852-
//fprintf(stderr,"PROCESSING_QUERY\n");
48534863
// Pause Check
48544864
// It checks if pause_until is greater than the current time (thread->curtime).
48554865
// If so, it returns handler_ret immediately, indicating that processing should be paused until a later time.

lib/ProxySQL_Admin.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ void ProxySQL_Admin::flush_logs() {
11171117
}
11181118
free(ssl_keylog_file);
11191119
}
1120+
proxy_debug(PROXY_DEBUG_ADMIN, 1, "Running PROXYSQL FLUSH LOGS\n");
11201121
}
11211122

11221123

lib/debug.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct DebugLogEntry {
4343
std::string backtrace;
4444
};
4545

46-
static const size_t limitSize = 30;
46+
static const size_t limitSize = 100;
4747
static std::vector<DebugLogEntry> log_buffer = {};
4848

4949

@@ -285,7 +285,11 @@ void proxy_debug_func(
285285
// but the entries can be read in `log_buffer` in the core dump
286286
// note2: also in case of shutdown , `log_buffer` will have entries that won't be saved.
287287
// if we really want *all* entries, we could just call sync_log_buffer_to_disk() on shutdown
288-
if (log_buffer.size() > limitSize) {
288+
if (
289+
(log_buffer.size() >= limitSize)
290+
||
291+
(entry.file == "ProxySQL_Admin.cpp" && entry.funct == "flush_logs")
292+
) {
289293
sync_log_buffer_to_disk(db);
290294
}
291295
}

lib/sqlite3db.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,13 @@ void SQLite3_result::add_column_definition(int a, const char *b) {
764764
* @return An integer representing the result of the operation (SQLITE_ROW on success).
765765
*/
766766
int SQLite3_result::add_row(sqlite3_stmt *stmt, bool skip) {
767-
int rc=(*proxy_sqlite3_step)(stmt);
767+
int rc = 0;
768+
do {
769+
rc = (*proxy_sqlite3_step)(stmt);
770+
if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
771+
usleep(USLEEP_SQLITE_LOCKED);
772+
}
773+
} while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
768774
if (rc!=SQLITE_ROW) return rc;
769775
if (skip==false) {
770776
SQLite3_row *row=new SQLite3_row(columns);

test/tap/tap/tap.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,18 @@ static TEST_DATA g_test = { NO_PLAN, 0, 0, "" };
7979
@param us True for enabling microseconds in log output.
8080
@param len Buffer len.
8181
*/
82-
size_t get_fmt_time(char* tm_buf, size_t len, bool us=false) {
83-
time_t __timer;
84-
time(&__timer);
82+
size_t get_fmt_time(char* tm_buf, size_t len, bool us) {
83+
struct timeval tv {};
84+
gettimeofday(&tv, NULL);
85+
8586
struct tm __tm_info {};
86-
localtime_r(&__timer, &__tm_info);
87+
localtime_r(&tv.tv_sec, &__tm_info);
88+
8789
size_t rc = strftime(tm_buf, len, "%Y-%m-%d %H:%M:%S", &__tm_info);
8890

8991
if (rc == 0) {
9092
return rc;
9193
} else if (us) {
92-
struct timeval tv;
93-
struct tm *tm_info;
94-
95-
gettimeofday(&tv, NULL);
96-
tm_info = localtime(&tv.tv_sec);
9794
rc = snprintf(tm_buf + rc, len - rc, ".%06ld", tv.tv_usec);
9895
}
9996

test/tap/tap/tap.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef TAP_H
2121
#define TAP_H
2222

23-
//#include "my_global.h"
23+
#include <unistd.h>
2424

2525
/*
2626
@defgroup MyTAP MySQL support for performing unit tests according to
@@ -91,6 +91,15 @@ extern volatile int tap_log_us;
9191
@{
9292
*/
9393

94+
/**
95+
@brief Writes current time ("%Y-%m-%d %H:%M:%S") in the supplied buffer.
96+
97+
@param tm_buf Buffer to be written.
98+
@param us True for enabling microseconds in log output.
99+
@param len Buffer len.
100+
*/
101+
size_t get_fmt_time(char* tm_buf, size_t len, bool us=false);
102+
94103
/**
95104
Set number of tests that is planned to execute.
96105

0 commit comments

Comments
 (0)