diff --git a/server/modules/routing/avrorouter/avro_rbr.cc b/server/modules/routing/avrorouter/avro_rbr.cc index 5f83c5143..07991090a 100644 --- a/server/modules/routing/avrorouter/avro_rbr.cc +++ b/server/modules/routing/avrorouter/avro_rbr.cc @@ -841,6 +841,27 @@ bool Rpl::save_and_replace_table_create(STableCreateEvent created) return m_handler->create_table(created); } +bool Rpl::rename_table_create(STableCreateEvent created, const std::string& old_id) +{ + auto it = m_created_tables.find(old_id); + + if (it != m_created_tables.end()) + { + auto tm_it = m_table_maps.find(old_id); + + if (tm_it != m_table_maps.end()) + { + m_active_maps.erase(tm_it->second->id); + m_table_maps.erase(tm_it); + } + } + + m_created_tables.erase(old_id); + m_created_tables[created->id()] = created; + mxb_assert(created->columns.size() > 0); + return m_handler->create_table(created); +} + void unify_whitespace(char* sql, int len) { for (int i = 0; i < len; i++) diff --git a/server/modules/routing/avrorouter/rpl.cc b/server/modules/routing/avrorouter/rpl.cc index e8da7f859..a09eb82f8 100644 --- a/server/modules/routing/avrorouter/rpl.cc +++ b/server/modules/routing/avrorouter/rpl.cc @@ -1381,6 +1381,38 @@ bool Rpl::table_create_alter(STableCreateEvent create, const char* sql, const ch } } + tok = get_next_def(tok, end); + len = 0; + } + else if (tok_eq(ptok, "rename", plen)) + { + if (tok_eq(tok, "to", len)) + { + // Skip the optional TO keyword + tok = get_tok(tok + len, &len, end); + } + + char new_name[len + 1]; + make_avro_token(new_name, tok, len); + + auto old_id = create->id(); + + if (char* p = strchr(new_name, '.')) + { + *p++ = '\0'; + create->database = new_name; + create->table = p; + } + else + { + create->table = new_name; + } + + create->version = 1; + create->was_used = false; + + rename_table_create(create, old_id); + tok = get_next_def(tok, end); len = 0; } diff --git a/server/modules/routing/avrorouter/rpl.hh b/server/modules/routing/avrorouter/rpl.hh index 4ecf61653..173fcecdf 100644 --- a/server/modules/routing/avrorouter/rpl.hh +++ b/server/modules/routing/avrorouter/rpl.hh @@ -290,6 +290,7 @@ private: bool handle_row_event(REP_HEADER* hdr, uint8_t* ptr); STableCreateEvent table_create_copy(const char* sql, size_t len, const char* db); bool save_and_replace_table_create(STableCreateEvent created); + bool rename_table_create(STableCreateEvent created, const std::string& old_id); bool table_create_alter(STableCreateEvent create, const char* sql, const char* end); bool table_matches(const std::string& ident); };