diff --git a/lib/Standard_ProxySQL_Admin.cpp b/lib/Standard_ProxySQL_Admin.cpp index aa3dc9fa9..f0331ee98 100644 --- a/lib/Standard_ProxySQL_Admin.cpp +++ b/lib/Standard_ProxySQL_Admin.cpp @@ -157,6 +157,8 @@ class Standard_ProxySQL_Admin: public ProxySQL_Admin { void send_MySQL_OK(MySQL_Protocol *myprot, char *msg); void send_MySQL_ERR(MySQL_Protocol *myprot, char *msg); // virtual void admin_session_handler(MySQL_Session *sess); + int load_debug_to_runtime() { return flush_debug_levels_database_to_runtime(admindb); } + void save_debug_from_runtime() { return flush_debug_levels_runtime_to_database(admindb, true); } }; static Standard_ProxySQL_Admin *SPA=NULL; @@ -224,6 +226,85 @@ bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_ return true; } +/* Note: + * This function can modify the original query + */ +bool admin_handler_command_load_or_save(char *query_no_space, unsigned int query_no_space_length, MySQL_Session *sess, ProxySQL_Admin *pa, char **q, unsigned int *ql) { + + if ( + (query_no_space_length==strlen("LOAD DEBUG TO MEMORY") && !strncasecmp("LOAD DEBUG TO MEMORY",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD DEBUG TO MEM") && !strncasecmp("LOAD DEBUG TO MEM",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD DEBUG FROM DISK") && !strncasecmp("LOAD DEBUG FROM DISK",query_no_space, query_no_space_length)) + ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received %s command\n", query_no_space); + l_free(*ql,*q); + *q=l_strdup("INSERT OR REPLACE INTO main.debug_levels SELECT * FROM disk.debug_levels"); + *ql=strlen(*q)+1; + return true; + } + + if ( + (query_no_space_length==strlen("SAVE DEBUG FROM MEMORY") && !strncasecmp("SAVE DEBUG FROM MEMORY",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE DEBUG FROM MEM") && !strncasecmp("SAVE DEBUG FROM MEM",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE DEBUG TO DISK") && !strncasecmp("SAVE DEBUG TO DISK",query_no_space, query_no_space_length)) + ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received %s command\n", query_no_space); + l_free(*ql,*q); + *q=l_strdup("INSERT OR REPLACE INTO disk.debug_levels SELECT * FROM main.debug_levels"); + *ql=strlen(*q)+1; + return true; + } + + if ( + (query_no_space_length==strlen("LOAD DEBUG FROM MEMORY") && !strncasecmp("LOAD DEBUG FROM MEMORY",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD DEBUG FROM MEM") && !strncasecmp("LOAD DEBUG FROM MEM",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD DEBUG TO RUNTIME") && !strncasecmp("LOAD DEBUG TO RUNTIME",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD DEBUG TO RUN") && !strncasecmp("LOAD DEBUG TO RUN",query_no_space, query_no_space_length)) + ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received %s command\n", query_no_space); + + Standard_ProxySQL_Admin *SPA=(Standard_ProxySQL_Admin *)pa; + int rc=SPA->load_debug_to_runtime(); + if (rc) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Loaded debug levels to RUNTIME\n"); + SPA->send_MySQL_OK(&sess->myprot_client, NULL); + } else { + proxy_debug(PROXY_DEBUG_ADMIN, 1, "Error while loading debug levels to RUNTIME\n"); + SPA->send_MySQL_ERR(&sess->myprot_client, (char *)"Error while loading debug levels to RUNTIME"); + } + return false; + } + + if ( + (query_no_space_length==strlen("SAVE DEBUG TO MEMORY") && !strncasecmp("SAVE DEBUG TO MEMORY",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE DEBUG TO MEM") && !strncasecmp("SAVE DEBUG TO MEM",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE DEBUG FROM RUNTIME") && !strncasecmp("SAVE DEBUG FROM RUNTIME",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE DEBUG FROM RUN") && !strncasecmp("SAVE DEBUG FROM RUN",query_no_space, query_no_space_length)) + ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received %s command\n", query_no_space); + + Standard_ProxySQL_Admin *SPA=(Standard_ProxySQL_Admin *)pa; + SPA->save_debug_from_runtime(); + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Saved debug levels from RUNTIME\n"); + SPA->send_MySQL_OK(&sess->myprot_client, NULL); + return false; + } + + return true; +} + + + void admin_session_handler(MySQL_Session *sess, ProxySQL_Admin *pa, PtrSize_t *pkt) { char *error=NULL; @@ -251,7 +332,13 @@ void admin_session_handler(MySQL_Session *sess, ProxySQL_Admin *pa, PtrSize_t *p if ((query_no_space_length>8) && (!strncasecmp("PROXYSQL ", query_no_space, 8))) { proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL command\n"); - run_query=admin_handler_command_proxysql(query_no_space, query_no_space_length, sess, pa); + run_query=admin_handler_command_proxysql(query_no_space, query_no_space_length, sess, pa); + goto __run_query; + } + + if ((query_no_space_length>5) && ( (!strncasecmp("SAVE ", query_no_space, 5)) || (!strncasecmp("LOAD ", query_no_space, 5))) ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received LOAD or SAVE command\n"); + run_query=admin_handler_command_load_or_save(query_no_space, query_no_space_length, sess, pa, &query, &query_length); goto __run_query; }