Added caching of the hashtables used to map databases to servers.
This commit is contained in:
Markus Makela
2015-10-28 15:23:43 +02:00
parent 6d1c069d41
commit 18c53bebf1
2 changed files with 382 additions and 129 deletions

View File

@ -56,6 +56,26 @@ typedef enum showdb_response
SHOWDB_DUPLICATE_DATABASES,
SHOWDB_FATAL_ERROR
} showdb_response_t;
enum shard_map_state
{
SHMAP_UNINIT, /*< No databases have been added to this shard map */
SHMAP_READY, /*< All available databases have been added */
SHMAP_STALE /*< The shard map has old data or has not been updated recently */
};
/**
* A map of the shards tied to a single user.
*/
typedef struct shard_map
{
HASHTABLE *hash; /*< A hashtable of database names and the servers which
* have these databases. */
SPINLOCK lock;
time_t last_updated;
enum shard_map_state state; /*< State of the shard map */
}shard_map_t;
/**
* The state of the backend server reference
*/
@ -274,6 +294,8 @@ typedef struct {
double ses_longest; /*< Longest session */
double ses_shortest; /*< Shortest session */
double ses_average; /*< Average session length */
int shmap_cache_hit; /*< Shard map was found from the cache */
int shmap_cache_miss;/*< No shard map found from the cache */
} ROUTER_STATS;
/**
@ -299,7 +321,7 @@ struct router_client_session {
bool rses_transaction_active; /*< Is a transaction active */
struct router_instance *router; /*< The router instance */
struct router_client_session* next; /*< List of router sessions */
HASHTABLE* dbhash; /*< Database hash containing names of the databases mapped to the servers that contain them */
shard_map_t* shardmap; /*< Database hash containing names of the databases mapped to the servers that contain them */
char connect_db[MYSQL_DATABASE_MAXLEN+1]; /*< Database the user was trying to connect to */
init_mask_t init; /*< Initialization state bitmask */
GWBUF* queue; /*< Query that was received before the session was ready */
@ -318,6 +340,7 @@ struct router_client_session {
* The per instance data for the router.
*/
typedef struct router_instance {
HASHTABLE* shard_maps; /*< Shard maps hashed by user name */
SERVICE* service; /*< Pointer to service */
ROUTER_CLIENT_SES* connections; /*< List of client connections */
SPINLOCK lock; /*< Lock for the instance data */