1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MDEV-15530: Variable replicate_rewrite_db cannot be found in "show global variables"

- Add `replicate_rewrite_db` status variable, that may accept comma
separated key-value pairs.
- Note that option `OPT_REPLICATE_REWRITE_DB` already existed in `mysqld.h`
  from this commit 23d8586dbf

Reviewer:Brandon Nesterenko <brandon.nesterenko@mariadb.com>
This commit is contained in:
Anel Husakovic
2022-08-09 13:50:12 +02:00
committed by Brandon Nesterenko
parent ccf0e27f28
commit 1a057a923b
30 changed files with 936 additions and 141 deletions

View File

@ -48,7 +48,7 @@ Rpl_filter::~Rpl_filter()
free_string_array(&wild_ignore_table);
free_string_list(&do_db);
free_string_list(&ignore_db);
free_list(&rewrite_db);
free_string_pair_list(&rewrite_db);
}
@ -470,14 +470,6 @@ Rpl_filter::set_wild_ignore_table(const char* table_spec)
}
void
Rpl_filter::add_db_rewrite(const char* from_db, const char* to_db)
{
i_string_pair *db_pair = new i_string_pair(from_db, to_db);
rewrite_db.push_back(db_pair);
}
int
Rpl_filter::add_table_rule(HASH* h, const char* table_spec)
{
@ -520,6 +512,70 @@ Rpl_filter::add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec)
}
int
Rpl_filter::add_string_pair_list(const char* spec)
{
/* See also OPT_REWRITE_DB handling in client/mysqlbinlog.cc */
char* from_db, *to_db;
const char *ptr, *val_ptr;
size_t len;
// Remove pre-space in key
while(*spec && my_isspace(system_charset_info, (unsigned char)*spec)) spec++;
if (!(ptr= strstr(spec, "->")))
{
// Bad syntax, missing ->
return 1;
}
// value
val_ptr= ptr + 2;
// Skip blanks at the end of spec
while(ptr > spec && my_isspace(system_charset_info, ptr[-1])) ptr--;
if (ptr == spec)
{
// Bad syntax: empty FROM db (key)
return 1;
}
// key
len= (size_t)(ptr - spec);
if (! (from_db= (char *) my_malloc(PSI_NOT_INSTRUMENTED, len + 1, MYF(0))))
{
return 1;
}
memcpy(from_db, spec, len);
from_db[len]='\0';
// Remove pre-space in val
while(*val_ptr && my_isspace(system_charset_info, (unsigned char)*val_ptr)) val_ptr++;
// Value ends with \0 or space
if (!strlen(val_ptr))
{
// Bad syntax: Empty value \n"
my_free(from_db);
return 1;
}
for (ptr= val_ptr; *ptr && !my_isspace(system_charset_info, *ptr); ptr++){}
// value
len= (size_t)(ptr - val_ptr);
if(! (to_db= (char *) my_malloc(PSI_NOT_INSTRUMENTED, len + 1, MYF(0))))
{
my_free(from_db);
return 1;
}
memcpy(to_db, val_ptr, len);
to_db[len]='\0';
i_string_pair *db_pair = new i_string_pair(from_db, to_db);
rewrite_db.push_back(db_pair);
return false;
}
int
Rpl_filter::add_string_list(I_List<i_string> *list, const char* spec)
{
@ -541,6 +597,14 @@ Rpl_filter::add_string_list(I_List<i_string> *list, const char* spec)
}
int
Rpl_filter::add_rewrite_db(const char* table_spec)
{
DBUG_ENTER("Rpl_filter::add_rewrite_db");
DBUG_RETURN(add_string_pair_list(table_spec));
}
int
Rpl_filter::add_do_db(const char* table_spec)
{
@ -557,6 +621,14 @@ Rpl_filter::add_ignore_db(const char* table_spec)
}
int
Rpl_filter::set_rewrite_db(const char* db_spec)
{
free_string_pair_list(&rewrite_db);
return parse_filter_rule(db_spec, &Rpl_filter::add_rewrite_db);
}
int
Rpl_filter::set_do_db(const char* db_spec)
{
@ -665,6 +737,21 @@ Rpl_filter::free_string_list(I_List<i_string> *l)
}
void
Rpl_filter::free_string_pair_list(I_List<i_string_pair> *l)
{
i_string_pair *tmp;
while ((tmp= l->get()))
{
my_free((void *) tmp->key);
my_free((void *) tmp->val);
delete tmp;
}
l->empty();
}
/*
Builds a String from a HASH of TABLE_RULE_ENT. Cannot be used for any other
hash, as it assumes that the hash entries are TABLE_RULE_ENT.
@ -749,6 +836,34 @@ Rpl_filter::rewrite_db_is_empty()
}
I_List<i_string_pair>*
Rpl_filter::get_rewrite_db()
{
return &rewrite_db;
}
void
Rpl_filter::db_rewrite_rule_ent_list_to_str(String* str, I_List<i_string_pair>* list)
{
I_List_iterator<i_string_pair> it(*list);
i_string_pair* s;
str->length(0);
const char *delimiter= ",";
size_t delim_len= 0;
while ((s= it++))
{
str->append(delimiter, delim_len);
str->append(s->key, strlen(s->key));
str->append(STRING_WITH_LEN("->"));
str->append(s->val, strlen(s->val));
delim_len= 1;
}
}
const char*
Rpl_filter::get_rewrite_db(const char* db, size_t *new_len)
{
@ -769,18 +884,6 @@ Rpl_filter::get_rewrite_db(const char* db, size_t *new_len)
}
void
Rpl_filter::copy_rewrite_db(Rpl_filter *from)
{
I_List_iterator<i_string_pair> it(from->rewrite_db);
i_string_pair* tmp;
DBUG_ASSERT(rewrite_db.is_empty());
/* TODO: Add memory checking here and in all add_xxxx functions ! */
while ((tmp=it++))
add_db_rewrite(tmp->key, tmp->val);
}
I_List<i_string>*
Rpl_filter::get_do_db()
{
@ -815,6 +918,13 @@ Rpl_filter::db_rule_ent_list_to_str(String* str, I_List<i_string>* list)
}
void
Rpl_filter::get_rewrite_db(String* str)
{
db_rewrite_rule_ent_list_to_str(str, get_rewrite_db());
}
void
Rpl_filter::get_do_db(String* str)
{