From 25b8eeb415131419c1125ea8f09a35010914459d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 22 Apr 2020 09:06:58 +0300 Subject: [PATCH] MXS-2972: Store servers in the cache key This allows the set of servers used by the service to also participate in the cache value resolution. This will prevent the most obvious of problems but any abstractions of the servers will prevent this from working. --- .../schemarouter/schemaroutersession.cc | 19 +++++++++++++++++-- .../schemarouter/schemaroutersession.hh | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/server/modules/routing/schemarouter/schemaroutersession.cc b/server/modules/routing/schemarouter/schemaroutersession.cc index 6e3ac02ee..9cc287eb7 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.cc +++ b/server/modules/routing/schemarouter/schemaroutersession.cc @@ -45,7 +45,7 @@ SchemaRouterSession::SchemaRouterSession(MXS_SESSION* session, , m_backends(backends) , m_config(router->m_config) , m_router(router) - , m_shard(m_router->m_shard_manager.get_shard(m_client->user, m_config->refresh_min_interval)) + , m_shard(m_router->m_shard_manager.get_shard(get_cache_key(), m_config->refresh_min_interval)) , m_state(0) , m_sent_sescmd(0) , m_replied_sescmd(0) @@ -665,7 +665,7 @@ void SchemaRouterSession::handleError(GWBUF* pMessage, void SchemaRouterSession::synchronize_shards() { m_router->m_stats.shmap_cache_miss++; - m_router->m_shard_manager.update_shard(m_shard, m_client->user); + m_router->m_shard_manager.update_shard(m_shard, get_cache_key()); } /** @@ -1784,4 +1784,19 @@ SERVER* SchemaRouterSession::get_ps_target(GWBUF* buffer, uint32_t qtype, qc_que } return rval; } + +std::string SchemaRouterSession::get_cache_key() const +{ + std::string key = m_client->user; + + for (const auto& b : m_backends) + { + if (b->in_use()) + { + key += b->name(); + } + } + + return key; +} } diff --git a/server/modules/routing/schemarouter/schemaroutersession.hh b/server/modules/routing/schemarouter/schemaroutersession.hh index e554591a1..3791884ce 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.hh +++ b/server/modules/routing/schemarouter/schemaroutersession.hh @@ -151,6 +151,7 @@ private: void synchronize_shards(); void handle_mapping_reply(SSRBackend& bref, GWBUF** pPacket); bool handle_statement(GWBUF* querybuf, SSRBackend& bref, uint8_t command, uint32_t type); + std::string get_cache_key() const; /** Member variables */ bool m_closed; /**< True if session closed */