Add PGSQL eventslog dump commands and periodic disk sync scheduling

pull/5391/head
Rene Cannao 2 months ago
parent acbd7d0df3
commit b100235fbd

@ -3190,6 +3190,33 @@ void admin_session_handler(S* sess, void *_pa, PtrSize_t *pkt) {
goto __run_query;
}
if (!strncasecmp("DUMP PGSQL EVENTSLOG ", query_no_space, strlen("DUMP PGSQL EVENTSLOG "))) {
int num_rows = 0;
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received command DUMP PGSQL EVENTSLOG: %s\n", query_no_space);
proxy_info("Received command DUMP PGSQL EVENTSLOG: %s\n", query_no_space);
std::map<std::string, std::pair<SQLite3DB*, SQLite3DB*>> commandMap = {
{"DUMP PGSQL EVENTSLOG FROM BUFFER TO MEMORY", {SPA->statsdb, nullptr}},
{"DUMP PGSQL EVENTSLOG FROM BUFFER TO DISK", {nullptr, SPA->statsdb_disk}},
{"DUMP PGSQL EVENTSLOG FROM BUFFER TO BOTH", {SPA->statsdb, SPA->statsdb_disk}}
};
string s = string(query_no_space);
auto it = commandMap.find(s);
if (it != commandMap.end()) {
if (GloPgSQL_Logger != nullptr) {
num_rows = GloPgSQL_Logger->processEvents(it->second.first, it->second.second);
}
SPA->send_ok_msg_to_client(sess, NULL, num_rows, query_no_space);
} else {
proxy_warning("Received invalid command DUMP PGSQL EVENTSLOG: %s\n", query_no_space);
const string err_msg = "Invalid DUMP PGSQL EVENTSLOG command";
SPA->send_error_msg_to_client(sess, const_cast<char*>(err_msg.c_str()));
}
run_query = false;
goto __run_query;
}
// handle special queries from Cluster
// for bug #1188 , ProxySQL Admin needs to know the exact query

@ -2511,6 +2511,26 @@ __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)) {
if (GloMyLogger != nullptr) {
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 dumped MySQL eventslog buffer to disk: %llums to write %d entries\n", curtime2 - curtime1, r1);
}
}
if (GloProxyStats->PgSQL_Logger_dump_eventslog_timetoget(curtime)) {
if (GloPgSQL_Logger != nullptr) {
unsigned long long curtime1 = monotonic_time();
int r1 = GloPgSQL_Logger->processEvents(nullptr, SPA->statsdb_disk);
unsigned long long curtime2 = monotonic_time();
curtime1 = curtime1 / 1000;
curtime2 = curtime2 / 1000;
proxy_info("Automatically dumped PgSQL eventslog buffer to disk: %llums to write %d entries\n", curtime2 - curtime1, r1);
}
}
if (GloProxyStats->system_cpu_timetoget(curtime)) {
GloProxyStats->system_cpu_sets();
}

Loading…
Cancel
Save