Use unordered_map in schemarouter
The shard map doesn't have to be in order and an unordered map will do just fine.
This commit is contained in:
@ -32,7 +32,6 @@
|
|||||||
#include <maxscale/spinlock.h>
|
#include <maxscale/spinlock.h>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::map;
|
|
||||||
|
|
||||||
namespace schemarouter
|
namespace schemarouter
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ namespace schemarouter
|
|||||||
bool connect_backend_servers(SSRBackendList& backends, MXS_SESSION* session);
|
bool connect_backend_servers(SSRBackendList& backends, MXS_SESSION* session);
|
||||||
|
|
||||||
enum route_target get_shard_route_target(uint32_t qtype);
|
enum route_target get_shard_route_target(uint32_t qtype);
|
||||||
bool change_current_db(string& dest, Shard& shard, GWBUF* buf);
|
bool change_current_db(std::string& dest, Shard& shard, GWBUF* buf);
|
||||||
bool extract_database(GWBUF* buf, char* str);
|
bool extract_database(GWBUF* buf, char* str);
|
||||||
bool detect_show_shards(GWBUF* query);
|
bool detect_show_shards(GWBUF* query);
|
||||||
void write_error_to_client(DCB* dcb, int errnum, const char* mysqlstate, const char* errmsg);
|
void write_error_to_client(DCB* dcb, int errnum, const char* mysqlstate, const char* errmsg);
|
||||||
@ -1114,7 +1114,7 @@ void create_error_reply(char* fail_str, DCB* dcb)
|
|||||||
* @return true if new database is set, false if non-existent database was tried
|
* @return true if new database is set, false if non-existent database was tried
|
||||||
* to be set
|
* to be set
|
||||||
*/
|
*/
|
||||||
bool change_current_db(string& dest, Shard& shard, GWBUF* buf)
|
bool change_current_db(std::string& dest, Shard& shard, GWBUF* buf)
|
||||||
{
|
{
|
||||||
bool succp = false;
|
bool succp = false;
|
||||||
char db[MYSQL_DATABASE_MAXLEN + 1];
|
char db[MYSQL_DATABASE_MAXLEN + 1];
|
||||||
|
@ -24,12 +24,12 @@ Shard::~Shard()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Shard::add_location(string db, SERVER* target)
|
bool Shard::add_location(std::string db, SERVER* target)
|
||||||
{
|
{
|
||||||
return m_map.insert(make_pair(db, target)).second;
|
return m_map.insert(std::make_pair(db, target)).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
SERVER* Shard::get_location(string db)
|
SERVER* Shard::get_location(std::string db)
|
||||||
{
|
{
|
||||||
SERVER* rval = NULL;
|
SERVER* rval = NULL;
|
||||||
ServerMap::iterator iter = m_map.find(db);
|
ServerMap::iterator iter = m_map.find(db);
|
||||||
@ -76,9 +76,9 @@ ShardManager::~ShardManager()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Shard ShardManager::get_shard(string user, double max_interval)
|
Shard ShardManager::get_shard(std::string user, double max_interval)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
mxs::SpinLockGuard guard(m_lock);
|
||||||
|
|
||||||
ShardMap::iterator iter = m_maps.find(user);
|
ShardMap::iterator iter = m_maps.find(user);
|
||||||
|
|
||||||
@ -98,9 +98,9 @@ Shard ShardManager::get_shard(string user, double max_interval)
|
|||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShardManager::update_shard(Shard& shard, string user)
|
void ShardManager::update_shard(Shard& shard, std::string user)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
mxs::SpinLockGuard guard(m_lock);
|
||||||
ShardMap::iterator iter = m_maps.find(user);
|
ShardMap::iterator iter = m_maps.find(user);
|
||||||
|
|
||||||
if (iter == m_maps.end() || shard.newer_than(iter->second))
|
if (iter == m_maps.end() || shard.newer_than(iter->second))
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include <maxscale/cppdefs.hh>
|
#include <maxscale/cppdefs.hh>
|
||||||
|
|
||||||
#include <map>
|
#include <tr1/unordered_map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@ -23,11 +23,9 @@
|
|||||||
#include <maxscale/spinlock.hh>
|
#include <maxscale/spinlock.hh>
|
||||||
|
|
||||||
using namespace maxscale;
|
using namespace maxscale;
|
||||||
using std::map;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
/** This contains the database to server mapping */
|
/** This contains the database to server mapping */
|
||||||
typedef map<string, SERVER*> ServerMap;
|
typedef std::tr1::unordered_map<std::string, SERVER*> ServerMap;
|
||||||
|
|
||||||
class Shard
|
class Shard
|
||||||
{
|
{
|
||||||
@ -43,7 +41,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return True if location was added
|
* @return True if location was added
|
||||||
*/
|
*/
|
||||||
bool add_location(string db, SERVER* target);
|
bool add_location(std::string db, SERVER* target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve the location of a database
|
* @brief Retrieve the location of a database
|
||||||
@ -52,7 +50,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return The database or NULL if no server contains the database
|
* @return The database or NULL if no server contains the database
|
||||||
*/
|
*/
|
||||||
SERVER* get_location(string db);
|
SERVER* get_location(std::string db);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if shard contains stale information
|
* @brief Check if shard contains stale information
|
||||||
@ -91,7 +89,7 @@ private:
|
|||||||
time_t m_last_updated;
|
time_t m_last_updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef map<string, Shard> ShardMap;
|
typedef std::tr1::unordered_map<std::string, Shard> ShardMap;
|
||||||
|
|
||||||
class ShardManager
|
class ShardManager
|
||||||
{
|
{
|
||||||
@ -108,7 +106,7 @@ public:
|
|||||||
* @return The latest version of the shard or a newly created shard if no
|
* @return The latest version of the shard or a newly created shard if no
|
||||||
* old version is available
|
* old version is available
|
||||||
*/
|
*/
|
||||||
Shard get_shard(string user, double max_lifetime);
|
Shard get_shard(std::string user, double max_lifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Update the shard information
|
* @brief Update the shard information
|
||||||
@ -119,7 +117,7 @@ public:
|
|||||||
* @param shard New version of the shard
|
* @param shard New version of the shard
|
||||||
* @param user The user whose shard this is
|
* @param user The user whose shard this is
|
||||||
*/
|
*/
|
||||||
void update_shard(Shard& shard, string user);
|
void update_shard(Shard& shard, std::string user);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SPINLOCK m_lock;
|
SPINLOCK m_lock;
|
||||||
|
Reference in New Issue
Block a user