Moving return_proxysql_internal() to Base_Session

v2.x_pg_PrepStmtBase_240714
Rene Cannao 2 years ago
parent 649c985384
commit 66b7c103af

@ -12,6 +12,11 @@ template<typename S, typename DSi, typename B, typename T> class Base_Session;
#ifndef CLASS_BASE_SESSION_H
#define CLASS_BASE_SESSION_H
#ifndef PROXYJSON
#define PROXYJSON
namespace nlohmann { class json; }
#endif // PROXYJSON
class MySQL_STMTs_meta;
class StmtLongDataHandler;
class MySQL_Session;
@ -21,7 +26,7 @@ template<typename S, typename DS, typename B, typename T>
class Base_Session {
public:
Base_Session();
~Base_Session();
virtual ~Base_Session();
// uint64_t
unsigned long long start_time;
@ -102,6 +107,10 @@ class Base_Session {
B * create_backend(int, DS * _myds = NULL);
B * find_or_create_backend(int, DS * _myds = NULL);
void writeout();
void return_proxysql_internal(PtrSize_t* pkt);
virtual void generate_proxysql_internal_session_json(nlohmann::json &) = 0;
virtual void RequestEnd(DS *) = 0;
virtual void SQLite3_to_MySQL(SQLite3_result*, char*, int, MySQL_Protocol*, bool in_transaction = false, bool deprecate_eof_active = false) = 0;
};
#endif // CLASS_BASE_SESSION_H

@ -154,7 +154,7 @@ class MySQL_Session: public Base_Session<MySQL_Session, MySQL_Data_Stream, MySQL
void handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED__get_connection();
void return_proxysql_internal(PtrSize_t *);
//void return_proxysql_internal(PtrSize_t *);
bool handler_special_queries(PtrSize_t *);
bool handler_special_queries_STATUS(PtrSize_t *);
/**
@ -186,7 +186,7 @@ class MySQL_Session: public Base_Session<MySQL_Session, MySQL_Data_Stream, MySQL
* @param myds If not null, should point to a MySQL_Data_Stream (backend connection) which connection status
* should be updated, and previous query resources cleanup.
*/
void RequestEnd(MySQL_Data_Stream *);
void RequestEnd(MySQL_Data_Stream *) override;
void LogQuery(MySQL_Data_Stream *);
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___create_mirror_session();
@ -395,7 +395,7 @@ class MySQL_Session: public Base_Session<MySQL_Session, MySQL_Data_Stream, MySQL
//MySQL_Backend * create_backend(int, MySQL_Data_Stream *_myds=NULL);
//MySQL_Backend * find_or_create_backend(int, MySQL_Data_Stream *_myds=NULL);
void SQLite3_to_MySQL(SQLite3_result *, char *, int , MySQL_Protocol *, bool in_transaction=false, bool deprecate_eof_active=false);
void SQLite3_to_MySQL(SQLite3_result *, char *, int , MySQL_Protocol *, bool in_transaction=false, bool deprecate_eof_active=false) override;
void MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *MyRS, unsigned int warning_count, MySQL_Data_Stream *_myds=NULL);
void MySQL_Stmt_Result_to_MySQL_wire(MYSQL_STMT *stmt, MySQL_Connection *myconn);
unsigned int NumActiveTransactions(bool check_savpoint=false);
@ -435,7 +435,7 @@ class MySQL_Session: public Base_Session<MySQL_Session, MySQL_Data_Stream, MySQL
* params.
*/
void finishQuery(MySQL_Data_Stream *myds, MySQL_Connection *myconn, bool);
void generate_proxysql_internal_session_json(nlohmann::json &);
void generate_proxysql_internal_session_json(nlohmann::json &) override;
bool known_query_for_locked_on_hostgroup(uint64_t);
void unable_to_parse_set_statement(bool *);
bool has_any_backend();

@ -147,7 +147,7 @@ private:
void handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED__get_connection();
void return_proxysql_internal(PtrSize_t*);
//void return_proxysql_internal(PtrSize_t*);
bool handler_special_queries(PtrSize_t*);
bool handler_special_queries_STATUS(PtrSize_t*);
/**
@ -179,7 +179,7 @@ private:
* @param myds If not null, should point to a PgSQL_Data_Stream (backend connection) which connection status
* should be updated, and previous query resources cleanup.
*/
void RequestEnd(PgSQL_Data_Stream*);
void RequestEnd(PgSQL_Data_Stream*) override;
void LogQuery(PgSQL_Data_Stream*);
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___create_mirror_session();
@ -373,7 +373,7 @@ public:
//PgSQL_Backend* create_backend(int, PgSQL_Data_Stream* _myds = NULL);
//PgSQL_Backend* find_or_create_backend(int, PgSQL_Data_Stream* _myds = NULL);
void SQLite3_to_MySQL(SQLite3_result*, char*, int, MySQL_Protocol*, bool in_transaction = false, bool deprecate_eof_active = false);
void SQLite3_to_MySQL(SQLite3_result*, char*, int, MySQL_Protocol*, bool in_transaction = false, bool deprecate_eof_active = false) override;
void PgSQL_Result_to_PgSQL_wire(PgSQL_Connection* conn, PgSQL_Data_Stream* _myds = NULL);
void MySQL_Stmt_Result_to_MySQL_wire(MYSQL_STMT* stmt, PgSQL_Connection* myconn);
unsigned int NumActiveTransactions(bool check_savpoint = false);
@ -413,7 +413,7 @@ public:
* params.
*/
void finishQuery(PgSQL_Data_Stream* myds, PgSQL_Connection* myconn, bool);
void generate_proxysql_internal_session_json(nlohmann::json&);
void generate_proxysql_internal_session_json(nlohmann::json&) override;
bool known_query_for_locked_on_hostgroup(uint64_t);
void unable_to_parse_set_statement(bool*);
bool has_any_backend();

