MXS-3892: Limit concurrent mapping of databases
As there are no practical benefits to multiple sessions for the same user mapping the databases at the same time, limiting them to one update per user is sensible. This is especially true now that we know the information_schema tables aren't the most efficient things in the world. The current code implements this rate limiting by closing any extra sessions that would start a second update. The final implementation should suspend them for the duration of the update as it is far more user-friendly. The limits are currently global as the shard caches are also global. This is a performance bottleneck and it could be solved by storing the shard cache inside of a mxs::WorkerGlobal instead of having it as a global cache.
This commit is contained in:
@ -209,4 +209,34 @@ void ShardManager::update_shard(Shard& shard, std::string user)
|
||||
{
|
||||
m_maps[user] = shard;
|
||||
}
|
||||
|
||||
mxb_assert(m_limits[user] > 0);
|
||||
--m_limits[user];
|
||||
}
|
||||
|
||||
void ShardManager::set_update_limit(int64_t limit)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
m_update_limit = limit;
|
||||
}
|
||||
|
||||
bool ShardManager::start_update(const std::string& user)
|
||||
{
|
||||
bool rval = false;
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
|
||||
if (m_limits[user] < m_update_limit)
|
||||
{
|
||||
++m_limits[user];
|
||||
rval = true;
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
void ShardManager::cancel_update(const std::string& user)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
mxb_assert(m_limits[user] > 0);
|
||||
--m_limits[user];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user