From f2fcf79fb2bd2cedd80593845d182b661c855c4c Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Tue, 4 Dec 2018 16:53:37 +0200 Subject: [PATCH] Cleanup server.hh Simplify type definitions. --- include/maxscale/authenticator.h | 2 +- include/maxscale/buffer.h | 4 +-- include/maxscale/config.hh | 4 +-- include/maxscale/dcb.hh | 8 ++--- include/maxscale/protocol.h | 6 ++-- include/maxscale/server.hh | 44 ++++++++++-------------- include/maxscale/service.hh | 2 +- include/maxscale/session.hh | 4 +-- server/core/dcb.cc | 4 +-- server/modules/routing/hintrouter/dcb.hh | 2 +- 10 files changed, 37 insertions(+), 43 deletions(-) diff --git a/include/maxscale/authenticator.h b/include/maxscale/authenticator.h index 30d94d189..0c93fe2b1 100644 --- a/include/maxscale/authenticator.h +++ b/include/maxscale/authenticator.h @@ -44,7 +44,7 @@ typedef enum authenticator_capability #define AUTHENTICATOR_MAX_OPTIONS 256 struct DCB; -struct server; +struct SERVER; struct MXS_SESSION; /** diff --git a/include/maxscale/buffer.h b/include/maxscale/buffer.h index 3dafdb0b9..78616be4d 100644 --- a/include/maxscale/buffer.h +++ b/include/maxscale/buffer.h @@ -33,7 +33,7 @@ MXS_BEGIN_DECLS -struct server; +struct SERVER; /** * Buffer properties - used to store properties related to the buffer @@ -126,7 +126,7 @@ typedef struct gwbuf SHARED_BUF* sbuf; /*< The shared buffer with the real data */ HINT* hint; /*< Hint data for this buffer */ BUF_PROPERTY* properties; /*< Buffer properties */ - struct server* server; /*< The target server where the buffer is executed */ + struct SERVER* server; /*< The target server where the buffer is executed */ uint32_t gwbuf_type; /*< buffer's data type information */ #ifdef SS_DEBUG int owner; /*< Owner of the thread, only for debugging */ diff --git a/include/maxscale/config.hh b/include/maxscale/config.hh index 1cda41d53..1c78cfb4f 100644 --- a/include/maxscale/config.hh +++ b/include/maxscale/config.hh @@ -422,7 +422,7 @@ SERVICE* config_get_service(const MXS_CONFIG_PARAMETER* params, const char* key) * * @return Pointer to configured server */ -struct server* config_get_server(const MXS_CONFIG_PARAMETER* params, const char* key); +struct SERVER* config_get_server(const MXS_CONFIG_PARAMETER* params, const char* key); /** * @brief Get an array of servers. The caller should free the produced array, @@ -435,7 +435,7 @@ struct server* config_get_server(const MXS_CONFIG_PARAMETER* params, const char* */ int config_get_server_list(const MXS_CONFIG_PARAMETER* params, const char* key, - struct server*** output); + struct SERVER*** output); /** * Get a compiled regular expression and the ovector size of the pattern. The diff --git a/include/maxscale/dcb.hh b/include/maxscale/dcb.hh index 31de1408f..6664f6fc1 100644 --- a/include/maxscale/dcb.hh +++ b/include/maxscale/dcb.hh @@ -35,7 +35,7 @@ MXS_BEGIN_DECLS #define ERRHANDLE struct MXS_SESSION; -struct server; +struct SERVER; struct DCB; @@ -193,7 +193,7 @@ struct DCB : public MXB_POLL_DATA void* authenticator_data = nullptr;/**< The authenticator data for this DCB */ DCB_CALLBACK* callbacks = nullptr; /**< The list of callbacks for the DCB */ int64_t last_read = 0; /**< Last time the DCB received data */ - struct server* server = nullptr; /**< The associated backend server */ + struct SERVER* server = nullptr; /**< The associated backend server */ SSL* ssl = nullptr; /**< SSL struct for connection */ bool ssl_read_want_read = false; bool ssl_read_want_write = false; @@ -241,7 +241,7 @@ void dcb_global_init(); int dcb_write(DCB*, GWBUF*); DCB* dcb_alloc(DCB::Role, MXS_SESSION*); -DCB* dcb_connect(struct server*, MXS_SESSION*, const char*); +DCB* dcb_connect(struct SERVER*, MXS_SESSION*, const char*); int dcb_read(DCB*, GWBUF**, int); int dcb_drain_writeq(DCB*); void dcb_close(DCB*); @@ -275,7 +275,7 @@ int dcb_add_callback(DCB*, DCB_REASON, int (*)(DCB*, DCB_REASON, void*), void*); int dcb_remove_callback(DCB*, DCB_REASON, int (*)(DCB*, DCB_REASON, void*), void*); int dcb_count_by_usage(DCB_USAGE); /* Return counts of DCBs */ int dcb_persistent_clean_count(DCB*, int, bool); /* Clean persistent and return count */ -void dcb_hangup_foreach(struct server* server); +void dcb_hangup_foreach(struct SERVER* server); uint64_t dcb_get_session_id(DCB* dcb); char* dcb_role_name(DCB*); /* Return the name of a role */ int dcb_accept_SSL(DCB* dcb); diff --git a/include/maxscale/protocol.h b/include/maxscale/protocol.h index e91115b5f..82e1a26a8 100644 --- a/include/maxscale/protocol.h +++ b/include/maxscale/protocol.h @@ -26,7 +26,7 @@ MXS_BEGIN_DECLS struct DCB; -struct server; +struct SERVER; struct MXS_SESSION; /** @@ -106,7 +106,7 @@ typedef struct mxs_protocol * * @return The opened file descriptor or DCBFD_CLOSED on error */ - int32_t (* connect)(DCB* dcb, struct server* server, MXS_SESSION* session); + int32_t (* connect)(DCB* dcb, struct SERVER* server, MXS_SESSION* session); /** * Free protocol data allocated in the connect handler @@ -131,7 +131,7 @@ typedef struct mxs_protocol * * @note Currently the return value is ignored */ - int32_t (* auth)(DCB* dcb, struct server* server, MXS_SESSION* session, GWBUF* buffer); + int32_t (* auth)(DCB* dcb, struct SERVER* server, MXS_SESSION* session, GWBUF* buffer); /** * Returns the name of the default authenticator module for this protocol diff --git a/include/maxscale/server.hh b/include/maxscale/server.hh index 8ea457ef3..eecba3c28 100644 --- a/include/maxscale/server.hh +++ b/include/maxscale/server.hh @@ -23,7 +23,7 @@ #define MAX_SERVER_MONUSER_LEN 1024 #define MAX_SERVER_MONPW_LEN 1024 #define MAX_SERVER_VERSION_LEN 256 -#define MAX_NUM_SLAVES 128 /**< Maximum number of slaves under a single server*/ +#define MAX_NUM_SLAVES 128 /**< Maximum number of slaves under a single server*/ /** * Server configuration parameters names @@ -46,21 +46,17 @@ const int MAINTENANCE_FLAG_CHECK = -1; // Default replication lag value const int MXS_RLAG_UNDEFINED = -1; -/** - * The server parameters used for weighting routing decisions - */ -typedef struct server_params +/* Custom server parameters. These can be used by modules for e.g. weighting routing decisions. */ +struct SERVER_PARAM { - char* name; /**< Parameter name */ - char* value; /**< Parameter value */ - bool active; /**< Whether the parameter is valid */ - struct server_params* next; /**< Next Paramter in the linked list */ -} SERVER_PARAM; + char* name; /**< Parameter name */ + char* value; /**< Parameter value */ + bool active; /**< Whether the parameter is valid */ + struct SERVER_PARAM* next; /**< Next Paramter in the linked list */ +}; -/** - * The server statistics structure - */ -typedef struct +/* Server connection and usage statistics */ +struct SERVER_STATS { int n_connections; /**< Number of connections */ int n_current; /**< Current connections */ @@ -69,23 +65,21 @@ typedef struct uint64_t n_new_conn; /**< Times the current pool was empty */ uint64_t n_from_pool; /**< Times when a connection was available from the pool */ uint64_t packets; /**< Number of packets routed to this server */ -} SERVER_STATS; +}; -/** - * The server version. - */ -typedef struct server_version +/* Server version */ +struct SERVER_VERSION { uint32_t major; uint32_t minor; uint32_t patch; -} SERVER_VERSION; +}; -typedef enum +enum server_type_t { SERVER_TYPE_MARIADB, SERVER_TYPE_MYSQL -} server_type_t; +}; static inline void server_decode_version(uint64_t version, SERVER_VERSION* server_version) { @@ -109,7 +103,7 @@ static uint64_t server_encode_version(const SERVER_VERSION* server_version) * the name of a protocol module that is loaded to implement the protocol * between the gateway and the server. */ -typedef struct server +struct SERVER { // Base settings char* name; /**< Server config name */ @@ -126,7 +120,7 @@ typedef struct server bool proxy_protocol; /**< Send proxy-protocol header to backends when connecting * routing sessions. */ SERVER_PARAM* parameters; /**< Additional custom parameters which may affect routing - * decisions. */ + * decisions. */ // Base variables bool is_active; /**< Server is active and has not been "destroyed" */ void* auth_instance; /**< Authenticator instance data */ @@ -158,7 +152,7 @@ typedef struct server * by rwsplit. TODO: Move to rwsplit */ bool warn_ssl_not_enabled;/**< SSL not used for an SSL enabled server */ MxsDiskSpaceThreshold* disk_space_threshold;/**< Disk space thresholds */ -} SERVER; +}; /** * Status bits in the SERVER->status member, which describes the general state of a server. Although the diff --git a/include/maxscale/service.hh b/include/maxscale/service.hh index 326fe192b..04921d3c5 100644 --- a/include/maxscale/service.hh +++ b/include/maxscale/service.hh @@ -29,7 +29,7 @@ #include #include -struct server; +struct SERVER; struct mxs_router; struct mxs_router_object; struct users; diff --git a/include/maxscale/session.hh b/include/maxscale/session.hh index 023522f90..9848c9da9 100644 --- a/include/maxscale/session.hh +++ b/include/maxscale/session.hh @@ -29,7 +29,7 @@ struct mxs_filter_def; struct mxs_filter; struct mxs_filter_session; struct mxs_router_session; -struct server; +struct SERVER; class Listener; using SListener = std::shared_ptr; @@ -610,7 +610,7 @@ void session_retain_statement(MXS_SESSION* session, GWBUF* buffer); * @param final_response True if this was the final server to respond, * false otherwise. */ -void session_book_server_response(MXS_SESSION* session, struct server* server, bool final_response); +void session_book_server_response(MXS_SESSION* session, struct SERVER* server, bool final_response); /** * @brief Reset the server bookkeeping for the current statement. diff --git a/server/core/dcb.cc b/server/core/dcb.cc index 966d2357e..8c2c59e1d 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -1920,7 +1920,7 @@ static void dcb_call_callback(DCB* dcb, DCB_REASON reason) } } -static void dcb_hangup_foreach_worker(MXB_WORKER* worker, struct server* server) +static void dcb_hangup_foreach_worker(MXB_WORKER* worker, struct SERVER* server) { RoutingWorker* rworker = static_cast(worker); int id = rworker->id(); @@ -1940,7 +1940,7 @@ static void dcb_hangup_foreach_worker(MXB_WORKER* worker, struct server* server) * * @param reason The DCB_REASON that triggers the callback */ -void dcb_hangup_foreach(struct server* server) +void dcb_hangup_foreach(struct SERVER* server) { intptr_t arg1 = (intptr_t)dcb_hangup_foreach_worker; intptr_t arg2 = (intptr_t)server; diff --git a/server/modules/routing/hintrouter/dcb.hh b/server/modules/routing/hintrouter/dcb.hh index 777079327..75361e68a 100644 --- a/server/modules/routing/hintrouter/dcb.hh +++ b/server/modules/routing/hintrouter/dcb.hh @@ -36,7 +36,7 @@ public: return *this; } - struct server* server() const + struct SERVER* server() const { return (this->m_sInner.get()) ? m_sInner.get()->server : NULL; }