From 7767231c8f03bc56924a9ed77beaeec1df6e1571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 30 Sep 2019 08:41:50 +0300 Subject: [PATCH] MXS-2264: Fix table versioning The table versions are now stored in memory and are only resolved on startup. This simplifies things and removes the need to know where the data is stored as that information is not available to the Rpl class. --- server/modules/routing/avrorouter/avro_rbr.cc | 1 + server/modules/routing/avrorouter/rpl.cc | 21 +++---------------- server/modules/routing/avrorouter/rpl.hh | 2 ++ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/server/modules/routing/avrorouter/avro_rbr.cc b/server/modules/routing/avrorouter/avro_rbr.cc index 07991090a..3258caef2 100644 --- a/server/modules/routing/avrorouter/avro_rbr.cc +++ b/server/modules/routing/avrorouter/avro_rbr.cc @@ -836,6 +836,7 @@ bool Rpl::save_and_replace_table_create(STableCreateEvent created) } } + created->version = ++m_versions[created->id()]; m_created_tables[table_ident] = created; mxb_assert(created->columns.size() > 0); return m_handler->create_table(created); diff --git a/server/modules/routing/avrorouter/rpl.cc b/server/modules/routing/avrorouter/rpl.cc index a09eb82f8..c736acb2f 100644 --- a/server/modules/routing/avrorouter/rpl.cc +++ b/server/modules/routing/avrorouter/rpl.cc @@ -522,21 +522,6 @@ static void process_column_definition(const char* nameptr, std::vector& } } -int resolve_table_version(const char* db, const char* table) -{ - int version = 0; - char buf[PATH_MAX + 1]; - - do - { - version++; - snprintf(buf, sizeof(buf), "%s.%s.%06d.avsc", db, table, version); - } - while (access(buf, F_OK) == 0); - - return version; -} - /** * @brief Handle a query event which contains a CREATE TABLE statement * @@ -569,8 +554,7 @@ STableCreateEvent table_create_alloc(char* ident, const char* sql, int len) if (!columns.empty()) { - int version = resolve_table_version(database, table); - rval.reset(new(std::nothrow) TableCreateEvent(database, table, version, std::move(columns))); + rval.reset(new(std::nothrow) TableCreateEvent(database, table, 0, std::move(columns))); } else { @@ -686,6 +670,7 @@ void Rpl::add_create(STableCreateEvent create) if (it == m_created_tables.end() || create->version > it->second->version) { m_created_tables[create->id()] = create; + m_versions[create->id()] = create->version; } } @@ -1408,7 +1393,7 @@ bool Rpl::table_create_alter(STableCreateEvent create, const char* sql, const ch create->table = new_name; } - create->version = 1; + create->version = ++m_versions[create->id()]; create->was_used = false; rename_table_create(create, old_id); diff --git a/server/modules/routing/avrorouter/rpl.hh b/server/modules/routing/avrorouter/rpl.hh index 173fcecdf..5eb1c9296 100644 --- a/server/modules/routing/avrorouter/rpl.hh +++ b/server/modules/routing/avrorouter/rpl.hh @@ -285,6 +285,8 @@ private: pcre2_match_data* m_md_match; pcre2_match_data* m_md_exclude; + std::unordered_map m_versions; // Table version numbers per identifier + void handle_query_event(REP_HEADER* hdr, uint8_t* ptr); bool handle_table_map_event(REP_HEADER* hdr, uint8_t* ptr); bool handle_row_event(REP_HEADER* hdr, uint8_t* ptr);