Hi!
I have a plugin where I have system variables that I want to be able
to modify at runtime. I have this working but I'm wondering if there
is a better way to do this. Without worrying about thread safety for
the moment, here is a snippet of what I have for one system variable:
static string *tmp_sch_filter_string= NULL;
static int check_filtered_schemas(Session *,
struct st_mysql_sys_var *,
void *,
struct st_mysql_value *value)
{
char buff[STRING_BUFFER_USUAL_SIZE];
int len= sizeof(buff);
const char *input= value->val_str(value, buff, &len);
if (input && filtered_replicator)
{
tmp_sch_filter_string= new(std::nothrow) string(input);
if (tmp_sch_filter_string == NULL)
{
return 1;
}
return 0;
}
return 1;
}
static void set_filtered_schemas(Session *,
struct st_mysql_sys_var *,
void *var_ptr,
const void *save)
{
if (filtered_replicator)
{
if (*(bool *)save != true)
{
filtered_replicator->setSchemaFilter(*tmp_sch_filter_string);
/* update the system variable value */
*(const char **) var_ptr= tmp_sch_filter_string->c_str();
/* we don't need this temporary string anymore */
delete tmp_sch_filter_string;
}
}
}
static DRIZZLE_SYSVAR_STR(filteredschemas,
sysvar_filtered_replicator_sch_filters,
PLUGIN_VAR_OPCMDARG,
N_("List of schemas to filter"),
check_filtered_schemas,
set_filtered_schemas,
NULL);
The above does work as expected but what I'm wondering is whether
there is a better or easier way to do this? For instance, how can I
get the input string to the SET command in the set_filtered_schemas()
method? Is there a way to avoid the copying into a temporary string?
A sample run to show how I update the variable is:
posul...@aghadoe:~/repos/drizzle/filtered-replicator/run$
../client/drizzle --port=9306
Welcome to the Drizzle client.. Commands end with ; or \g.
Your Drizzle connection id is 2
Server version: 2009.07.1067 Source distribution (filtered-replicator)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
drizzle> show variables like '%replicat%';
+-------------------------------------+--------------+
| Variable_name | Value |
+-------------------------------------+--------------+
| default_replicator_enable | OFF |
| filtered_replicator_enable | ON |
| filtered_replicator_filteredschemas | first,second |
| filtered_replicator_filteredtables | me,too |
| innodb_replication_delay | 0 |
+-------------------------------------+--------------+
5 rows in set (0 sec)
drizzle> set global filtered_replicator_filteredschemas = 'third,fourth,fifth';
Query OK, 0 rows affected (0 sec)
drizzle> show variables like '%replicat%';
+-------------------------------------+--------------------+
| Variable_name | Value |
+-------------------------------------+--------------------+
| default_replicator_enable | OFF |
| filtered_replicator_enable | ON |
| filtered_replicator_filteredschemas | third,fourth,fifth |
| filtered_replicator_filteredtables | me,too |
| innodb_replication_delay | 0 |
+-------------------------------------+--------------------+
5 rows in set (0 sec)
drizzle>
-Padraig
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp