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:
@ -111,7 +111,8 @@ private:
|
||||
time_t m_last_updated;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<std::string, Shard> ShardMap;
|
||||
typedef std::unordered_map<std::string, Shard> ShardMap;
|
||||
typedef std::unordered_map<std::string, int64_t> MapLimits;
|
||||
|
||||
class ShardManager
|
||||
{
|
||||
@ -141,7 +142,38 @@ public:
|
||||
*/
|
||||
void update_shard(Shard& shard, std::string user);
|
||||
|
||||
/**
|
||||
* Set how many concurrent shard updates are allowed per user
|
||||
*
|
||||
* By default only one update per user is allowed.
|
||||
*
|
||||
* @param limit Number of concurrent users to allow
|
||||
*/
|
||||
void set_update_limit(int64_t limit);
|
||||
|
||||
/**
|
||||
* Start a shard update
|
||||
*
|
||||
* The update is considered finished when either update_shard() or cancel_update() is called. One of these
|
||||
* two must be called by the session once start_update() has returned true.
|
||||
*
|
||||
* @param user The user whose shard is about to be updated
|
||||
*
|
||||
* @return True if an update can be done. False if there are too many concurrent
|
||||
* updates being done by this user.
|
||||
*/
|
||||
bool start_update(const std::string& user);
|
||||
|
||||
/**
|
||||
* Cancels a started shard update
|
||||
*
|
||||
* @param user The user whose shard was being updated
|
||||
*/
|
||||
void cancel_update(const std::string& user);
|
||||
|
||||
private:
|
||||
mutable std::mutex m_lock;
|
||||
ShardMap m_maps;
|
||||
MapLimits m_limits;
|
||||
int64_t m_update_limit {1};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user