fix(mysql): handle proxy-rejected session variables
This commit is contained in:
2 files changed
+41
-11
No files matched your search
@@ -730,7 +730,9 @@ async fn verify_pool_connection_with_setup_fallback(
|
||||
let Some(fallback_mode) = mysql_group_concat_setup_fallback_mode(setup_mode, &err) else {
|
||||
return Err(err);
|
||||
};
|
||||
log::info!("MySQL server rejected group_concat_max_len setup syntax; retrying with {fallback_mode:?} mode");
|
||||
log::info!(
|
||||
"MySQL server rejected optional group_concat_max_len setup; retrying with {fallback_mode:?} mode"
|
||||
);
|
||||
let fallback_pool = create_pool(
|
||||
url,
|
||||
ca_cert_path,
|
||||
@@ -758,7 +760,14 @@ fn mysql_group_concat_setup_fallback_mode(setup_mode: MySqlSetupMode, error: &st
|
||||
let sphinxql_setup_query_rejected = lower.contains("sphinxql")
|
||||
&& lower.contains("only 0 and 1 could be used as boolean values")
|
||||
&& lower.contains(&format!("near '{MYSQL_GROUP_CONCAT_MAX_LEN}'"));
|
||||
if (lower.contains("group_concat_max_len") && setup_query_rejected) || sphinxql_setup_query_rejected {
|
||||
// Some MySQL gateways omit the variable name and report session-variable
|
||||
// changes as a forbidden global-variable operation.
|
||||
let gateway_session_variable_rejected =
|
||||
lower.contains("error 10192 (hy000)") && lower.contains("set global variables is forbidden");
|
||||
if (lower.contains("group_concat_max_len") && setup_query_rejected)
|
||||
|| sphinxql_setup_query_rejected
|
||||
|| gateway_session_variable_rejected
|
||||
{
|
||||
return Some(MySqlSetupMode::Compatible);
|
||||
}
|
||||
|
||||
@@ -4861,6 +4870,27 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_gateway_forbidden_global_variables_error_retries_without_session_variable() {
|
||||
let error = "MySQL connection failed: Server error: `ERROR 10192 (HY000): SET GLOBAL VARIABLES is forbidden'";
|
||||
|
||||
assert_eq!(
|
||||
mysql_group_concat_setup_fallback_mode(MySqlSetupMode::Standard, error),
|
||||
Some(MySqlSetupMode::Compatible)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_gateway_setup_retry_requires_exact_error_code_and_message() {
|
||||
for error in [
|
||||
"Server error: ERROR 10192 (HY000): operation is forbidden",
|
||||
"Server error: ERROR 1227 (42000): SET GLOBAL VARIABLES is forbidden",
|
||||
"Server error: ERROR 101920 (HY000): SET GLOBAL VARIABLES is forbidden",
|
||||
] {
|
||||
assert_eq!(mysql_group_concat_setup_fallback_mode(MySqlSetupMode::Standard, error), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_sphinxql_group_concat_boolean_error_retries_without_session_variable() {
|
||||
let error = "MySQL connection failed: Server error: `ERROR 42000 (1064): sphinxql: only 0 and 1 could be used as boolean values near '1048576'`";
|
||||
|
||||
@@ -210,6 +210,15 @@ async fn questdb_normal_view_ddl(pool: &Pool, view: &str) -> Result<String, Stri
|
||||
first_string_cell(db::postgres::execute_query(pool, &sql).await?)
|
||||
}
|
||||
|
||||
fn first_string_cell(result: QueryResult) -> Result<String, String> {
|
||||
result
|
||||
.rows
|
||||
.first()
|
||||
.and_then(|row| row.iter().find_map(|value| value.as_str().map(str::to_string)))
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
.ok_or_else(|| "Object source not found".to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -221,12 +230,3 @@ mod tests {
|
||||
assert_eq!(questdb_tables_sql_basic(), "SELECT table_name FROM tables()");
|
||||
}
|
||||
}
|
||||
|
||||
fn first_string_cell(result: QueryResult) -> Result<String, String> {
|
||||
result
|
||||
.rows
|
||||
.first()
|
||||
.and_then(|row| row.iter().find_map(|value| value.as_str().map(str::to_string)))
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
.ok_or_else(|| "Object source not found".to_string())
|
||||
}
|
||||
Reference in new issue
Block a user