Add readwritesplit options to diagnostic output

This helps detect the state of the loaded configuration.
This commit is contained in:
Markus Mäkelä
2017-01-27 10:02:33 +02:00
parent 6f24502e14
commit 50cffed5b2
3 changed files with 92 additions and 10 deletions

View File

@ -113,4 +113,26 @@ typedef enum
TYPE_ALL TYPE_ALL
} mxs_target_t; } mxs_target_t;
/**
* @brief Convert mxs_target_t to a string
*
* @param target Target to convert
*
* @return Target type as string
*/
static inline const char* mxs_target_to_str(mxs_target_t target)
{
switch (target)
{
case TYPE_MASTER:
return "master";
case TYPE_ALL:
return "all";
default:
return "UNDEFINED";
}
}
MXS_END_DECLS MXS_END_DECLS

View File

@ -596,6 +596,27 @@ static void diagnostics(MXS_ROUTER *instance, DCB *dcb)
char *weightby; char *weightby;
double master_pct = 0.0, slave_pct = 0.0, all_pct = 0.0; double master_pct = 0.0, slave_pct = 0.0, all_pct = 0.0;
dcb_printf(dcb, "\n");
dcb_printf(dcb, "\tuse_sql_variables_in: %s\n",
mxs_target_to_str(router->rwsplit_config.use_sql_variables_in));
dcb_printf(dcb, "\tslave_selection_criteria: %s\n",
select_criteria_to_str(router->rwsplit_config.slave_selection_criteria));
dcb_printf(dcb, "\tmaster_failure_mode: %s\n",
failure_mode_to_str(router->rwsplit_config.master_failure_mode));
dcb_printf(dcb, "\tmax_slave_replication_lag: %d\n",
router->rwsplit_config.max_slave_replication_lag);
dcb_printf(dcb, "\tretry_failed_reads: %s\n",
router->rwsplit_config.retry_failed_reads ? "true" : "false");
dcb_printf(dcb, "\tstrict_multi_stmt: %s\n",
router->rwsplit_config.strict_multi_stmt ? "true" : "false");
dcb_printf(dcb, "\tdisable_sescmd_history: %s\n",
router->rwsplit_config.disable_sescmd_history ? "true" : "false");
dcb_printf(dcb, "\tmax_sescmd_history: %d\n",
router->rwsplit_config.max_sescmd_history);
dcb_printf(dcb, "\tmaster_accept_reads: %s\n",
router->rwsplit_config.master_accept_reads ? "true" : "false");
dcb_printf(dcb, "\n");
if (router->stats.n_queries > 0) if (router->stats.n_queries > 0)
{ {
master_pct = ((double)router->stats.n_master / (double)router->stats.n_queries) * 100.0; master_pct = ((double)router->stats.n_master / (double)router->stats.n_queries) * 100.0;

View File

@ -110,6 +110,55 @@ typedef enum select_criteria
LAST_CRITERIA /*< not used except for an index */ LAST_CRITERIA /*< not used except for an index */
} select_criteria_t; } select_criteria_t;
static inline const char* select_criteria_to_str(select_criteria_t type)
{
switch (type)
{
case LEAST_GLOBAL_CONNECTIONS:
return "LEAST_GLOBAL_CONNECTIONS";
case LEAST_ROUTER_CONNECTIONS:
return "LEAST_ROUTER_CONNECTIONS";
case LEAST_BEHIND_MASTER:
return "LEAST_BEHIND_MASTER";
case LEAST_CURRENT_OPERATIONS:
return "LEAST_CURRENT_OPERATIONS";
default:
return "UNDEFINED_CRITERIA";
}
}
/**
* Controls how master failure is handled
*/
enum failure_mode
{
RW_FAIL_INSTANTLY, /**< Close the connection as soon as the master is lost */
RW_FAIL_ON_WRITE, /**< Close the connection when the first write is received */
RW_ERROR_ON_WRITE /**< Don't close the connection but send an error for writes */
};
static inline const char* failure_mode_to_str(enum failure_mode type)
{
switch (type)
{
case RW_FAIL_INSTANTLY:
return "fail_instantly";
case RW_FAIL_ON_WRITE:
return "fail_on_write";
case RW_ERROR_ON_WRITE:
return "error_on_write";
default:
ss_dassert(false);
return "UNDEFINED_MODE";
}
}
/** default values for rwsplit configuration parameters */ /** default values for rwsplit configuration parameters */
#define CONFIG_MAX_SLAVE_CONN 1 #define CONFIG_MAX_SLAVE_CONN 1
@ -209,16 +258,6 @@ typedef struct backend_ref_st
int closed_at; /** DEBUG: Line number where this backend reference was closed */ int closed_at; /** DEBUG: Line number where this backend reference was closed */
} backend_ref_t; } backend_ref_t;
/**
* Controls how master failure is handled
*/
enum failure_mode
{
RW_FAIL_INSTANTLY, /**< Close the connection as soon as the master is lost */
RW_FAIL_ON_WRITE, /**< Close the connection when the first write is received */
RW_ERROR_ON_WRITE /**< Don't close the connection but send an error for writes */
};
typedef struct rwsplit_config_st typedef struct rwsplit_config_st
{ {
int rw_max_slave_conn_percent; /**< Maximum percentage of slaves int rw_max_slave_conn_percent; /**< Maximum percentage of slaves