MXS-1881: Add table creation method to RowEventHandler
The new method is called for each new CREATE TABLE statement that is processed as well as all ALTER TABLE statemets that modify the table structure. Right now the entry point not in use but it opens up the possibility of persisting the CREATE TABLE statements at creation time. Currently the tables are only persisted when the first actual event for the table is received.
This commit is contained in:
parent
c27529c9a4
commit
3417842e75
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user