* For a Describe Portal message, peek at the next message in the extended query frame. If it is an Execute message, indicating that client is sending a Bind/Describe/Execute sequence

skip processing the Describe Portal. This is because libpq automatically includes a Describe Portal during execution, and sending it again would be redundant.
* Removed server_capabilities from PgSQL modules
pull/5044/head
Rahim Kanji 9 months ago
parent ef2b0cb1ed
commit bc87d0d901

@ -963,7 +963,6 @@ public:
#ifdef DEBUG
bool session_debug;
#endif /* DEBUG */
uint32_t server_capabilities;
int poll_timeout;
int poll_timeout_on_failure;
char* eventslog_filename;
@ -1259,23 +1258,6 @@ public:
*/
char* get_variable_string(char* name);
/**
* @brief Retrieves the value of a thread variable as a uint16_t.
*
* @param name The name of the variable to retrieve.
*
* @return The value of the variable as a uint16_t, or 0 if the variable is not found
* or its value is not a valid uint16_t.
*
* @details This function retrieves the value of a thread variable as a uint16_t. It checks
* if the variable exists and then converts its value to a uint16_t. If the variable is
* not found or its value is not a valid uint16_t, it returns 0.
*
* @note This function is used internally by the `get_variable()` function to retrieve
* the value of a variable as a uint16_t.
*/
uint16_t get_variable_uint16(char* name);
/**
* @brief Retrieves the value of a thread variable as an integer.
*

@ -769,7 +769,6 @@ EXECUTION_STATE PgSQL_Protocol::process_handshake_response_packet(unsigned char*
return EXECUTION_STATE::FAILED;
}
user = (char*)(*myds)->myconn->conn_params.get_value(PG_USER);
if (!user || *user == '\0') {

@ -6043,6 +6043,13 @@ int PgSQL_Session::handle_post_sync_describe_message(PgSQL_Describe_Message* des
return 2;
}
if (extended_query_frame.empty() == false) {
// peeking next message in the extended query frame
if (std::holds_alternative<std::unique_ptr<PgSQL_Execute_Message>>(extended_query_frame.front())) {
return 0; // assuming client is sending Bind/Describe/Execute in the correct order, so libpq alreay sends describe message
}
}
portal_name = describe_data->stmt_name; // currently only supporting unanmed portals
stmt_client_name = bind_waiting_for_execute->data()->stmt_name; // data() will always be a valid pointer
assert(strcmp(portal_name, bind_waiting_for_execute->data()->portal_name) == 0); // portal name should match the one in bind_waiting_for_execute

@ -406,7 +406,6 @@ static char* pgsql_thread_variables_names[] = {
(char*)"default_schema",
(char*)"poll_timeout",
(char*)"poll_timeout_on_failure",
(char*)"server_capabilities",
(char*)"server_version",
(char*)"server_encoding",
(char*)"keep_multiplexing_variables",
@ -1035,9 +1034,6 @@ PgSQL_Threads_Handler::PgSQL_Threads_Handler() {
variables.eventslog_format = 1;
variables.auditlog_filename = strdup((char*)"");
variables.auditlog_filesize = 100 * 1024 * 1024;
//variables.server_capabilities=CLIENT_FOUND_ROWS | CLIENT_PROTOCOL_41 | CLIENT_IGNORE_SIGPIPE | CLIENT_TRANSACTIONS | CLIENT_SECURE_CONNECTION | CLIENT_CONNECT_WITH_DB;
// major upgrade in 2.0.0
variables.server_capabilities = CLIENT_MYSQL | CLIENT_FOUND_ROWS | CLIENT_PROTOCOL_41 | CLIENT_IGNORE_SIGPIPE | CLIENT_TRANSACTIONS | CLIENT_SECURE_CONNECTION | CLIENT_CONNECT_WITH_DB | CLIENT_PLUGIN_AUTH;;
variables.poll_timeout = 2000;
variables.poll_timeout_on_failure = 100;
variables.have_compress = true;
@ -1314,14 +1310,6 @@ char* PgSQL_Threads_Handler::get_variable_string(char* name) {
// LCOV_EXCL_STOP
}
uint16_t PgSQL_Threads_Handler::get_variable_uint16(char* name) {
if (!strcasecmp(name, "server_capabilities")) return variables.server_capabilities;
// LCOV_EXCL_START
proxy_error("Not existing variable: %s\n", name); assert(0);
return 0;
// LCOV_EXCL_STOP
}
int PgSQL_Threads_Handler::get_variable_int(const char* name) {
// convert name to string, and lowercase
std::string nameS = string(name);
@ -1442,11 +1430,6 @@ char* PgSQL_Threads_Handler::get_variable(char* name) { // this is the public fu
if (!strcasecmp(name, "default_schema")) return strdup(variables.default_schema);
if (!strcasecmp(name, "keep_multiplexing_variables")) return strdup(variables.keep_multiplexing_variables);
if (!strcasecmp(name, "interfaces")) return strdup(variables.interfaces);
if (!strcasecmp(name, "server_capabilities")) {
// FIXME : make it human readable
sprintf(intbuf, "%d", variables.server_capabilities);
return strdup(intbuf);
}
// SSL variables
if (!strncasecmp(name, "ssl_", 4)) {
if (!strcasecmp(name, "ssl_p2s_ca")) {
@ -1972,20 +1955,7 @@ bool PgSQL_Threads_Handler::set_variable(char* name, const char* value) { // thi
return true;
}
}
if (!strcasecmp(name, "server_capabilities")) {
// replaced atoi() with strtoul() to have a 32 bit result
uint32_t intv = strtoul(value, NULL, 10);
if (intv > 10) {
// Note that:
// - some capabilities are changed at runtime while performing the handshake with the client
// - even if we support 32 bits capabilities, many of them do not have any real meaning for proxysql (not supported)
variables.server_capabilities = intv;
return true;
}
else {
return false;
}
}
if (!strcasecmp(name, "stacksize")) {
int intv = atoi(value);
if (intv >= 256 * 1024 && intv <= 4 * 1024 * 1024) {
@ -2010,12 +1980,10 @@ bool PgSQL_Threads_Handler::set_variable(char* name, const char* value) { // thi
if (!strcasecmp(name, "have_compress")) {
if (strcasecmp(value, "true") == 0 || strcasecmp(value, "1") == 0) {
variables.have_compress = true;
variables.server_capabilities |= CLIENT_COMPRESS;
return true;
}
if (strcasecmp(value, "false") == 0 || strcasecmp(value, "0") == 0) {
variables.have_compress = false;
variables.server_capabilities &= ~CLIENT_COMPRESS;
return true;
}
return false;
@ -2023,12 +1991,10 @@ bool PgSQL_Threads_Handler::set_variable(char* name, const char* value) { // thi
if (!strcasecmp(name, "have_ssl")) {
if (strcasecmp(value, "true") == 0 || strcasecmp(value, "1") == 0) {
variables.have_ssl = true;
variables.server_capabilities |= CLIENT_SSL;
return true;
}
if (strcasecmp(value, "false") == 0 || strcasecmp(value, "0") == 0) {
variables.have_ssl = false;
variables.server_capabilities &= ~CLIENT_SSL;
return true;
}
return false;
@ -3984,8 +3950,7 @@ void PgSQL_Thread::refresh_variables() {
pgsql_thread___handle_unknown_charset = GloPTH->get_variable_int((char*)"handle_unknown_charset");
/*
mysql_thread___server_capabilities = GloPTH->get_variable_uint16((char*)"server_capabilities");
mysql_thread___have_compress = (bool)GloPTH->get_variable_int((char*)"have_compress");
mysql_thread___enforce_autocommit_on_reads = (bool)GloPTH->get_variable_int((char*)"enforce_autocommit_on_reads");

@ -2071,17 +2071,6 @@ void* child_postgres(void* arg) {
arg_proxysql_adm* myarg = (arg_proxysql_adm*)arg;
int client = myarg->client_t;
//struct sockaddr *addr = arg->addr;
//socklen_t addr_size;
GloPTH->wrlock();
{
char* s = GloPTH->get_variable((char*)"server_capabilities");
mysql_thread___server_capabilities = atoi(s);
free(s);
}
GloPTH->wrunlock();
struct pollfd fds[1];
nfds_t nfds = 1;
int rc;

Loading…
Cancel
Save