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

@ -36,6 +36,33 @@ void Shard::add_statement(std::string stmt, SERVER* target)
stmt_map[stmt] = target;
}
void Shard::add_statement(uint32_t id, SERVER* target)
{
MXS_DEBUG("ADDING ID: [%u] server: [%s]", id, target->name);
m_binary_map[id] = target;
}
void Shard::add_ps_handle(uint32_t id, uint32_t handle)
{
MXS_DEBUG("ID: [%u] HANDLE: [%u]", id, handle);
m_ps_handles[id] = handle;
}
bool Shard::remove_ps_handle(uint32_t id)
{
return m_ps_handles.erase(id);
}
uint32_t Shard::get_ps_handle(uint32_t id)
{
PSHandleMap::iterator it = m_ps_handles.find(id);
if (it != m_ps_handles.end())
{
return it->second;
}
return 0;
}
void Shard::replace_location(std::string db, SERVER* target)
{
m_map[db] = target;
@ -94,11 +121,27 @@ SERVER* Shard::get_statement(std::string stmt)
return rval;
}
SERVER* Shard::get_statement(uint32_t id)
{
SERVER* rval = NULL;
BinaryPSMap::iterator iter = m_binary_map.find(id);
if(iter != m_binary_map.end())
{
rval = iter->second;
}
return rval;
}
bool Shard::remove_statement(std::string stmt)
{
return stmt_map.erase(stmt);
}
bool Shard::remove_statement(uint32_t id)
{
return m_binary_map.erase(id);
}
bool Shard::stale(double max_interval) const
{
time_t now = time(NULL);
@ -164,4 +207,4 @@ void ShardManager::update_shard(Shard& shard, std::string user)
{
m_maps[user] = shard;
}
}
}