@ -1,9 +1,15 @@
#include "../deps/json/json.hpp"
using json = nlohmann::json;
#define PROXYJSON
#include "Base_Session.h"
#include "MySQL_PreparedStatement.h"
#include "MySQL_Data_Stream.h"
#include "PgSQL_Data_Stream.h"
using json = nlohmann::json;
// Explicitly instantiate the required template class and member functions
template void Base_Session<MySQL_Session,MySQL_Data_Stream,MySQL_Backend,MySQL_Thread>::init();
template void Base_Session<PgSQL_Session,PgSQL_Data_Stream,PgSQL_Backend,PgSQL_Thread>::init();
@ -36,6 +42,9 @@ template PgSQL_Backend * Base_Session<PgSQL_Session,PgSQL_Data_Stream,PgSQL_Back
template void Base_Session<MySQL_Session,MySQL_Data_Stream,MySQL_Backend,MySQL_Thread>::writeout();
template void Base_Session<PgSQL_Session,PgSQL_Data_Stream,PgSQL_Backend,PgSQL_Thread>::writeout();
template void Base_Session<MySQL_Session, MySQL_Data_Stream, MySQL_Backend, MySQL_Thread>::return_proxysql_internal(_PtrSize_t*);
template void Base_Session<PgSQL_Session, PgSQL_Data_Stream, PgSQL_Backend, PgSQL_Thread>::return_proxysql_internal(_PtrSize_t*);
template<typename S, typename DS, typename B, typename T>
Base_Session<S,DS,B,T>::Base_Session() {
};
@ -274,3 +283,43 @@ void PgSQL_Session::writeout() {
}
}
#endif // 0
template<typename S, typename DS, typename B, typename T>
void Base_Session<S,DS,B,T>::return_proxysql_internal(PtrSize_t* pkt) {
unsigned int l = 0;
l = strlen((char*)"PROXYSQL INTERNAL SESSION");
if (pkt->size == (5 + l) && strncasecmp((char*)"PROXYSQL INTERNAL SESSION", (char*)pkt->ptr + 5, l) == 0) {
json j;
generate_proxysql_internal_session_json(j);
std::string s = j.dump(4, ' ', false, json::error_handler_t::replace);
SQLite3_result* resultset = new SQLite3_result(1);
resultset->add_column_definition(SQLITE_TEXT, "session_info");
char* pta[1];
pta[0] = (char*)s.c_str();
resultset->add_row(pta);
bool deprecate_eof_active = client_myds->myconn->options.client_flag & CLIENT_DEPRECATE_EOF;
SQLite3_to_MySQL(resultset, NULL, 0, &client_myds->myprot, false, deprecate_eof_active);
delete resultset;
l_free(pkt->size, pkt->ptr);
return;
}
// default
client_myds->DSS = STATE_QUERY_SENT_NET;
if constexpr (std::is_same_v<S, MySQL_Session>) {
client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,1,1064,(char *)"42000",(char *)"Unknown PROXYSQL INTERNAL command",true);
} else if constexpr (std::is_same_v<S, PgSQL_Session>) {
client_myds->myprot.generate_error_packet(true, true, "Unknown PROXYSQL INTERNAL command", PGSQL_ERROR_CODES::ERRCODE_SYNTAX_ERROR, false, true);
} else {
assert(0);
}
if (mirror == false) {
RequestEnd(NULL);
}
else {
client_myds->DSS = STATE_SLEEP;
status = WAITING_CLIENT_DATA;
}
l_free(pkt->size, pkt->ptr);
}

@ -1279,6 +1279,7 @@ void MySQL_Session::generate_proxysql_internal_session_json(json &j) {
}
}
#if 0
void MySQL_Session::return_proxysql_internal(PtrSize_t *pkt) {
unsigned int l = 0;
l = strlen((char *)"PROXYSQL INTERNAL SESSION");
@ -1308,6 +1309,7 @@ void MySQL_Session::return_proxysql_internal(PtrSize_t *pkt) {
}
l_free(pkt->size,pkt->ptr);
}
#endif // 0
/**
* @brief Handles special queries executed by the STATUS command in mysql cli .

@ -1256,6 +1256,7 @@ void PgSQL_Session::generate_proxysql_internal_session_json(json& j) {
}
}
#if 0
void PgSQL_Session::return_proxysql_internal(PtrSize_t* pkt) {
unsigned int l = 0;
l = strlen((char*)"PROXYSQL INTERNAL SESSION");
@ -1286,6 +1287,7 @@ void PgSQL_Session::return_proxysql_internal(PtrSize_t* pkt) {
}
l_free(pkt->size, pkt->ptr);
}
#endif // 0
/**
* @brief Handles special queries executed by the STATUS command in pgsql cli .

Loading…
Cancel
Save