Added dbshard technical documentation.

This commit is contained in:
Markus Makela 2015-02-03 11:26:53 +02:00
parent b09fe1cc44
commit 7b8579163a
4 changed files with 27 additions and 19 deletions

View File

@ -0,0 +1,23 @@
#DBShard Router - Technical Overview
This document is designed with a developer's point-of-view in mind. It explains the lifecycle of the module and details about its internal workings. It refers to the source code which can be found at [GitHub](https://github.com/mariadb-corporation/MaxScale).
## Source Files and Data Structures
The dbshard router consists of the dbshard.h header file located in the `server/modules/include/` directory and the dbshard.c file located in the `server/modules/routing/dbshard` directory. This router implements the router interface defined in the router.h file. The entry points and structures this router uses can be found in the header file. The two main structures in use are the router instace and router session structures. The router instance structure is defined in `struct router_instance` and the router session structure in `struct router_client_session`.
The definitions of the external functions and all the internal functions of the router can be found in the dbshard.c file.
## Router Lifecycle
When MaxScale first starts, it creates all services and thus creates the router instances of all the routers. The functions involved in this stage are ModuleInit, which is called only once when MaxScale first starts, and createInstance, called for each individual instace of this router in all the configured services. These functions read configuraion values and initialize internal data.
When a user connects to MaxScale, a new session is created and the newSession function is called. At this point the client session connects to all the backend servers and initializes the list of databases.
After the session is created queries are routed to the router's routeQuery function. This is where most of the work regarding the resolution of query destinations is done. The main internal functions involved in routing the query are get_shard_route_target (detects if a query needs to be sent to all the servers or to a specific one), get_shard_target_name (parses the query and finds the name of the right server) and route_session_write (handles sending and and storing session commands). After this point the client's query has been sent to the backend server and the router waits for either an response or an error signaling that the backend server is not responding.
If a response is received the clientReply function is called and response is simply sent to the client and the router is then ready for more queries. If there is no response from the server and the connection to it is lost the handleError function is called. This function tries to find replacement servers for the failed ones and regenerates the list of databases. This also triggeres the sending of an error packet to the client that notifies that the server is not responding.
After the session ends the closeSession is called where the session is set to a closed state after which the freeSession is called where the final freeing of memory is done. After this point the router's session has gone through all the stages of its lifecycle.
![DBShard Router Lifecycle](dbshard-lifecycle.png)

View File

@ -26,3 +26,7 @@ SELECT queries that modify session variables are not currently supported because
## Examples
To be implemeted.
## Technical Documentation
[Technical Overview and Lifecycle Walkthrough](DBShard-technical.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -224,25 +224,6 @@ typedef struct dbshard_config_st {
} rwsplit_config_t;
#if defined(PREP_STMT_CACHING)
typedef struct prep_stmt_st {
#if defined(SS_DEBUG)
skygw_chk_t pstmt_chk_top;
#endif
union id {
int seq;
char* name;
} pstmt_id;
prep_stmt_state_t pstmt_state;
prep_stmt_type_t pstmt_type;
#if defined(SS_DEBUG)
skygw_chk_t pstmt_chk_tail;
#endif
} prep_stmt_t;
#endif /*< PREP_STMT_CACHING */
/**
* The client session structure used within this router.
*/