Reindent server/core/server.c

This commit is contained in:
Johan Wikman
2015-11-30 18:42:07 +02:00
parent 02da87f737
commit ed06d4f14c
2 changed files with 747 additions and 658 deletions

File diff suppressed because it is too large Load Diff

View File

@ -28,23 +28,23 @@
* @verbatim * @verbatim
* Revision History * Revision History
* *
* Date Who Description * Date Who Description
* 14/06/13 Mark Riddoch Initial implementation * 14/06/13 Mark Riddoch Initial implementation
* 21/06/13 Mark Riddoch Addition of server status flags * 21/06/13 Mark Riddoch Addition of server status flags
* 22/07/13 Mark Riddoch Addition of JOINED status for Galera * 22/07/13 Mark Riddoch Addition of JOINED status for Galera
* 18/05/14 Mark Riddoch Addition of unique_name field * 18/05/14 Mark Riddoch Addition of unique_name field
* 20/05/14 Massimiliano Pinto Addition of server_string field * 20/05/14 Massimiliano Pinto Addition of server_string field
* 20/05/14 Massimiliano Pinto Addition of node_id field * 20/05/14 Massimiliano Pinto Addition of node_id field
* 23/05/14 Massimiliano Pinto Addition of rlag and node_ts fields * 23/05/14 Massimiliano Pinto Addition of rlag and node_ts fields
* 03/06/14 Mark Riddoch Addition of maintainance mode * 03/06/14 Mark Riddoch Addition of maintainance mode
* 20/06/14 Massimiliano Pinto Addition of master_id, depth, slaves fields * 20/06/14 Massimiliano Pinto Addition of master_id, depth, slaves fields
* 26/06/14 Mark Riddoch Adidtion of server parameters * 26/06/14 Mark Riddoch Adidtion of server parameters
* 30/07/14 Massimiliano Pinto Addition of NDB status for MySQL Cluster * 30/07/14 Massimiliano Pinto Addition of NDB status for MySQL Cluster
* 30/08/14 Massimiliano Pinto Addition of SERVER_STALE_STATUS * 30/08/14 Massimiliano Pinto Addition of SERVER_STALE_STATUS
* 27/10/14 Massimiliano Pinto Addition of SERVER_MASTER_STICKINESS * 27/10/14 Massimiliano Pinto Addition of SERVER_MASTER_STICKINESS
* 19/02/15 Mark Riddoch Addition of serverGetList * 19/02/15 Mark Riddoch Addition of serverGetList
* 01/06/15 Massimiliano Pinto Addition of server_update_address/port * 01/06/15 Massimiliano Pinto Addition of server_update_address/port
* 19/06/15 Martin Brampton Extra fields for persistent connections, CHK_SERVER * 19/06/15 Martin Brampton Extra fields for persistent connections, CHK_SERVER
* *
* @endverbatim * @endverbatim
*/ */
@ -55,22 +55,23 @@
* The server parameters used for weighting routing decissions * The server parameters used for weighting routing decissions
* *
*/ */
typedef struct server_params { typedef struct server_params
char *name; /**< Parameter name */ {
char *value; /**< Parameter value */ char *name; /**< Parameter name */
struct server_params char *value; /**< Parameter value */
*next; /**< Next Paramter in the linked list */ struct server_params *next; /**< Next Paramter in the linked list */
} SERVER_PARAM; } SERVER_PARAM;
/** /**
* The server statistics structure * The server statistics structure
* *
*/ */
typedef struct { typedef struct
int n_connections; /**< Number of connections */ {
int n_current; /**< Current connections */ int n_connections; /**< Number of connections */
int n_current_ops; /**< Current active operations */ int n_current; /**< Current connections */
int n_persistent; /**< Current persistent pool */ int n_current_ops; /**< Current active operations */
int n_persistent; /**< Current persistent pool */
} SERVER_STATS; } SERVER_STATS;
/** /**
@ -81,35 +82,35 @@ typedef struct {
*/ */
typedef struct server { typedef struct server {
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
skygw_chk_t server_chk_top; skygw_chk_t server_chk_top;
#endif #endif
SPINLOCK lock; /**< Common access lock */ SPINLOCK lock; /**< Common access lock */
char *unique_name; /**< Unique name for the server */ char *unique_name; /**< Unique name for the server */
char *name; /**< Server name/IP address*/ char *name; /**< Server name/IP address*/
unsigned short port; /**< Port to listen on */ unsigned short port; /**< Port to listen on */
char *protocol; /**< Protocol module to use */ char *protocol; /**< Protocol module to use */
unsigned int status; /**< Status flag bitmap for the server */ unsigned int status; /**< Status flag bitmap for the server */
char *monuser; /**< User name to use to monitor the db */ char *monuser; /**< User name to use to monitor the db */
char *monpw; /**< Password to use to monitor the db */ char *monpw; /**< Password to use to monitor the db */
SERVER_STATS stats; /**< The server statistics */ SERVER_STATS stats; /**< The server statistics */
struct server *next; /**< Next server */ struct server *next; /**< Next server */
struct server *nextdb; /**< Next server in list attached to a service */ struct server *nextdb; /**< Next server in list attached to a service */
char *server_string; /**< Server version string, i.e. MySQL server version */ char *server_string; /**< Server version string, i.e. MySQL server version */
long node_id; /**< Node id, server_id for M/S or local_index for Galera */ long node_id; /**< Node id, server_id for M/S or local_index for Galera */
int rlag; /**< Replication Lag for Master / Slave replication */ int rlag; /**< Replication Lag for Master / Slave replication */
unsigned long node_ts; /**< Last timestamp set from M/S monitor module */ unsigned long node_ts; /**< Last timestamp set from M/S monitor module */
SERVER_PARAM *parameters; /**< Parameters of a server that may be used to weight routing decisions */ SERVER_PARAM *parameters; /**< Parameters of a server that may be used to weight routing decisions */
long master_id; /**< Master server id of this node */ long master_id; /**< Master server id of this node */
int depth; /**< Replication level in the tree */ int depth; /**< Replication level in the tree */
long *slaves; /**< Slaves of this node */ long *slaves; /**< Slaves of this node */
bool master_err_is_logged; /*< If node failed, this indicates whether it is logged */ bool master_err_is_logged; /*< If node failed, this indicates whether it is logged */
DCB *persistent; /**< List of unused persistent connections to the server */ DCB *persistent; /**< List of unused persistent connections to the server */
SPINLOCK persistlock; /**< Lock for adjusting the persistent connections list */ SPINLOCK persistlock; /**< Lock for adjusting the persistent connections list */
long persistpoolmax; /**< Maximum size of persistent connections pool */ long persistpoolmax; /**< Maximum size of persistent connections pool */
long persistmaxtime; /**< Maximum number of seconds connection can live */ long persistmaxtime; /**< Maximum number of seconds connection can live */
int persistmax; /**< Maximum pool size actually achieved since startup */ int persistmax; /**< Maximum pool size actually achieved since startup */
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
skygw_chk_t server_chk_tail; skygw_chk_t server_chk_tail;
#endif #endif
} SERVER; } SERVER;
@ -118,101 +119,105 @@ typedef struct server {
* *
* These are a bitmap of attributes that may be applied to a server * These are a bitmap of attributes that may be applied to a server
*/ */
#define SERVER_RUNNING 0x0001 /**<< The server is up and running */ #define SERVER_RUNNING 0x0001 /**<< The server is up and running */
#define SERVER_MASTER 0x0002 /**<< The server is a master, i.e. can handle writes */ #define SERVER_MASTER 0x0002 /**<< The server is a master, i.e. can handle writes */
#define SERVER_SLAVE 0x0004 /**<< The server is a slave, i.e. can handle reads */ #define SERVER_SLAVE 0x0004 /**<< The server is a slave, i.e. can handle reads */
#define SERVER_JOINED 0x0008 /**<< The server is joined in a Galera cluster */ #define SERVER_JOINED 0x0008 /**<< The server is joined in a Galera cluster */
#define SERVER_NDB 0x0010 /**<< The server is part of a MySQL cluster setup */ #define SERVER_NDB 0x0010 /**<< The server is part of a MySQL cluster setup */
#define SERVER_MAINT 0x0020 /**<< Server is in maintenance mode */ #define SERVER_MAINT 0x0020 /**<< Server is in maintenance mode */
#define SERVER_SLAVE_OF_EXTERNAL_MASTER 0x0040 /**<< Server is slave of a Master outside the provided replication topology */ #define SERVER_SLAVE_OF_EXTERNAL_MASTER 0x0040 /**<< Server is slave of a Master outside
#define SERVER_STALE_STATUS 0x0080 /**<< Server stale status, monitor didn't update it */ the provided replication topology */
#define SERVER_MASTER_STICKINESS 0x0100 /**<< Server Master stickiness */ #define SERVER_STALE_STATUS 0x0080 /**<< Server stale status, monitor didn't update it */
#define SERVER_AUTH_ERROR 0x1000 /**<< Authentication erorr from monitor */ #define SERVER_MASTER_STICKINESS 0x0100 /**<< Server Master stickiness */
#define SERVER_AUTH_ERROR 0x1000 /**<< Authentication erorr from monitor */
/** /**
* Is the server running - the macro returns true if the server is marked as running * Is the server running - the macro returns true if the server is marked as running
* regardless of it's state as a master or slave * regardless of it's state as a master or slave
*/ */
#define SERVER_IS_RUNNING(server) (((server)->status & (SERVER_RUNNING|SERVER_MAINT)) == SERVER_RUNNING) #define SERVER_IS_RUNNING(server) (((server)->status & (SERVER_RUNNING|SERVER_MAINT)) == SERVER_RUNNING)
/** /**
* Is the server marked as down - the macro returns true if the server is believed * Is the server marked as down - the macro returns true if the server is believed
* to be inoperable. * to be inoperable.
*/ */
#define SERVER_IS_DOWN(server) (((server)->status & SERVER_RUNNING) == 0) #define SERVER_IS_DOWN(server) (((server)->status & SERVER_RUNNING) == 0)
/** /**
* Is the server a master? The server must be both running and marked as master * Is the server a master? The server must be both running and marked as master
* in order for the macro to return true * in order for the macro to return true
*/ */
#define SERVER_IS_MASTER(server) SRV_MASTER_STATUS((server)->status) #define SERVER_IS_MASTER(server) SRV_MASTER_STATUS((server)->status)
#define SRV_MASTER_STATUS(status) ((status & \ #define SRV_MASTER_STATUS(status) ((status & \
(SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == \ (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == \
(SERVER_RUNNING|SERVER_MASTER)) (SERVER_RUNNING|SERVER_MASTER))
/** /**
* Is the server valid candidate for root master. The server must be running, * Is the server valid candidate for root master. The server must be running,
* marked as master and not have maintenance bit set. * marked as master and not have maintenance bit set.
*/ */
#define SERVER_IS_ROOT_MASTER(server) \ #define SERVER_IS_ROOT_MASTER(server) \
(((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_MASTER)) (((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_MASTER))
/** /**
* Is the server a slave? The server must be both running and marked as a slave * Is the server a slave? The server must be both running and marked as a slave
* in order for the macro to return true * in order for the macro to return true
*/ */
#define SERVER_IS_SLAVE(server) \ #define SERVER_IS_SLAVE(server) \
(((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_SLAVE)) (((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == \
(SERVER_RUNNING|SERVER_SLAVE))
/** /**
* Is the server joined Galera node? The server must be running and joined. * Is the server joined Galera node? The server must be running and joined.
*/ */
#define SERVER_IS_JOINED(server) \ #define SERVER_IS_JOINED(server) \
(((server)->status & (SERVER_RUNNING|SERVER_JOINED|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_JOINED)) (((server)->status & (SERVER_RUNNING|SERVER_JOINED|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_JOINED))
/** /**
* Is the server a SQL node in MySQL Cluster? The server must be running and with NDB status * Is the server a SQL node in MySQL Cluster? The server must be running and with NDB status
*/ */
#define SERVER_IS_NDB(server) \ #define SERVER_IS_NDB(server) \
(((server)->status & (SERVER_RUNNING|SERVER_NDB|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_NDB)) (((server)->status & (SERVER_RUNNING|SERVER_NDB|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_NDB))
/** /**
* Is the server in maintenance mode. * Is the server in maintenance mode.
*/ */
#define SERVER_IN_MAINT(server) ((server)->status & SERVER_MAINT) #define SERVER_IN_MAINT(server) ((server)->status & SERVER_MAINT)
/** server is not master, slave or joined */ /** server is not master, slave or joined */
#define SERVER_NOT_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED|SERVER_NDB)) == 0) #define SERVER_NOT_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED|SERVER_NDB)) == 0)
#define SERVER_IS_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED|SERVER_NDB)) != 0) #define SERVER_IS_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED|SERVER_NDB)) != 0)
#define SERVER_IS_RELAY_SERVER(server) \ #define SERVER_IS_RELAY_SERVER(server) \
(((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE)) (((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == \
(SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE))
extern SERVER *server_alloc(char *, char *, unsigned short); extern SERVER *server_alloc(char *, char *, unsigned short);
extern int server_free(SERVER *); extern int server_free(SERVER *);
extern SERVER *server_find_by_unique_name(char *); extern SERVER *server_find_by_unique_name(char *);
extern SERVER *server_find(char *, unsigned short); extern SERVER *server_find(char *, unsigned short);
extern void printServer(SERVER *); extern void printServer(SERVER *);
extern void printAllServers(); extern void printAllServers();
extern void dprintAllServers(DCB *); extern void dprintAllServers(DCB *);
extern void dprintAllServersJson(DCB *); extern void dprintAllServersJson(DCB *);
extern void dprintServer(DCB *, SERVER *); extern void dprintServer(DCB *, SERVER *);
extern void dprintPersistentDCBs(DCB *, SERVER *); extern void dprintPersistentDCBs(DCB *, SERVER *);
extern void dListServers(DCB *); extern void dListServers(DCB *);
extern char *server_status(SERVER *); extern char *server_status(SERVER *);
extern void server_clear_set_status(SERVER *server, int specified_bits, int bits_to_set); extern void server_clear_set_status(SERVER *server, int specified_bits, int bits_to_set);
extern void server_set_status(SERVER *, int); extern void server_set_status(SERVER *, int);
extern void server_clear_status(SERVER *, int); extern void server_clear_status(SERVER *, int);
extern void server_transfer_status(SERVER *dest_server, SERVER *source_server); extern void server_transfer_status(SERVER *dest_server, SERVER *source_server);
extern void serverAddMonUser(SERVER *, char *, char *); extern void serverAddMonUser(SERVER *, char *, char *);
extern void serverAddParameter(SERVER *, char *, char *); extern void serverAddParameter(SERVER *, char *, char *);
extern char *serverGetParameter(SERVER *, char *); extern char *serverGetParameter(SERVER *, char *);
extern void server_update(SERVER *, char *, char *, char *); extern void server_update(SERVER *, char *, char *, char *);
extern void server_set_unique_name(SERVER *, char *); extern void server_set_unique_name(SERVER *, char *);
extern DCB *server_get_persistent(SERVER *, char *, const char *); extern DCB *server_get_persistent(SERVER *, char *, const char *);
extern void server_update_address(SERVER *, char *); extern void server_update_address(SERVER *, char *);
extern void server_update_port(SERVER *, unsigned short); extern void server_update_port(SERVER *, unsigned short);
extern RESULTSET *serverGetList(); extern RESULTSET *serverGetList();
extern unsigned int server_map_status(char *str); extern unsigned int server_map_status(char *str);
extern bool server_set_version_string(SERVER* server, const char* string); extern bool server_set_version_string(SERVER* server, const char* string);
#endif #endif