diff --git a/server/modules/routing/avrorouter/avro_file.cc b/server/modules/routing/avrorouter/avro_file.cc index d28f3d6a5..662968c3c 100644 --- a/server/modules/routing/avrorouter/avro_file.cc +++ b/server/modules/routing/avrorouter/avro_file.cc @@ -756,7 +756,7 @@ bool is_alter_table_statement(pcre2_code* alter_table_re, char* ptr, size_t len) */ bool Rpl::save_and_replace_table_create(STableCreateEvent created) { - std::string table_ident = created->database + "." + created->table; + std::string table_ident = created->id(); auto it = m_created_tables.find(table_ident); if (it != m_created_tables.end()) @@ -772,7 +772,7 @@ bool Rpl::save_and_replace_table_create(STableCreateEvent created) m_created_tables[table_ident] = created; ss_dassert(created->columns.size() > 0); - return true; + return m_handler->create_table(created); } void unify_whitespace(char *sql, int len) @@ -909,7 +909,7 @@ void Rpl::handle_query_event(REP_HEADER *hdr, uint8_t *ptr) if (it != m_created_tables.end()) { - table_create_alter(it->second.get(), sql, sql + len); + table_create_alter(it->second, sql, sql + len); } else { diff --git a/server/modules/routing/avrorouter/avro_schema.cc b/server/modules/routing/avrorouter/avro_schema.cc index b44e28901..594ba87c7 100644 --- a/server/modules/routing/avrorouter/avro_schema.cc +++ b/server/modules/routing/avrorouter/avro_schema.cc @@ -1131,7 +1131,7 @@ static bool not_column_operation(const char* tok, int len) return false; } -bool table_create_alter(TableCreateEvent *create, const char *sql, const char *end) +bool Rpl::table_create_alter(STableCreateEvent create, const char *sql, const char *end) { const char *tbl = strcasestr(sql, "table"), *def; @@ -1250,6 +1250,15 @@ bool table_create_alter(TableCreateEvent *create, const char *sql, const char *e { create->version++; create->was_used = false; + + /** + * Although the table was only altered, we can treat it like it + * would have been just created. This allows for a minimal API that + * only creates and replaces tables. + * + * TODO: Add DROP TABLE entry point for pruning old tables + */ + m_handler->create_table(create); } } diff --git a/server/modules/routing/avrorouter/rpl.hh b/server/modules/routing/avrorouter/rpl.hh index 8b42d9277..eecf31500 100644 --- a/server/modules/routing/avrorouter/rpl.hh +++ b/server/modules/routing/avrorouter/rpl.hh @@ -140,6 +140,12 @@ public: { } + // A table was created + virtual bool create_table(const STableCreateEvent& create) + { + return true; + } + // A table was opened virtual bool open_table(const STableMapEvent& map, const STableCreateEvent& create) { @@ -241,4 +247,5 @@ 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 table_create_alter(STableCreateEvent create, const char *sql, const char *end); };