MXS-1113 Add support for prepared statements in schemarouter

Add support for binary protocol prepared statements for schemarouter.
This implementation doesn't yet attempt to handle all the edge cases.

Prepared statements are routed to the server that contains the affected
tables, the internal id from the server is then mapped to the session
command id that is inceremented for each prepared statement. This unique
session command id is returned to the client because internal id given
by server might be same around different servers and this way it is
possible to keep track of them and route them to the right servers when
executed.
This commit is contained in:
Marko
2018-07-29 14:48:30 +03:00
parent adbc3a6749
commit 11d57a264c
4 changed files with 160 additions and 10 deletions

View File

@ -25,6 +25,8 @@ using namespace maxscale;
/** This contains the database to server mapping */
typedef std::unordered_map<std::string, SERVER*> ServerMap;
typedef std::unordered_map<uint64_t, SERVER*> BinaryPSMap;
typedef std::unordered_map<uint32_t, uint32_t> PSHandleMap;
class Shard
{
@ -52,10 +54,14 @@ public:
SERVER* get_location(std::string db);
void add_statement(std::string stmt, SERVER* target);
void add_statement(uint32_t id, SERVER* target);
void add_ps_handle(uint32_t id, uint32_t handle);
uint32_t get_ps_handle(uint32_t id);
bool remove_ps_handle(uint32_t id);
SERVER* get_statement(std::string stmt);
SERVER* get_statement(uint32_t id);
bool remove_statement(std::string stmt);
bool remove_statement(uint32_t id);
/**
* @brief Change the location of a database
@ -100,6 +106,8 @@ public:
private:
ServerMap m_map;
ServerMap stmt_map;
BinaryPSMap m_binary_map;
PSHandleMap m_ps_handles;
time_t m_last_updated;
};