mirror of https://github.com/sysown/proxysql
Extract backend variable sync decisions (Phase 3.6, #5494)
New: include/BackendSyncDecision.h, lib/BackendSyncDecision.cpp determine_backend_sync_actions() returns bitmask of needed sync: - SYNC_USER: username mismatch → CHANGE USER required - SYNC_SCHEMA: schema mismatch → USE <db> required (skipped if SYNC_USER set, since CHANGE USER handles schema) - SYNC_AUTOCOMMIT: autocommit state mismatch Covers both MySQL (7 verify functions) and PgSQL (2 verify functions) at the decision level — the core comparisons are the same.pull/5511/head
parent
1354b798b1
commit
ead2331fb9
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file BackendSyncDecision.h
|
||||
* @brief Pure decision functions for backend variable synchronization.
|
||||
*
|
||||
* Extracted from MySQL_Session's verify chain (handler_again___verify_*).
|
||||
* Determines what sync actions are needed before a query can execute
|
||||
* on a backend connection.
|
||||
*
|
||||
* @see Phase 3.6 (GitHub issue #5494)
|
||||
*/
|
||||
|
||||
#ifndef BACKEND_SYNC_DECISION_H
|
||||
#define BACKEND_SYNC_DECISION_H
|
||||
|
||||
/**
|
||||
* @brief Actions that may be needed to synchronize backend state.
|
||||
*/
|
||||
enum BackendSyncAction {
|
||||
SYNC_NONE = 0, ///< No synchronization needed.
|
||||
SYNC_SCHEMA = 1, ///< Schema (USE db) needs to be sent.
|
||||
SYNC_USER = 2, ///< Username mismatch, CHANGE USER required.
|
||||
SYNC_AUTOCOMMIT = 4, ///< Autocommit state needs to be synced.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Determine what sync actions are needed for the backend.
|
||||
*
|
||||
* Checks client vs backend state and returns a bitmask of required
|
||||
* actions. Mirrors the MySQL_Session verify chain logic.
|
||||
*
|
||||
* @param client_user Client connection username.
|
||||
* @param backend_user Backend connection username.
|
||||
* @param client_schema Client connection schema.
|
||||
* @param backend_schema Backend connection schema.
|
||||
* @param client_autocommit Client autocommit setting.
|
||||
* @param backend_autocommit Backend autocommit setting.
|
||||
* @return Bitmask of BackendSyncAction values.
|
||||
*/
|
||||
int determine_backend_sync_actions(
|
||||
const char *client_user,
|
||||
const char *backend_user,
|
||||
const char *client_schema,
|
||||
const char *backend_schema,
|
||||
bool client_autocommit,
|
||||
bool backend_autocommit
|
||||
);
|
||||
|
||||
#endif // BACKEND_SYNC_DECISION_H
|
||||
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @file BackendSyncDecision.cpp
|
||||
* @brief Implementation of backend variable sync decisions.
|
||||
*
|
||||
* @see BackendSyncDecision.h
|
||||
* @see Phase 3.6 (GitHub issue #5494)
|
||||
*/
|
||||
|
||||
#include "BackendSyncDecision.h"
|
||||
#include <cstring>
|
||||
|
||||
int determine_backend_sync_actions(
|
||||
const char *client_user,
|
||||
const char *backend_user,
|
||||
const char *client_schema,
|
||||
const char *backend_schema,
|
||||
bool client_autocommit,
|
||||
bool backend_autocommit)
|
||||
{
|
||||
int actions = SYNC_NONE;
|
||||
|
||||
// Username mismatch → CHANGE USER required
|
||||
if (client_user && backend_user) {
|
||||
if (strcmp(client_user, backend_user) != 0) {
|
||||
actions |= SYNC_USER;
|
||||
}
|
||||
}
|
||||
|
||||
// Schema mismatch → USE <db> required
|
||||
// Only check if usernames match (user change handles schema too)
|
||||
if (!(actions & SYNC_USER)) {
|
||||
if (client_schema && backend_schema) {
|
||||
if (strcmp(client_schema, backend_schema) != 0) {
|
||||
actions |= SYNC_SCHEMA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Autocommit mismatch → SET autocommit required
|
||||
if (client_autocommit != backend_autocommit) {
|
||||
actions |= SYNC_AUTOCOMMIT;
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
Loading…
Reference in new issue