Rename member variables
Renamed and cleaned up schemarouter member variables. Removed unused variables.
This commit is contained in:
parent
ac641e0f22
commit
39903e40b7
@ -47,23 +47,23 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
|
||||
MXS_CONFIG_PARAMETER* param;
|
||||
|
||||
/** Add default system databases to ignore */
|
||||
this->ignored_dbs.insert("mysql");
|
||||
this->ignored_dbs.insert("information_schema");
|
||||
this->ignored_dbs.insert("performance_schema");
|
||||
this->service = service;
|
||||
this->stats.longest_sescmd = 0;
|
||||
this->stats.n_hist_exceeded = 0;
|
||||
this->stats.n_queries = 0;
|
||||
this->stats.n_sescmd = 0;
|
||||
this->stats.ses_longest = 0;
|
||||
this->stats.ses_shortest = (double)((unsigned long)(~0));
|
||||
spinlock_init(&this->lock);
|
||||
this->m_ignored_dbs.insert("mysql");
|
||||
this->m_ignored_dbs.insert("information_schema");
|
||||
this->m_ignored_dbs.insert("performance_schema");
|
||||
this->m_service = service;
|
||||
this->m_stats.longest_sescmd = 0;
|
||||
this->m_stats.n_hist_exceeded = 0;
|
||||
this->m_stats.n_queries = 0;
|
||||
this->m_stats.n_sescmd = 0;
|
||||
this->m_stats.ses_longest = 0;
|
||||
this->m_stats.ses_shortest = (double)((unsigned long)(~0));
|
||||
spinlock_init(&this->m_lock);
|
||||
|
||||
conf = service->svc_config_param;
|
||||
|
||||
this->schemarouter_config.refresh_databases = config_get_bool(conf, "refresh_databases");
|
||||
this->schemarouter_config.refresh_min_interval = config_get_integer(conf, "refresh_interval");
|
||||
this->schemarouter_config.debug = config_get_bool(conf, "debug");
|
||||
this->m_config.refresh_databases = config_get_bool(conf, "refresh_databases");
|
||||
this->m_config.refresh_min_interval = config_get_integer(conf, "refresh_interval");
|
||||
this->m_config.debug = config_get_bool(conf, "debug");
|
||||
|
||||
if ((config_get_param(conf, "auth_all_servers")) == NULL)
|
||||
{
|
||||
@ -96,8 +96,8 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
this->ignore_regex = re;
|
||||
this->ignore_match_data = match_data;
|
||||
this->m_ignore_regex = re;
|
||||
this->m_ignore_match_data = match_data;
|
||||
}
|
||||
|
||||
if ((param = config_get_param(conf, "ignore_databases")))
|
||||
@ -111,7 +111,7 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
|
||||
|
||||
while (tok)
|
||||
{
|
||||
this->ignored_dbs.insert(tok);
|
||||
this->m_ignored_dbs.insert(tok);
|
||||
tok = strtok_r(NULL, sep, &sptr);
|
||||
}
|
||||
}
|
||||
@ -142,15 +142,15 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
|
||||
}
|
||||
else if (strcmp(options[i], "refresh_databases") == 0)
|
||||
{
|
||||
this->schemarouter_config.refresh_databases = config_truth_value(value);
|
||||
this->m_config.refresh_databases = config_truth_value(value);
|
||||
}
|
||||
else if (strcmp(options[i], "refresh_interval") == 0)
|
||||
{
|
||||
this->schemarouter_config.refresh_min_interval = atof(value);
|
||||
this->m_config.refresh_min_interval = atof(value);
|
||||
}
|
||||
else if (strcmp(options[i], "debug") == 0)
|
||||
{
|
||||
this->schemarouter_config.debug = config_truth_value(value);
|
||||
this->m_config.debug = config_truth_value(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -168,14 +168,14 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
|
||||
|
||||
SchemaRouter::~SchemaRouter()
|
||||
{
|
||||
if (this->ignore_regex)
|
||||
if (this->m_ignore_regex)
|
||||
{
|
||||
pcre2_code_free(this->ignore_regex);
|
||||
pcre2_code_free(this->m_ignore_regex);
|
||||
}
|
||||
|
||||
if (this->ignore_match_data)
|
||||
if (this->m_ignore_match_data)
|
||||
{
|
||||
pcre2_match_data_free(this->ignore_match_data);
|
||||
pcre2_match_data_free(this->m_ignore_match_data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,32 +191,32 @@ SchemaRouterSession* SchemaRouter::newSession(MXS_SESSION* pSession)
|
||||
|
||||
void SchemaRouter::diagnostics(DCB* dcb)
|
||||
{
|
||||
double sescmd_pct = this->stats.n_sescmd != 0 ?
|
||||
100.0 * ((double)this->stats.n_sescmd / (double)this->stats.n_queries) :
|
||||
double sescmd_pct = this->m_stats.n_sescmd != 0 ?
|
||||
100.0 * ((double)this->m_stats.n_sescmd / (double)this->m_stats.n_queries) :
|
||||
0.0;
|
||||
|
||||
/** Session command statistics */
|
||||
dcb_printf(dcb, "\n\33[1;4mSession Commands\33[0m\n");
|
||||
dcb_printf(dcb, "Total number of queries: %d\n",
|
||||
this->stats.n_queries);
|
||||
this->m_stats.n_queries);
|
||||
dcb_printf(dcb, "Percentage of session commands: %.2f\n",
|
||||
sescmd_pct);
|
||||
dcb_printf(dcb, "Longest chain of stored session commands: %d\n",
|
||||
this->stats.longest_sescmd);
|
||||
this->m_stats.longest_sescmd);
|
||||
dcb_printf(dcb, "Session command history limit exceeded: %d times\n",
|
||||
this->stats.n_hist_exceeded);
|
||||
this->m_stats.n_hist_exceeded);
|
||||
|
||||
/** Session time statistics */
|
||||
|
||||
if (this->stats.sessions > 0)
|
||||
if (this->m_stats.sessions > 0)
|
||||
{
|
||||
dcb_printf(dcb, "\n\33[1;4mSession Time Statistics\33[0m\n");
|
||||
dcb_printf(dcb, "Longest session: %.2lf seconds\n", this->stats.ses_longest);
|
||||
dcb_printf(dcb, "Shortest session: %.2lf seconds\n", this->stats.ses_shortest);
|
||||
dcb_printf(dcb, "Average session length: %.2lf seconds\n", this->stats.ses_average);
|
||||
dcb_printf(dcb, "Longest session: %.2lf seconds\n", this->m_stats.ses_longest);
|
||||
dcb_printf(dcb, "Shortest session: %.2lf seconds\n", this->m_stats.ses_shortest);
|
||||
dcb_printf(dcb, "Average session length: %.2lf seconds\n", this->m_stats.ses_average);
|
||||
}
|
||||
dcb_printf(dcb, "Shard map cache hits: %d\n", this->stats.shmap_cache_hit);
|
||||
dcb_printf(dcb, "Shard map cache misses: %d\n", this->stats.shmap_cache_miss);
|
||||
dcb_printf(dcb, "Shard map cache hits: %d\n", this->m_stats.shmap_cache_hit);
|
||||
dcb_printf(dcb, "Shard map cache misses: %d\n", this->m_stats.shmap_cache_miss);
|
||||
dcb_printf(dcb, "\n");
|
||||
}
|
||||
|
||||
|
@ -42,20 +42,19 @@ public:
|
||||
|
||||
protected:
|
||||
friend class SchemaRouterSession;
|
||||
schemarouter_config_t schemarouter_config; /*< expanded config info from SERVICE */
|
||||
|
||||
ShardManager shard_manager; /*< Shard maps hashed by user name */
|
||||
SERVICE* service; /*< Pointer to service */
|
||||
SPINLOCK lock; /*< Lock for the instance data */
|
||||
int schemarouter_version; /*< version number for router's config */
|
||||
ROUTER_STATS stats; /*< Statistics for this router */
|
||||
set<string> ignored_dbs; /*< List of databases to ignore when the
|
||||
* database mapping finds multiple servers
|
||||
* with the same database */
|
||||
pcre2_code* ignore_regex; /*< Databases matching this regex will
|
||||
* not cause the session to be terminated
|
||||
* if they are found on more than one server. */
|
||||
pcre2_match_data* ignore_match_data;
|
||||
schemarouter_config_t m_config; /*< expanded config info from SERVICE */
|
||||
ShardManager m_shard_manager; /*< Shard maps hashed by user name */
|
||||
SERVICE* m_service; /*< Pointer to service */
|
||||
SPINLOCK m_lock; /*< Lock for the instance data */
|
||||
ROUTER_STATS m_stats; /*< Statistics for this router */
|
||||
set<string> m_ignored_dbs; /*< List of databases to ignore when the
|
||||
* database mapping finds multiple servers
|
||||
* with the same database */
|
||||
pcre2_code* m_ignore_regex; /*< Databases matching this regex will
|
||||
* not cause the session to be terminated
|
||||
* if they are found on more than one server. */
|
||||
pcre2_match_data* m_ignore_match_data;
|
||||
|
||||
SchemaRouter(SERVICE *service, char **options);
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -56,12 +56,12 @@ typedef enum bref_state
|
||||
BREF_DB_MAPPED = 0x10
|
||||
} bref_state_t;
|
||||
|
||||
#define BREF_IS_NOT_USED(s) ((s)->bref_state & ~BREF_IN_USE)
|
||||
#define BREF_IS_IN_USE(s) ((s)->bref_state & BREF_IN_USE)
|
||||
#define BREF_IS_WAITING_RESULT(s) ((s)->bref_num_result_wait > 0)
|
||||
#define BREF_IS_QUERY_ACTIVE(s) ((s)->bref_state & BREF_QUERY_ACTIVE)
|
||||
#define BREF_IS_CLOSED(s) ((s)->bref_state & BREF_CLOSED)
|
||||
#define BREF_IS_MAPPED(s) ((s)->bref_mapped)
|
||||
#define BREF_IS_NOT_USED(s) ((s)->state & ~BREF_IN_USE)
|
||||
#define BREF_IS_IN_USE(s) ((s)->state & BREF_IN_USE)
|
||||
#define BREF_IS_WAITING_RESULT(s) ((s)->num_result_wait > 0)
|
||||
#define BREF_IS_QUERY_ACTIVE(s) ((s)->state & BREF_QUERY_ACTIVE)
|
||||
#define BREF_IS_CLOSED(s) ((s)->state & BREF_CLOSED)
|
||||
#define BREF_IS_MAPPED(s) ((s)->mapped)
|
||||
|
||||
#define SCHEMA_ERR_DUPLICATEDB 5000
|
||||
#define SCHEMA_ERRSTR_DUPLICATEDB "DUPDB"
|
||||
@ -94,13 +94,12 @@ typedef struct backend_ref_st
|
||||
{
|
||||
int n_mapping_eof;
|
||||
GWBUF* map_queue;
|
||||
SERVER_REF* bref_backend; /*< Backend server */
|
||||
DCB* bref_dcb; /*< Backend DCB */
|
||||
int bref_state; /*< State of the backend */
|
||||
bool bref_mapped; /*< Whether the backend has been mapped */
|
||||
bool last_sescmd_replied;
|
||||
int bref_num_result_wait; /*< Number of not yet received results */
|
||||
GWBUF* bref_pending_cmd; /*< Pending commands */
|
||||
SERVER_REF* backend; /**< Backend server */
|
||||
DCB* dcb; /**< Backend DCB */
|
||||
int state; /**< State of the backend */
|
||||
bool mapped; /**< Whether the backend has been mapped */
|
||||
int num_result_wait; /**< Number of not yet received results */
|
||||
GWBUF* pending_cmd; /**< Pending commands */
|
||||
|
||||
SessionCommandList session_commands; /**< List of session commands that are
|
||||
* to be executed on this backend server */
|
||||
@ -157,42 +156,37 @@ public:
|
||||
mxs_error_action_t action,
|
||||
bool* pSuccess);
|
||||
private:
|
||||
bool closed; /*< true when closeSession is called */
|
||||
DCB* rses_client_dcb;
|
||||
MYSQL_session* rses_mysql_session; /*< Session client data (username, password, SHA1). */
|
||||
backend_ref_t* rses_backend_ref; /*< Pointer to backend reference array */
|
||||
schemarouter_config_t rses_config; /*< Copied config info from router instance */
|
||||
int rses_nbackends; /*< Number of backends */
|
||||
SchemaRouter& m_router; /*< The router instance */
|
||||
Shard shardmap; /**< Database hash containing names of the databases
|
||||
* mapped to the servers that contain them */
|
||||
string connect_db; /*< Database the user was trying to connect to */
|
||||
string current_db; /*< Current active database */
|
||||
int state; /*< Initialization state bitmask */
|
||||
GWBUF* queue; /*< Query that was received before the session was ready */
|
||||
ROUTER_STATS stats; /*< Statistics for this router */
|
||||
|
||||
uint64_t sent_sescmd; /**< The latest session command being executed */
|
||||
uint64_t replied_sescmd; /**< The last session command reply that was sent to the client */
|
||||
bool m_closed; /**< True if session closed */
|
||||
DCB* m_client; /**< The client DCB */
|
||||
MYSQL_session* m_mysql_session; /**< Session client data (username, password, SHA1). */
|
||||
backend_ref_t* m_backends; /**< Pointer to backend reference array */
|
||||
schemarouter_config_t m_config; /**< Copied config info from router instance */
|
||||
int m_backend_count; /**< Number of backends */
|
||||
SchemaRouter& m_router; /**< The router instance */
|
||||
Shard m_shard; /**< Database to server mapping */
|
||||
string m_connect_db; /**< Database the user was trying to connect to */
|
||||
string m_current_db; /**< Current active database */
|
||||
int m_state; /**< Initialization state bitmask */
|
||||
GWBUF* m_queue; /**< Query that was received before the session was ready */
|
||||
ROUTER_STATS m_stats; /**< Statistics for this router */
|
||||
uint64_t m_sent_sescmd; /**< The latest session command being executed */
|
||||
uint64_t m_replied_sescmd; /**< The last session command reply that was sent to the client */
|
||||
|
||||
/** Internal functions */
|
||||
void synchronize_shard_map();
|
||||
|
||||
int inspect_backend_mapping_states(backend_ref_t *bref, GWBUF** wbuf);
|
||||
|
||||
bool route_session_write(GWBUF* querybuf, uint8_t command);
|
||||
|
||||
bool handle_error_new_connection(DCB* backend_dcb, GWBUF* errmsg);
|
||||
void handle_error_reply_client(DCB* backend_dcb, GWBUF* errmsg);
|
||||
int process_show_shards();
|
||||
bool handle_default_db();
|
||||
void route_queued_query();
|
||||
bool get_shard_dcb(DCB** dcb, char* name);
|
||||
SERVER* get_shard_target(GWBUF* buffer, uint32_t qtype);
|
||||
backend_ref_t* get_bref_from_dcb(DCB* dcb);
|
||||
bool execute_sescmd_in_backend(backend_ref_t* backend_ref);
|
||||
bool get_shard_dcb(DCB** dcb, char* name);
|
||||
bool handle_default_db();
|
||||
bool handle_error_new_connection(DCB* backend_dcb, GWBUF* errmsg);
|
||||
bool have_servers();
|
||||
bool route_session_write(GWBUF* querybuf, uint8_t command);
|
||||
bool send_database_list();
|
||||
int gen_databaselist();
|
||||
int inspect_backend_mapping_states(backend_ref_t *bref, GWBUF** wbuf);
|
||||
int process_show_shards();
|
||||
showdb_response_t parse_showdb_response(backend_ref_t* bref, GWBUF** buffer);
|
||||
bool execute_sescmd_in_backend(backend_ref_t* backend_ref);
|
||||
void handle_error_reply_client(DCB* backend_dcb, GWBUF* errmsg);
|
||||
void route_queued_query();
|
||||
void synchronize_shard_map();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user