From 40485d746cfb6da8610522d0699229f958fb557a Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 19 Dec 2018 15:15:02 +0200 Subject: [PATCH] MXS-2220 Change server name to constant string --- examples/roundrobinrouter.cpp | 2 +- include/maxscale/backend.hh | 2 +- include/maxscale/server.hh | 8 ++- server/core/config.cc | 2 +- server/core/config_runtime.cc | 28 ++++---- server/core/dcb.cc | 4 +- server/core/internal/server.hh | 17 ++++- server/core/monitor.cc | 40 ++++++------ server/core/mysql_utils.cc | 4 +- server/core/server.cc | 40 ++++++------ server/core/service.cc | 14 ++-- server/core/session.cc | 2 +- server/core/test/test_local_address.cc | 3 +- server/core/test/test_server.cc | 2 +- .../GSSAPI/GSSAPIAuth/gssapi_auth.cc | 2 +- .../GSSAPIBackendAuth/gssapi_backend_auth.cc | 2 +- .../authenticator/MySQLAuth/dbusers.cc | 4 +- .../authenticator/PAM/PAMAuth/pam_instance.cc | 6 +- .../PAM/PAMBackendAuth/pam_backend_session.cc | 8 +-- server/modules/filter/tpmfilter/tpmfilter.cc | 2 +- server/modules/monitor/galeramon/galeramon.cc | 10 +-- .../mariadbmon/cluster_manipulation.cc | 10 +-- .../monitor/mariadbmon/mariadbserver.cc | 2 +- .../mariadbmon/test/test_cycle_find.cc | 5 +- server/modules/monitor/mmmon/mmmon.cc | 2 +- .../MySQL/mariadbbackend/mysql_backend.cc | 8 +-- server/modules/routing/binlogrouter/blr.cc | 2 +- .../routing/binlogrouter/blr_master.cc | 8 +-- server/modules/routing/debugcli/debugcmd.cc | 12 ++-- .../modules/routing/hintrouter/hintrouter.cc | 4 +- .../routing/hintrouter/hintroutersession.cc | 14 ++-- .../routing/readconnroute/readconnroute.cc | 12 ++-- .../routing/readwritesplit/readwritesplit.cc | 6 +- .../routing/readwritesplit/rwsplitsession.cc | 2 +- .../schemarouter/schemaroutersession.cc | 64 +++++++++---------- .../schemarouter/schemaroutersession.hh | 2 +- .../modules/routing/schemarouter/shard_map.cc | 12 ++-- 37 files changed, 194 insertions(+), 173 deletions(-) diff --git a/examples/roundrobinrouter.cpp b/examples/roundrobinrouter.cpp index bdad10af0..516fce0a7 100644 --- a/examples/roundrobinrouter.cpp +++ b/examples/roundrobinrouter.cpp @@ -269,7 +269,7 @@ int RRRouter::route_query(RRRouterSession* rses, GWBUF* querybuf) { MXS_NOTICE("Routing statement of length %du to backend '%s'.", gwbuf_length(querybuf), - target->server->name); + target->server->name()); } /* Do not use dcb_write() to output to a dcb. dcb_write() is used only * for raw write in the procol modules. */ diff --git a/include/maxscale/backend.hh b/include/maxscale/backend.hh index a7d42101e..91819cfc9 100644 --- a/include/maxscale/backend.hh +++ b/include/maxscale/backend.hh @@ -311,7 +311,7 @@ public: */ inline const char* name() const { - return m_backend->server->name; + return m_backend->server->name(); } /** diff --git a/include/maxscale/server.hh b/include/maxscale/server.hh index b41794483..c9afc1437 100644 --- a/include/maxscale/server.hh +++ b/include/maxscale/server.hh @@ -82,7 +82,6 @@ public: }; // Base settings - char* name = nullptr; /**< Server config name */ char* protocol = nullptr; /**< Backend protocol module name */ char* authenticator = nullptr; /**< Authenticator module name */ @@ -190,6 +189,13 @@ public: */ virtual std::string version_string() const = 0; + /** + * Returns the server configuration name. The value is returned as a c-string for printing convenience. + * + * @return Server name + */ + virtual const char* name() const = 0; + /** * Update the server port. TODO: Move this to internal class once blr is gone. * diff --git a/server/core/config.cc b/server/core/config.cc index 53e573a6c..32a90973f 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -3727,7 +3727,7 @@ int create_new_server(CONFIG_CONTEXT* obj) { MXS_ERROR("Invalid value for '%s' for server %s: %s", CN_DISK_SPACE_THRESHOLD, - server->name, + server->name(), disk_space_threshold); error = true; } diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 9a4194479..36fda56cb 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -150,7 +150,7 @@ bool runtime_link_server(Server* server, const char* target) { config_runtime_error("Service '%s' already uses server '%s'", service->name, - server->name); + server->name()); } } else if (monitor) @@ -162,14 +162,14 @@ bool runtime_link_server(Server* server, const char* target) } else { - config_runtime_error("Server '%s' is already monitored", server->name); + config_runtime_error("Server '%s' is already monitored", server->name()); } } if (rval) { const char* type = service ? "service" : "monitor"; - MXS_NOTICE("Added server '%s' to %s '%s'", server->name, type, target); + MXS_NOTICE("Added server '%s' to %s '%s'", server->name(), type, target); } return rval; @@ -199,7 +199,7 @@ bool runtime_unlink_server(Server* server, const char* target) } const char* type = service ? "service" : "monitor"; - MXS_NOTICE("Removed server '%s' from %s '%s'", server->name, type, target); + MXS_NOTICE("Removed server '%s' from %s '%s'", server->name(), type, target); } return rval; @@ -248,7 +248,7 @@ bool runtime_create_server(const char* name, { rval = true; MXS_NOTICE("Created server '%s' at %s:%u", - server->name, + server->name(), server->address, server->port); } @@ -281,8 +281,8 @@ bool runtime_destroy_server(Server* server) { const char* err = "Cannot destroy server '%s' as it is used by at least " "one service or monitor"; - config_runtime_error(err, server->name); - MXS_ERROR(err, server->name); + config_runtime_error(err, server->name()); + MXS_ERROR(err, server->name()); } else { @@ -291,7 +291,7 @@ bool runtime_destroy_server(Server* server) sizeof(filename), "%s/%s.cnf", get_config_persistdir(), - server->name); + server->name()); if (unlink(filename) == -1) { @@ -307,7 +307,7 @@ bool runtime_destroy_server(Server* server) rval = true; MXS_WARNING("Server '%s' was not created at runtime. Remove the " "server manually from the correct configuration file.", - server->name); + server->name()); } } else @@ -318,7 +318,7 @@ bool runtime_destroy_server(Server* server) if (rval) { MXS_NOTICE("Destroyed server '%s' at %s:%u", - server->name, + server->name(), server->address, server->port); server->is_active = false; @@ -371,7 +371,7 @@ bool runtime_enable_server_ssl(Server* server, if (key && cert && ca) { std::lock_guard guard(crt_lock); - SSL_LISTENER* ssl = create_ssl(server->name, key, cert, ca, version, depth, verify); + SSL_LISTENER* ssl = create_ssl(server->name(), key, cert, ca, version, depth, verify); if (ssl) { @@ -385,7 +385,7 @@ bool runtime_enable_server_ssl(Server* server, if (server->serialize()) { - MXS_NOTICE("Enabled SSL for server '%s'", server->name); + MXS_NOTICE("Enabled SSL for server '%s'", server->name()); rval = true; } } @@ -525,7 +525,7 @@ bool runtime_alter_server(Server* server, const char* key, const char* value) } server->serialize(); - MXS_NOTICE("Updated server '%s': %s=%s", server->name, key, value); + MXS_NOTICE("Updated server '%s': %s=%s", server->name(), key, value); return true; } @@ -1772,7 +1772,7 @@ static bool process_ssl_parameters(Server* server, json_t* params) { config_runtime_error("Failed to initialize SSL for server '%s'. See " "error log for more details.", - server->name); + server->name()); rval = false; } } diff --git a/server/core/dcb.cc b/server/core/dcb.cc index ec7504deb..310ad37a4 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -997,7 +997,7 @@ static void log_illegal_dcb(DCB* dcb) switch (dcb->role) { case DCB::Role::BACKEND: - connected_to = dcb->server->name; + connected_to = dcb->server->name(); break; case DCB::Role::CLIENT: @@ -3246,7 +3246,7 @@ json_t* dcb_to_json(DCB* dcb) char buf[25]; snprintf(buf, sizeof(buf), "%p", dcb); json_object_set_new(obj, "id", json_string(buf)); - json_object_set_new(obj, "server", json_string(dcb->server->name)); + json_object_set_new(obj, "server", json_string(dcb->server->name())); if (dcb->func.diagnostics_json) { diff --git a/server/core/internal/server.hh b/server/core/internal/server.hh index feabf163f..c40e354eb 100644 --- a/server/core/internal/server.hh +++ b/server/core/internal/server.hh @@ -31,8 +31,9 @@ std::unique_ptr serverGetList(); class Server : public SERVER { public: - Server() + Server(const std::string& name) : SERVER() + , m_name(name) , m_response_time(maxbase::EMAverage {0.04, 0.35, 500}) { } @@ -115,6 +116,11 @@ public: return info.version_string(); } + const char* name() const override + { + return m_name.c_str(); + } + /** * Get a DCB from the persistent connection pool, if possible * @@ -149,6 +155,14 @@ public: */ static Server* server_alloc(const char* name, MXS_CONFIG_PARAMETER* params); + /** + * Creates a server without any configuration. This should be used in unit tests in place of + * a default ctor. + * + * @return A new server + */ + static Server* create_test_server(); + /** * @brief Find a server with the specified name * @@ -274,6 +288,7 @@ private: char m_version_str[MAX_VERSION_LEN] = {'\0'}; /**< Server version string */ }; + const std::string m_name; /**< Server config name */ Settings m_settings; /**< Server settings */ VersionInfo info; /**< Server version and type information */ maxbase::EMAverage m_response_time; /**< Response time calculations for this server */ diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 278cf3761..322bb41a0 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -370,7 +370,7 @@ bool monitor_add_server(MXS_MONITOR* mon, SERVER* server) if (monitor_server_in_use(server)) { - MXS_ERROR("Server '%s' is already monitored.", server->name); + MXS_ERROR("Server '%s' is already monitored.", server->name()); } else { @@ -779,7 +779,7 @@ bool check_monitor_permissions(MXS_MONITOR* monitor, const char* query) MXS_ERROR("[%s] Failed to connect to server '%s' ([%s]:%d) when" " checking monitor user credentials and permissions: %s", monitor->name, - mondb->server->name, + mondb->server->name(), mondb->server->address, mondb->server->port, mysql_error(mondb->con)); @@ -1533,7 +1533,7 @@ void mon_log_connect_error(MXS_MONITORED_SERVER* database, mxs_connect_result_t const char REFUSED[] = "Monitor was unable to connect to server %s[%s:%d] : '%s'"; auto srv = database->server; MXS_ERROR(rval == MONITOR_CONN_TIMEOUT ? TIMED_OUT : REFUSED, - srv->name, + srv->name(), srv->address, srv->port, mysql_error(database->con)); @@ -1544,7 +1544,7 @@ static void mon_log_state_change(MXS_MONITORED_SERVER* ptr) string prev = mxs::server_status(ptr->mon_prev_status); string next = mxs::server_status(ptr->server); MXS_NOTICE("Server changed state: %s[%s:%u]: %s. [%s] -> [%s]", - ptr->server->name, ptr->server->address, ptr->server->port, + ptr->server->name(), ptr->server->address, ptr->server->port, mon_get_event_name(ptr), prev.c_str(), next.c_str()); } @@ -1603,7 +1603,7 @@ static bool create_monitor_config(const MXS_MONITOR* monitor, const char* filena { dprintf(file, ","); } - dprintf(file, "%s", db->server->name); + dprintf(file, "%s", db->server->name()); } dprintf(file, "\n"); } @@ -1680,7 +1680,7 @@ void mon_hangup_failed_servers(MXS_MONITOR* monitor) void mon_report_query_error(MXS_MONITORED_SERVER* db) { MXS_ERROR("Failed to execute query on server '%s' ([%s]:%d): %s", - db->server->name, + db->server->name(), db->server->address, db->server->port, mysql_error(db->con)); @@ -1831,7 +1831,7 @@ json_t* monitor_json_data(const MXS_MONITOR* monitor, const char* host) for (MXS_MONITORED_SERVER* db = monitor->monitored_servers; db; db = db->next) { - mxs_json_add_relation(mon_rel, db->server->name, CN_SERVERS); + mxs_json_add_relation(mon_rel, db->server->name(), CN_SERVERS); } json_object_set_new(rel, CN_SERVERS, mon_rel); @@ -2009,8 +2009,8 @@ static void store_data(MXS_MONITOR* monitor, MXS_MONITORED_SERVER* master, uint8 for (MXS_MONITORED_SERVER* db = monitor->monitored_servers; db; db = db->next) { *ptr++ = (char)SVT_SERVER; // Value type - memcpy(ptr, db->server->name, strlen(db->server->name));// Name of the server - ptr += strlen(db->server->name); + memcpy(ptr, db->server->name(), strlen(db->server->name()));// Name of the server + ptr += strlen(db->server->name()); *ptr++ = '\0'; // Null-terminate the string auto status = db->server->status; @@ -2023,8 +2023,8 @@ static void store_data(MXS_MONITOR* monitor, MXS_MONITORED_SERVER* master, uint8 if (master) { *ptr++ = (char)SVT_MASTER; - memcpy(ptr, master->server->name, strlen(master->server->name)); - ptr += strlen(master->server->name); + memcpy(ptr, master->server->name(), strlen(master->server->name())); + ptr += strlen(master->server->name()); *ptr++ = '\0'; // Null-terminate the string } @@ -2097,7 +2097,7 @@ static const char* process_server(MXS_MONITOR* monitor, const char* data, const { for (MXS_MONITORED_SERVER* db = monitor->monitored_servers; db; db = db->next) { - if (strcmp(db->server->name, data) == 0) + if (strcmp(db->server->name(), data) == 0) { const unsigned char* sptr = (unsigned char*)strchr(data, '\0'); mxb_assert(sptr); @@ -2128,7 +2128,7 @@ static const char* process_master(MXS_MONITOR* monitor, { for (MXS_MONITORED_SERVER* db = monitor->monitored_servers; db; db = db->next) { - if (strcmp(db->server->name, data) == 0) + if (strcmp(db->server->name(), data) == 0) { *master = db; break; @@ -2206,13 +2206,13 @@ void store_server_journal(MXS_MONITOR* monitor, MXS_MONITORED_SERVER* master) { /** Each server is stored as a type byte and a null-terminated string * followed by eight byte server status. */ - size += MMB_LEN_VALUE_TYPE + strlen(db->server->name) + 1 + MMB_LEN_SERVER_STATUS; + size += MMB_LEN_VALUE_TYPE + strlen(db->server->name()) + 1 + MMB_LEN_SERVER_STATUS; } if (master) { /** The master server name is stored as a null terminated string */ - size += MMB_LEN_VALUE_TYPE + strlen(master->server->name) + 1; + size += MMB_LEN_VALUE_TYPE + strlen(master->server->name()) + 1; } /** 4 bytes for file length, 1 byte for schema version and 4 bytes for CRC32 */ @@ -2434,7 +2434,7 @@ int mon_config_get_servers(const MXS_CONFIG_PARAMETER* params, else { MXS_WARNING("Server '%s' is not monitored by monitor '%s'.", - servers[i]->name, + servers[i]->name(), mon->name); } } @@ -2652,7 +2652,7 @@ bool check_disk_space_exhausted(MXS_MONITORED_SERVER* pMs, { MXS_ERROR("Disk space on %s at %s is exhausted; %d%% of the the disk " "mounted on the path %s has been used, and the limit it %d%%.", - pMs->server->name, + pMs->server->name(), pMs->server->address, used_percentage, path.c_str(), @@ -2708,7 +2708,7 @@ void MonitorInstance::update_disk_space_status(MXS_MONITORED_SERVER* pMs) MXS_WARNING("Disk space threshold specified for %s even though server %s at %s" "does not have that.", path.c_str(), - pMs->server->name, + pMs->server->name(), pMs->server->address); } } @@ -2752,14 +2752,14 @@ void MonitorInstance::update_disk_space_status(MXS_MONITORED_SERVER* pMs) MXS_ERROR("Disk space cannot be checked for %s at %s, because either the " "version (%s) is too old, or the DISKS information schema plugin " "has not been installed. Disk space checking has been disabled.", - pServer->name, + pServer->name(), pServer->address, pServer->version_string().c_str()); } else { MXS_ERROR("Checking the disk space for %s at %s failed due to: (%d) %s", - pServer->name, + pServer->name(), pServer->address, mysql_errno(pMs->con), mysql_error(pMs->con)); diff --git a/server/core/mysql_utils.cc b/server/core/mysql_utils.cc index d71ad790b..2a9fde3ac 100644 --- a/server/core/mysql_utils.cc +++ b/server/core/mysql_utils.cc @@ -183,7 +183,7 @@ MYSQL* mxs_mysql_real_connect(MYSQL* con, SERVER* server, const char* user, cons if (!mysql && extra_port > 0) { mysql = mysql_real_connect(con, server->address, user, passwd, NULL, extra_port, NULL, 0); - MXS_WARNING("Could not connect with normal port to server '%s', using extra_port", server->name); + MXS_WARNING("Could not connect with normal port to server '%s', using extra_port", server->name()); } if (mysql) @@ -200,7 +200,7 @@ MYSQL* mxs_mysql_real_connect(MYSQL* con, SERVER* server, const char* user, cons server->warn_ssl_not_enabled = false; MXS_ERROR("An encrypted connection to '%s' could not be created, " "ensure that TLS is enabled on the target server.", - server->name); + server->name()); } // Don't close the connection as it is closed elsewhere, just set to NULL mysql = NULL; diff --git a/server/core/server.cc b/server/core/server.cc index 558ccbf74..c9dfbd810 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -199,16 +199,14 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params) return NULL; } - Server* server = new(std::nothrow) Server; - char* my_name = MXS_STRDUP(name); + Server* server = new(std::nothrow) Server(name); char* my_protocol = MXS_STRDUP(protocol); char* my_authenticator = MXS_STRDUP(authenticator); DCB** persistent = (DCB**)MXS_CALLOC(config_threadcount(), sizeof(*persistent)); - if (!server || !my_name || !my_protocol || !my_authenticator || !persistent) + if (!server || !my_protocol || !my_authenticator || !persistent) { delete server; - MXS_FREE(my_name); MXS_FREE(persistent); MXS_FREE(my_protocol); MXS_FREE(my_authenticator); @@ -225,7 +223,6 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params) sizeof(server->address)); } - server->name = my_name; server->port = config_get_integer(params, CN_PORT); server->extra_port = config_get_integer(params, CN_EXTRA_PORT); server->protocol = my_protocol; @@ -261,6 +258,12 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params) return server; } +Server* Server::create_test_server() +{ + static int next_id = 1; + string name = "TestServer" + std::to_string(next_id++); + return new Server(name); +} /** * Deallocate the specified server @@ -281,7 +284,6 @@ void server_free(Server* server) /* Clean up session and free the memory */ MXS_FREE(server->protocol); - MXS_FREE(server->name); MXS_FREE(server->authenticator); if (server->persistent) @@ -353,7 +355,7 @@ SERVER* server_find_by_unique_name(const char* name) Guard guard(this_unit.all_servers_lock); for (Server* server : this_unit.all_servers) { - if (server->is_active && strcmp(server->name, name) == 0) + if (server->is_active && strcmp(server->name(), name) == 0) { return server; } @@ -508,7 +510,7 @@ void Server::print_to_dcb(DCB* dcb) const return; } - dcb_printf(dcb, "Server %p (%s)\n", server, server->name); + dcb_printf(dcb, "Server %p (%s)\n", server, server->name()); dcb_printf(dcb, "\tServer: %s\n", server->address); string stat = mxs::server_status(server); dcb_printf(dcb, "\tStatus: %s\n", stat.c_str()); @@ -635,7 +637,7 @@ void Server::dListServers(DCB* dcb) string stat = mxs::server_status(server); dcb_printf(dcb, "%-18s | %-15s | %5d | %11d | %s\n", - server->name, + server->name(), server->address, server->port, server->stats.n_current, @@ -803,7 +805,7 @@ void server_add_mon_user(SERVER* server, const char* user, const char* passwd) { MXS_WARNING("Truncated monitor user for server '%s', maximum username " "length is %lu characters.", - server->name, + server->name(), sizeof(server->monuser)); } @@ -812,7 +814,7 @@ void server_add_mon_user(SERVER* server, const char* user, const char* passwd) { MXS_WARNING("Truncated monitor password for server '%s', maximum password " "length is %lu characters.", - server->name, + server->name(), sizeof(server->monpw)); } } @@ -887,7 +889,7 @@ std::unique_ptr serverGetList() if (server_is_active(server)) { string stat = mxs::server_status(server); - set->add_row({server->name, server->address, std::to_string(server->port), + set->add_row({server->name(), server->address, std::to_string(server->port), std::to_string(server->stats.n_current), stat}); } } @@ -980,14 +982,14 @@ bool Server::create_server_config(const Server* server, const char* filename) { MXS_ERROR("Failed to open file '%s' when serializing server '%s': %d, %s", filename, - server->name, + server->name(), errno, mxs_strerror(errno)); return false; } // TODO: Check for return values on all of the dprintf calls - dprintf(file, "[%s]\n", server->name); + dprintf(file, "[%s]\n", server->name()); dprintf(file, "%s=server\n", CN_TYPE); const MXS_MODULE* mod = get_module(server->protocol, MODULE_PROTOCOL); @@ -1016,7 +1018,7 @@ bool Server::serialize() const sizeof(filename), "%s/%s.cnf.tmp", get_config_persistdir(), - server->name); + server->name()); if (unlink(filename) == -1 && errno != ENOENT) { @@ -1248,7 +1250,7 @@ static json_t* server_to_json_data(const Server* server, const char* host) json_t* rval = json_object(); /** Add resource identifiers */ - json_object_set_new(rval, CN_ID, json_string(server->name)); + json_object_set_new(rval, CN_ID, json_string(server->name())); json_object_set_new(rval, CN_TYPE, json_string(CN_SERVERS)); /** Relationships */ @@ -1269,7 +1271,7 @@ static json_t* server_to_json_data(const Server* server, const char* host) json_object_set_new(rval, CN_RELATIONSHIPS, rel); /** Attributes */ json_object_set_new(rval, CN_ATTRIBUTES, Server::server_json_attributes(server)); - json_object_set_new(rval, CN_LINKS, mxs_json_self_link(host, CN_SERVERS, server->name)); + json_object_set_new(rval, CN_LINKS, mxs_json_self_link(host, CN_SERVERS, server->name())); return rval; } @@ -1277,7 +1279,7 @@ static json_t* server_to_json_data(const Server* server, const char* host) json_t* server_to_json(const Server* server, const char* host) { string self = MXS_JSON_API_SERVERS; - self += server->name; + self += server->name(); return mxs_json_resource(host, self.c_str(), server_to_json_data(server, host)); } @@ -1371,7 +1373,7 @@ Server* Server::find_by_unique_name(const string& name) Guard guard(this_unit.all_servers_lock); for (Server* server : this_unit.all_servers) { - if (server->is_active && name == server->name) + if (server->is_active && server->m_name == name) { return server; } diff --git a/server/core/service.cc b/server/core/service.cc index eca768f22..516425908 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -920,7 +920,7 @@ void dprintService(DCB* dcb, SERVICE* svc) server->server->address, server->server->port, server->server->protocol, - server->server->name); + server->server->name()); } server = server->next; } @@ -978,11 +978,11 @@ void dListServices(DCB* dcb) { if (first) { - dcb_printf(dcb, "%s", server_ref->server->name); + dcb_printf(dcb, "%s", server_ref->server->name()); } else { - dcb_printf(dcb, ", %s", server_ref->server->name); + dcb_printf(dcb, ", %s", server_ref->server->name()); } first = false; } @@ -1363,7 +1363,7 @@ static void service_calculate_weights(SERVICE* service) " will only be used if no other servers are available.", weightby, config_weight, - server->server->name); + server->server->name()); config_weight = 0; } server->server_weight = config_weight / total; @@ -1374,7 +1374,7 @@ static void service_calculate_weights(SERVICE* service) " The runtime weight will be set to 0, and the server" " will only be used if no other servers are available.", weightby, - server->server->name); + server->server->name()); server->server_weight = 0; } } @@ -1481,7 +1481,7 @@ bool Service::dump_config(const char* filename) const { if (SERVER_REF_IS_ACTIVE(db)) { - dprintf(file, "%s%s", sep, db->server->name); + dprintf(file, "%s%s", sep, db->server->name()); sep = ","; } } @@ -1709,7 +1709,7 @@ json_t* Service::json_relationships(const char* host) const { if (SERVER_REF_IS_ACTIVE(ref)) { - mxs_json_add_relation(servers, ref->server->name, CN_SERVERS); + mxs_json_add_relation(servers, ref->server->name(), CN_SERVERS); } } diff --git a/server/core/session.cc b/server/core/session.cc index 09f1fae6d..30dfe35d5 100644 --- a/server/core/session.cc +++ b/server/core/session.cc @@ -1541,7 +1541,7 @@ json_t* Session::QueryInfo::as_json() const long int duration = processed - received; - json_object_set_new(pResponse, "server", json_string(info.pServer->name)); + json_object_set_new(pResponse, "server", json_string(info.pServer->name())); json_object_set_new(pResponse, "duration", json_integer(duration)); json_array_append_new(pResponses, pResponse); diff --git a/server/core/test/test_local_address.cc b/server/core/test/test_local_address.cc index e789a6698..97666e9a3 100644 --- a/server/core/test/test_local_address.cc +++ b/server/core/test/test_local_address.cc @@ -79,7 +79,8 @@ int test(bool success, const char* zHost, const char* zUser, const char* zPasswo MXS_CONFIG* config = config_get_global_options(); config->local_address = const_cast(zAddress); - Server server; + Server* pServer = Server::create_test_server(); + Server& server = *pServer; strcpy(server.address, zHost); server.port = 3306; diff --git a/server/core/test/test_server.cc b/server/core/test/test_server.cc index c520e203f..759e1ab97 100644 --- a/server/core/test/test_server.cc +++ b/server/core/test/test_server.cc @@ -112,7 +112,7 @@ bool test_load_config(const char* input, SERVER* server) MXS_CONFIG_PARAMETER* param = obj->parameters; config_add_defaults(obj, config_server_params); - TEST(strcmp(obj->object, server->name) == 0, "Server names differ"); + TEST(strcmp(obj->object, server->name()) == 0, "Server names differ"); TEST(strcmp(server->address, config_get_param(param, "address")->value) == 0, "Server addresses differ"); TEST(strcmp(server->protocol, config_get_param(param, "protocol")->value) == 0, diff --git a/server/modules/authenticator/GSSAPI/GSSAPIAuth/gssapi_auth.cc b/server/modules/authenticator/GSSAPI/GSSAPIAuth/gssapi_auth.cc index 5dca62172..3b961da84 100644 --- a/server/modules/authenticator/GSSAPI/GSSAPIAuth/gssapi_auth.cc +++ b/server/modules/authenticator/GSSAPI/GSSAPIAuth/gssapi_auth.cc @@ -649,7 +649,7 @@ int gssapi_auth_load_users(Listener* listener) if (mxs_mysql_query(mysql, gssapi_users_query)) { MXS_ERROR("Failed to query server '%s' for GSSAPI users: %s", - servers->server->name, + servers->server->name(), mysql_error(mysql)); } else diff --git a/server/modules/authenticator/GSSAPI/GSSAPIBackendAuth/gssapi_backend_auth.cc b/server/modules/authenticator/GSSAPI/GSSAPIBackendAuth/gssapi_backend_auth.cc index d9e0f0870..d396856b4 100644 --- a/server/modules/authenticator/GSSAPI/GSSAPIBackendAuth/gssapi_backend_auth.cc +++ b/server/modules/authenticator/GSSAPI/GSSAPIBackendAuth/gssapi_backend_auth.cc @@ -107,7 +107,7 @@ bool extract_principal_name(DCB* dcb, GWBUF* buffer) * it's possible that the server authenticated us as the anonymous user. This * means that the server is not secure. */ MXS_ERROR("Server '%s' returned an unexpected authentication response.%s", - dcb->server->name, + dcb->server->name(), databuf[0] == MYSQL_REPLY_OK ? " Authentication was complete before it even started, " "anonymous users might not be disabled." : ""); diff --git a/server/modules/authenticator/MySQLAuth/dbusers.cc b/server/modules/authenticator/MySQLAuth/dbusers.cc index 90cb08e35..e2f7864fe 100644 --- a/server/modules/authenticator/MySQLAuth/dbusers.cc +++ b/server/modules/authenticator/MySQLAuth/dbusers.cc @@ -884,7 +884,7 @@ static bool check_server_permissions(SERVICE* service, MXS_ERROR("[%s] Failed to connect to server '%s' ([%s]:%d) when" " checking authentication user credentials and permissions: %d %s", service->name, - server->name, + server->name(), server->address, server->port, my_errno, @@ -1146,7 +1146,7 @@ int get_users_from_server(MYSQL* con, SERVER_REF* server_ref, SERVICE* service, if (!rv) { - MXS_ERROR("Failed to load users from server '%s': %s", server->name, mysql_error(con)); + MXS_ERROR("Failed to load users from server '%s': %s", server->name(), mysql_error(con)); } MXS_FREE(query); diff --git a/server/modules/authenticator/PAM/PAMAuth/pam_instance.cc b/server/modules/authenticator/PAM/PAMAuth/pam_instance.cc index 8db88d005..ea010865a 100644 --- a/server/modules/authenticator/PAM/PAMAuth/pam_instance.cc +++ b/server/modules/authenticator/PAM/PAMAuth/pam_instance.cc @@ -208,7 +208,7 @@ int PamInstance::load_users(SERVICE* service) if (mysql_query(mysql, PAM_USERS_QUERY)) { MXS_ERROR("Failed to query server '%s' for PAM users: '%s'.", - servers->server->name, + servers->server->name(), mysql_error(mysql)); } else @@ -319,7 +319,7 @@ bool PamInstance::query_anon_proxy_user(SERVER* server, MYSQL* conn) if (mysql_query(conn, ANON_USER_QUERY)) { MXS_ERROR("Failed to query server '%s' for the anonymous PAM user: '%s'.", - server->name, + server->name(), mysql_error(conn)); success = false; } @@ -346,7 +346,7 @@ bool PamInstance::query_anon_proxy_user(SERVER* server, MYSQL* conn) if (mysql_query(conn, ANON_GRANT_QUERY)) { MXS_ERROR("Failed to query server '%s' for the grants of the anonymous PAM user: '%s'.", - server->name, + server->name(), mysql_error(conn)); success = false; } diff --git a/server/modules/authenticator/PAM/PAMBackendAuth/pam_backend_session.cc b/server/modules/authenticator/PAM/PAMBackendAuth/pam_backend_session.cc index 38aab7b1f..fbd3f38f6 100644 --- a/server/modules/authenticator/PAM/PAMBackendAuth/pam_backend_session.cc +++ b/server/modules/authenticator/PAM/PAMBackendAuth/pam_backend_session.cc @@ -48,7 +48,7 @@ bool check_auth_switch_request(DCB* dcb, GWBUF* buffer) bool was_ok_packet = copied > MYSQL_HEADER_LEN && data[MYSQL_HEADER_LEN + 1] == MYSQL_REPLY_OK; MXS_ERROR("Server '%s' returned an unexpected authentication response.%s", - dcb->server->name, + dcb->server->name(), was_ok_packet ? " Authentication was complete before it even started, " "anonymous users might not be disabled." : ""); @@ -124,7 +124,7 @@ bool PamBackendSession::extract(DCB* dcb, GWBUF* buffer) if (mxs_mysql_is_ok_packet(buffer)) { MXS_DEBUG("pam_backend_auth_extract received ok packet from '%s'.", - dcb->server->name); + dcb->server->name()); m_state = PAM_AUTH_OK; rval = true; } @@ -138,7 +138,7 @@ bool PamBackendSession::extract(DCB* dcb, GWBUF* buffer) if (!rval) { MXS_DEBUG("pam_backend_auth_extract to backend '%s' failed for user '%s'.", - dcb->server->name, + dcb->server->name(), dcb->user); } return rval; @@ -151,7 +151,7 @@ int PamBackendSession::authenticate(DCB* dcb) if (m_state == PAM_AUTH_INIT) { MXS_DEBUG("pam_backend_auth_authenticate sending password to '%s'.", - dcb->server->name); + dcb->server->name()); if (send_client_password(dcb)) { rval = MXS_AUTH_INCOMPLETE; diff --git a/server/modules/filter/tpmfilter/tpmfilter.cc b/server/modules/filter/tpmfilter/tpmfilter.cc index 91796ad03..6103a20e1 100644 --- a/server/modules/filter/tpmfilter/tpmfilter.cc +++ b/server/modules/filter/tpmfilter/tpmfilter.cc @@ -601,7 +601,7 @@ static int clientReply(MXS_FILTER* instance, MXS_FILTER_SESSION* session, GWBUF* "%ld%s%s%s%s%s%ld%s%s%s%s\n", timestamp, my_instance->delimiter, - reply->server->name, + reply->server->name(), my_instance->delimiter, my_session->userName, my_instance->delimiter, diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index 52db129d0..cf877af61 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -170,7 +170,7 @@ void GaleraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server) if (warn_erange_on_local_index) { MXS_WARNING("Invalid 'wsrep_local_index' on server '%s': %s", - monitored_server->server->name, + monitored_server->server->name(), row[1]); warn_erange_on_local_index = false; } @@ -655,20 +655,20 @@ static int compare_node_priority(const void* a, const void* b) if (!have_a && have_b) { MXS_DEBUG("Server %s has no given priority. It will be at the beginning of the list", - s_a->server->name); + s_a->server->name()); return -(INT_MAX - 1); } else if (have_a && !have_b) { MXS_DEBUG("Server %s has no given priority. It will be at the beginning of the list", - s_b->server->name); + s_b->server->name()); return INT_MAX - 1; } else if (!have_a && !have_b) { MXS_DEBUG("Servers %s and %s have no given priority. They be at the beginning of the list", - s_a->server->name, - s_b->server->name); + s_a->server->name(), + s_b->server->name()); return 0; } diff --git a/server/modules/monitor/mariadbmon/cluster_manipulation.cc b/server/modules/monitor/mariadbmon/cluster_manipulation.cc index 7069bfdad..3e3848513 100644 --- a/server/modules/monitor/mariadbmon/cluster_manipulation.cc +++ b/server/modules/monitor/mariadbmon/cluster_manipulation.cc @@ -171,7 +171,7 @@ bool MariaDBMonitor::manual_rejoin(SERVER* rejoin_cand_srv, json_t** output) else { PRINT_MXS_JSON_ERROR(output, "%s is not monitored by %s, cannot rejoin.", - rejoin_cand_srv->name, m_monitor->name); + rejoin_cand_srv->name(), m_monitor->name); } } else @@ -204,7 +204,7 @@ bool MariaDBMonitor::manual_reset_replication(SERVER* master_server, json_t** er MariaDBServer* new_master_cand = get_server(master_server); if (new_master_cand == NULL) { - PRINT_MXS_JSON_ERROR(error_out, NO_SERVER, master_server->name, m_monitor->name); + PRINT_MXS_JSON_ERROR(error_out, NO_SERVER, master_server->name(), m_monitor->name); } else if (!new_master_cand->is_usable()) { @@ -608,7 +608,7 @@ bool MariaDBMonitor::start_external_replication(MariaDBServer* new_master, json_ uint32_t MariaDBMonitor::do_rejoin(const ServerArray& joinable_servers, json_t** output) { SERVER* master_server = m_master->m_server_base->server; - const char* master_name = master_server->name; + const char* master_name = master_server->name(); uint32_t servers_joined = 0; if (!joinable_servers.empty()) { @@ -1602,7 +1602,7 @@ MariaDBMonitor::switchover_prepare(SERVER* promotion_server, SERVER* demotion_se MariaDBServer* demotion_candidate = get_server(demotion_server); if (demotion_candidate == NULL) { - PRINT_ERROR_IF(log_mode, error_out, NO_SERVER, demotion_server->name, m_monitor->name); + PRINT_ERROR_IF(log_mode, error_out, NO_SERVER, demotion_server->name(), m_monitor->name); } else if (!demotion_candidate->can_be_demoted_switchover(&demotion_msg)) { @@ -1646,7 +1646,7 @@ MariaDBMonitor::switchover_prepare(SERVER* promotion_server, SERVER* demotion_se MariaDBServer* promotion_candidate = get_server(promotion_server); if (promotion_candidate == NULL) { - PRINT_ERROR_IF(log_mode, error_out, NO_SERVER, promotion_server->name, m_monitor->name); + PRINT_ERROR_IF(log_mode, error_out, NO_SERVER, promotion_server->name(), m_monitor->name); } else if (!promotion_candidate->can_be_promoted(op_type, demotion_target, &promotion_msg)) { diff --git a/server/modules/monitor/mariadbmon/mariadbserver.cc b/server/modules/monitor/mariadbmon/mariadbserver.cc index db73dcdbf..00de47fba 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.cc +++ b/server/modules/monitor/mariadbmon/mariadbserver.cc @@ -647,7 +647,7 @@ bool MariaDBServer::is_read_only() const const char* MariaDBServer::name() const { - return m_server_base->server->name; + return m_server_base->server->name(); } string MariaDBServer::diagnostics() const diff --git a/server/modules/monitor/mariadbmon/test/test_cycle_find.cc b/server/modules/monitor/mariadbmon/test/test_cycle_find.cc index bc02f7b29..348eea299 100644 --- a/server/modules/monitor/mariadbmon/test/test_cycle_find.cc +++ b/server/modules/monitor/mariadbmon/test/test_cycle_find.cc @@ -156,9 +156,7 @@ void MariaDBMonitor::Test::init_servers(int count) for (int i = 1; i < count + 1; i++) { - auto base_server = new Server; // Contents mostly undefined - string server_name = create_servername(i); - base_server->name = MXS_STRDUP(server_name.c_str()); + auto base_server = Server::create_test_server(); // Contents mostly undefined MXS_MONITORED_SERVER* mon_server = new MXS_MONITORED_SERVER; // Contents mostly undefined mon_server->server = base_server; @@ -193,7 +191,6 @@ void MariaDBMonitor::Test::clear_servers() m_monitor->m_servers_by_id.clear(); for (MariaDBServer* server : m_monitor->m_servers) { - MXS_FREE(server->m_server_base->server->name); delete server->m_server_base->server; delete server->m_server_base; delete server; diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index 5b725ab24..2547da633 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -208,7 +208,7 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server) " for versions less than 5.5 does not have master_server_id, " "replication tree cannot be resolved for server %s." " MySQL Version: %s", - monitored_server->server->name, + monitored_server->server->name(), server_string.c_str()); monitored_server->log_version_err = false; } diff --git a/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc b/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc index 1a39822f0..e9cfe5f93 100644 --- a/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc +++ b/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc @@ -324,7 +324,7 @@ static void handle_error_response(DCB* dcb, GWBUF* buffer) MXS_ERROR("Invalid authentication message from backend '%s'. Error code: %d, " "Msg : %s", - dcb->server->name, + dcb->server->name(), errcode, bufstr); @@ -337,7 +337,7 @@ static void handle_error_response(DCB* dcb, GWBUF* buffer) "Run 'mysqladmin -h %s -P %d flush-hosts' on this " "server before taking this server out of maintenance " "mode.", - dcb->server->name, + dcb->server->name(), dcb->server->address, dcb->server->port); @@ -1211,7 +1211,7 @@ static int gw_MySQLWrite_backend(DCB* dcb, GWBUF* queue) { MXS_ERROR("Unable to write to backend '%s' due to " "%s failure. Server in state %s.", - dcb->server->name, + dcb->server->name(), backend_protocol->protocol_auth_state == MXS_AUTH_STATE_HANDSHAKE_FAILED ? "handshake" : "authentication", mxs::server_status(dcb->server).c_str()); @@ -1941,7 +1941,7 @@ static void gw_send_proxy_protocol_header(DCB* backend_dcb) { MXS_INFO("Sending proxy-protocol header '%s' to backend %s.", proxy_header, - backend_dcb->server->name); + backend_dcb->server->name()); if (!dcb_write(backend_dcb, headerbuf)) { gwbuf_free(headerbuf); diff --git a/server/modules/routing/binlogrouter/blr.cc b/server/modules/routing/binlogrouter/blr.cc index 8055bc731..82a9fae66 100644 --- a/server/modules/routing/binlogrouter/blr.cc +++ b/server/modules/routing/binlogrouter/blr.cc @@ -1314,7 +1314,7 @@ static void closeSession(MXS_ROUTER* instance, MXS_ROUTER_SESSION* router_sessio time(0) - router->connect_time, router->stats.n_binlogs_ses); MXS_ERROR("Binlog router close session with master server %s", - router->service->dbref->server->name); + router->service->dbref->server->name()); blr_master_reconnect(router); return; } diff --git a/server/modules/routing/binlogrouter/blr_master.cc b/server/modules/routing/binlogrouter/blr_master.cc index 7aa22097a..d3646f2c7 100644 --- a/server/modules/routing/binlogrouter/blr_master.cc +++ b/server/modules/routing/binlogrouter/blr_master.cc @@ -177,7 +177,7 @@ static void blr_start_master(void* data) "reached %d maximum number of retries. " "Replication is stopped.", router->service->name, - router->service->dbref->server->name, + router->service->dbref->server->name(), router->retry_limit); return; } @@ -246,7 +246,7 @@ static void blr_start_master(void* data) MXS_ERROR("%s: failure while connecting to master server '%s', " "retrying in %d seconds", router->service->name, - router->service->dbref->server->name, + router->service->dbref->server->name(), connect_retry); return; } @@ -385,7 +385,7 @@ static void blr_restart_master(ROUTER_INSTANCE* router) "reached %d maximum number of retries. " "Replication is stopped.", router->service->name, - router->service->dbref->server->name, + router->service->dbref->server->name(), router->retry_limit); return; } @@ -419,7 +419,7 @@ static void blr_restart_master(ROUTER_INSTANCE* router) MXS_ERROR("%s: failed to connect to master server '%s', " "retrying in %d seconds", router->service->name, - router->service->dbref->server->name, + router->service->dbref->server->name(), connect_retry); } else diff --git a/server/modules/routing/debugcli/debugcmd.cc b/server/modules/routing/debugcli/debugcmd.cc index 2f6040574..264f157b0 100644 --- a/server/modules/routing/debugcli/debugcmd.cc +++ b/server/modules/routing/debugcli/debugcmd.cc @@ -962,13 +962,13 @@ static void cmd_AddServer(DCB* dcb, Server* server, { if (runtime_link_server(server, values[i])) { - dcb_printf(dcb, "Added server '%s' to '%s'\n", server->name, values[i]); + dcb_printf(dcb, "Added server '%s' to '%s'\n", server->name(), values[i]); } else { dcb_printf(dcb, "Could not add server '%s' to object '%s'. See error log for more details.\n", - server->name, + server->name(), values[i]); } } @@ -1072,7 +1072,7 @@ static void cmd_RemoveServer(DCB* dcb, Server* server, { if (runtime_unlink_server(server, values[i])) { - dcb_printf(dcb, "Removed server '%s' from '%s'\n", server->name, values[i]); + dcb_printf(dcb, "Removed server '%s' from '%s'\n", server->name(), values[i]); } else { @@ -1388,8 +1388,8 @@ static void destroyServer(DCB* dcb, Server* server) /** Do this so that we don't directly access the server. Currently, the * destruction of a server does not free any memory and the server stays * valid. */ - char name[strlen(server->name) + 1]; - strcpy(name, server->name); + char name[strlen(server->name()) + 1]; + strcpy(name, server->name()); if (runtime_destroy_server(server)) { @@ -1566,7 +1566,7 @@ static void alterServer(DCB* dcb, Server* server, dcb_printf(dcb, "Enabling SSL for server '%s' failed, see log " "for more details.\n", - server->name); + server->name()); } } else diff --git a/server/modules/routing/hintrouter/hintrouter.cc b/server/modules/routing/hintrouter/hintrouter.cc index 9bcc5f250..4cd38d6ed 100644 --- a/server/modules/routing/hintrouter/hintrouter.cc +++ b/server/modules/routing/hintrouter/hintrouter.cc @@ -197,7 +197,7 @@ Dcb HintRouter::connect_to_backend(MXS_SESSION* session, HintRouterSession::BackendMap* all_backends) { Dcb result(NULL); - HR_DEBUG("Connecting to %s.", sref->server->name); + HR_DEBUG("Connecting to %s.", sref->server->name()); DCB* new_connection = dcb_connect(sref->server, session, sref->server->protocol); if (new_connection) @@ -206,7 +206,7 @@ Dcb HintRouter::connect_to_backend(MXS_SESSION* session, mxb::atomic::add(&sref->connections, 1, mxb::atomic::RELAXED); result = Dcb(new_connection); - string name(new_connection->server->name); + string name(new_connection->server->name()); all_backends->insert(HintRouterSession::MapElement(name, result)); } else diff --git a/server/modules/routing/hintrouter/hintroutersession.cc b/server/modules/routing/hintrouter/hintroutersession.cc index 3e66d8f03..68f1e7bff 100644 --- a/server/modules/routing/hintrouter/hintroutersession.cc +++ b/server/modules/routing/hintrouter/hintroutersession.cc @@ -43,7 +43,7 @@ public: if (pPacket) { SERVER* pServer = dcb.server(); - HR_DEBUG("Writing packet to %p %s.", dcb.get(), pServer ? pServer->name : "(null)"); + HR_DEBUG("Writing packet to %p %s.", dcb.get(), pServer ? pserver->name() : "(null)"); rv = dcb.write(pPacket); } return rv; @@ -138,13 +138,13 @@ void HintRouterSession::clientReply(GWBUF* pPacket, DCB* pBackend) if (m_surplus_replies == 0) { - HR_DEBUG("Returning packet from %s.", pServer ? pServer->name : "(null)"); + HR_DEBUG("Returning packet from %s.", pServer ? pserver->name() : "(null)"); MXS_SESSION_ROUTE_REPLY(pBackend->session, pPacket); } else { - HR_DEBUG("Ignoring reply packet from %s.", pServer ? pServer->name : "(null)"); + HR_DEBUG("Ignoring reply packet from %s.", pServer ? pserver->name() : "(null)"); --m_surplus_replies; gwbuf_free(pPacket); @@ -219,7 +219,7 @@ bool HintRouterSession::route_by_hint(GWBUF* pPacket, HINT* hint, bool print_err if (master_ok) { - HR_DEBUG("Writing packet to master: '%s'.", m_master.server()->name); + HR_DEBUG("Writing packet to master: '%s'.", m_master.server()->name()); success = m_master.write(pPacket); if (success) { @@ -247,7 +247,7 @@ bool HintRouterSession::route_by_hint(GWBUF* pPacket, HINT* hint, bool print_err BackendMap::const_iterator iter = m_backends.find(backend_name); if (iter != m_backends.end()) { - HR_DEBUG("Writing packet to %s.", iter->second.server()->name); + HR_DEBUG("Writing packet to %s.", iter->second.server()->name()); success = iter->second.write(pPacket); if (success) { @@ -319,7 +319,7 @@ bool HintRouterSession::route_to_slave(GWBUF* pPacket, bool print_errors) Dcb& candidate = m_slaves.at(curr % size); if (server_is_slave(candidate.server())) { - HR_DEBUG("Writing packet to slave: '%s'.", candidate.server()->name); + HR_DEBUG("Writing packet to slave: '%s'.", candidate.server()->name()); success = candidate.write(pPacket); if (success) { @@ -347,7 +347,7 @@ bool HintRouterSession::route_to_slave(GWBUF* pPacket, bool print_errors) for (size_type curr = begin; curr != limit; curr++) { Dcb& candidate = m_slaves.at(curr % size); - HR_DEBUG("Writing packet to slave: '%s'.", candidate.server()->name); + HR_DEBUG("Writing packet to slave: '%s'.", candidate.server()->name()); success = candidate.write(pPacket); if (success) { diff --git a/server/modules/routing/readconnroute/readconnroute.cc b/server/modules/routing/readconnroute/readconnroute.cc index 21f626778..03171cec4 100644 --- a/server/modules/routing/readconnroute/readconnroute.cc +++ b/server/modules/routing/readconnroute/readconnroute.cc @@ -428,7 +428,7 @@ static MXS_ROUTER_SESSION* newSession(MXS_ROUTER* instance, MXS_SESSION* session inst->stats.n_sessions++; MXS_INFO("New session for server %s. Connections : %d", - candidate->server->name, + candidate->server->name(), candidate->connections); return reinterpret_cast(client_rses); @@ -485,15 +485,15 @@ static void log_closed_session(mxs_mysql_cmd_t mysql_command, SERVER_REF* ref) if (server_is_down(ref->server)) { - sprintf(msg, "Server '%s' is down.", ref->server->name); + sprintf(msg, "Server '%s' is down.", ref->server->name()); } else if (server_is_in_maint(ref->server)) { - sprintf(msg, "Server '%s' is in maintenance.", ref->server->name); + sprintf(msg, "Server '%s' is in maintenance.", ref->server->name()); } else { - sprintf(msg, "Server '%s' no longer qualifies as a target server.", ref->server->name); + sprintf(msg, "Server '%s' no longer qualifies as a target server.", ref->server->name()); } MXS_ERROR("Failed to route MySQL command %d to backend server. %s", mysql_command, msg); @@ -598,7 +598,7 @@ static int routeQuery(MXS_ROUTER* instance, MXS_ROUTER_SESSION* router_session, MXS_INFO("Routed [%s] to '%s'%s%s", STRPACKETTYPE(mysql_command), - backend_dcb->server->name, + backend_dcb->server->name(), trc ? ": " : ".", trc ? trc : ""); MXS_FREE(trc); @@ -638,7 +638,7 @@ static void diagnostics(MXS_ROUTER* router, DCB* dcb) { dcb_printf(dcb, "\t\t%-20s %3.1f%% %d\n", - ref->server->name, + ref->server->name(), ref->server_weight * 100, ref->connections); } diff --git a/server/modules/routing/readwritesplit/readwritesplit.cc b/server/modules/routing/readwritesplit/readwritesplit.cc index f682c3ed4..1bb81a09e 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.cc +++ b/server/modules/routing/readwritesplit/readwritesplit.cc @@ -347,7 +347,7 @@ void RWSplit::diagnostics(DCB* dcb) { dcb_printf(dcb, "\t\t%-20s %3.1f%% %-6d %-6d %d\n", - ref->server->name, + ref->server->name(), ref->server_weight * 100, ref->server->stats.n_current, ref->connections, @@ -368,7 +368,7 @@ void RWSplit::diagnostics(DCB* dcb) dcb_printf(dcb, " %10s %10ld %10ld %10ld %9s %10.02f%% %10ld\n", - s.first->name, + s.first->name(), cs.total_queries, cs.total_read_queries, cs.total_write_queries, @@ -409,7 +409,7 @@ json_t* RWSplit::diagnostics_json() const ServerStats::CurrentStats stats = a.second.current_stats(); json_t* obj = json_object(); - json_object_set_new(obj, "id", json_string(a.first->name)); + json_object_set_new(obj, "id", json_string(a.first->name())); json_object_set_new(obj, "total", json_integer(stats.total_queries)); json_object_set_new(obj, "read", json_integer(stats.total_read_queries)); json_object_set_new(obj, "write", json_integer(stats.total_write_queries)); diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index b36386790..b02066eb6 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -764,7 +764,7 @@ void check_and_log_backend_state(const RWBackend* backend, DCB* problem_dcb) else { const char* remote = problem_dcb->state == DCB_STATE_POLLING - && problem_dcb->server ? problem_dcb->server->name : "CLOSED"; + && problem_dcb->server ? problem_dcb->server->name() : "CLOSED"; MXS_ERROR("DCB connected to '%s' is not in use by the router " "session, not closing it. DCB is in state '%s'", diff --git a/server/modules/routing/schemarouter/schemaroutersession.cc b/server/modules/routing/schemarouter/schemaroutersession.cc index 6bd674978..fc6749e97 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.cc +++ b/server/modules/routing/schemarouter/schemaroutersession.cc @@ -393,7 +393,7 @@ int32_t SchemaRouterSession::routeQuery(GWBUF* pPacket) { MXS_INFO("INIT_DB for database '%s' on server '%s'", m_current_db.c_str(), - target->name); + target->name()); route_target = TARGET_NAMED_SERVER; } else @@ -429,7 +429,7 @@ int32_t SchemaRouterSession::routeQuery(GWBUF* pPacket) DCB* target_dcb = NULL; if (TARGET_IS_NAMED_SERVER(route_target) && target - && get_shard_dcb(&target_dcb, target->name)) + && get_shard_dcb(&target_dcb, target->name())) { /** We know where to route this query */ SSRBackend bref = get_bref_from_dcb(target_dcb); @@ -530,7 +530,7 @@ void SchemaRouterSession::process_sescmd_response(SSRBackend& bref, GWBUF** ppPa mxs_mysql_extract_ps_response(*ppPacket, &resp); MXS_INFO("ID: %lu HANDLE: %lu", (unsigned long)id, (unsigned long)resp.id); m_shard.add_ps_handle(id, resp.id); - MXS_INFO("STMT SERVER: %s", bref->backend()->server->name); + MXS_INFO("STMT SERVER: %s", bref->backend()->server->name()); m_shard.add_statement(id, bref->backend()->server); uint8_t* ptr = GWBUF_DATA(*ppPacket) + MYSQL_PS_ID_OFFSET; gw_mysql_set_byte4(ptr, id); @@ -894,7 +894,7 @@ bool SchemaRouterSession::send_shards() for (const auto& a : pContent) { - set->add_row({a.first, a.second->name}); + set->add_row({a.first, a.second->name()}); } set->write(m_client); @@ -953,19 +953,19 @@ bool SchemaRouterSession::handle_default_db() SSRBackend backend; DCB* dcb = NULL; - if (get_shard_dcb(&dcb, target->name) + if (get_shard_dcb(&dcb, target->name()) && (backend = get_bref_from_dcb(dcb))) { backend->write(buffer); MXS_DEBUG("USE '%s' sent to %s for session %p", m_connect_db.c_str(), - target->name, + target->name(), m_client->session); rval = true; } else { - MXS_INFO("Couldn't find target DCB for '%s'.", target->name); + MXS_INFO("Couldn't find target DCB for '%s'.", target->name()); } } else @@ -1031,7 +1031,7 @@ int SchemaRouterSession::inspect_mapping_states(SSRBackend& bref, { (*it)->set_mapped(true); MXS_DEBUG("Received SHOW DATABASES reply from %s for session %p", - (*it)->backend()->server->name, + (*it)->backend()->server->name(), m_client->session); } else @@ -1086,7 +1086,7 @@ int SchemaRouterSession::inspect_mapping_states(SSRBackend& bref, { mapped = false; MXS_DEBUG("Still waiting for reply to SHOW DATABASES from %s for session %p", - (*it)->backend()->server->name, + (*it)->backend()->server->name(), m_client->session); } } @@ -1126,7 +1126,7 @@ bool change_current_db(std::string& dest, Shard& shard, GWBUF* buf) if (target) { dest = db; - MXS_INFO("change_current_db: database is on server: '%s'.", target->name); + MXS_INFO("change_current_db: database is on server: '%s'.", target->name()); succp = true; } } @@ -1306,7 +1306,7 @@ enum showdb_response SchemaRouterSession::parse_mapping_response(SSRBackend& bre { if (m_shard.add_location(data, target)) { - MXS_INFO("<%s, %s>", target->name, data); + MXS_INFO("<%s, %s>", target->name(), data); } else { @@ -1317,8 +1317,8 @@ enum showdb_response SchemaRouterSession::parse_mapping_response(SSRBackend& bre MXS_ERROR("Table '%s' found on servers '%s' and '%s' for user %s@%s.", data, - target->name, - duplicate->name, + target->name(), + duplicate->name(), m_client->user, m_client->remote); } @@ -1327,8 +1327,8 @@ enum showdb_response SchemaRouterSession::parse_mapping_response(SSRBackend& bre /** In conflict situations, use the preferred server */ MXS_INFO("Forcing location of '%s' from '%s' to '%s'", data, - m_shard.get_location(data)->name, - target->name); + m_shard.get_location(data)->name(), + target->name()); m_shard.replace_location(data, target); } } @@ -1341,12 +1341,12 @@ enum showdb_response SchemaRouterSession::parse_mapping_response(SSRBackend& bre { n_eof++; MXS_INFO("SHOW DATABASES fully received from %s.", - bref->backend()->server->name); + bref->backend()->server->name()); } else { MXS_INFO("SHOW DATABASES partially received from %s.", - bref->backend()->server->name); + bref->backend()->server->name()); } gwbuf_free(buf); @@ -1402,7 +1402,7 @@ void SchemaRouterSession::query_databases() if (!(*it)->write(clone)) { MXS_ERROR("Failed to write mapping query to '%s'", - (*it)->backend()->server->name); + (*it)->backend()->server->name()); } } } @@ -1441,12 +1441,12 @@ SERVER* SchemaRouterSession::get_shard_target(GWBUF* buffer, uint32_t qtype) { for (SSRBackendList::iterator it = m_backends.begin(); it != m_backends.end(); it++) { - char* srvnm = (*it)->backend()->server->name; + const char* srvnm = (*it)->backend()->server->name(); if (strcmp(srvnm, (char*)buffer->hint->data) == 0) { rval = (*it)->backend()->server; - MXS_INFO("Routing hint found (%s)", rval->name); + MXS_INFO("Routing hint found (%s)", rval->name()); } } } @@ -1463,7 +1463,7 @@ SERVER* SchemaRouterSession::get_shard_target(GWBUF* buffer, uint32_t qtype) { MXS_INFO("Using active database '%s' on '%s'", m_current_db.c_str(), - rval->name); + rval->name()); } } return rval; @@ -1482,7 +1482,7 @@ SERVER* SchemaRouterSession::get_shard_target(GWBUF* buffer, uint32_t qtype) * * @return True if proper DCB was found, false otherwise. */ -bool SchemaRouterSession::get_shard_dcb(DCB** p_dcb, char* name) +bool SchemaRouterSession::get_shard_dcb(DCB** p_dcb, const char* name) { bool succp = false; mxb_assert(p_dcb != NULL && *(p_dcb) == NULL); @@ -1496,7 +1496,7 @@ bool SchemaRouterSession::get_shard_dcb(DCB** p_dcb, char* name) * the backend state must be RUNNING */ if ((*it)->in_use() - && (strncasecmp(name, b->server->name, PATH_MAX) == 0) + && (strncasecmp(name, b->server->name(), PATH_MAX) == 0) && server_is_usable(b->server)) { *p_dcb = (*it)->dcb(); @@ -1706,15 +1706,15 @@ SERVER* SchemaRouterSession::get_query_target(GWBUF* buffer) { MXS_ERROR("Query targets tables on servers '%s' and '%s'. " "Cross server queries are not supported.", - rval->name, - target->name); + rval->name(), + target->name()); } else if (rval == NULL) { rval = target; MXS_INFO("Query targets table '%s' on server '%s'", tables[j], - rval->name); + rval->name()); } } } @@ -1754,8 +1754,8 @@ SERVER* SchemaRouterSession::get_ps_target(GWBUF* buffer, uint32_t qtype, qc_que { MXS_ERROR("Statement targets tables on servers '%s' and '%s'. " "Cross server queries are not supported.", - rval->name, - target->name); + rval->name(), + target->name()); } else if (rval == NULL) { @@ -1767,7 +1767,7 @@ SERVER* SchemaRouterSession::get_ps_target(GWBUF* buffer, uint32_t qtype, qc_que if (rval) { - MXS_INFO("PREPARING NAMED %s ON SERVER %s", stmt, rval->name); + MXS_INFO("PREPARING NAMED %s ON SERVER %s", stmt, rval->name()); m_shard.add_statement(stmt, rval); } MXS_FREE(tables); @@ -1777,7 +1777,7 @@ SERVER* SchemaRouterSession::get_ps_target(GWBUF* buffer, uint32_t qtype, qc_que { char* stmt = qc_get_prepare_name(buffer); rval = m_shard.get_statement(stmt); - MXS_INFO("Executing named statement %s on server %s", stmt, rval->name); + MXS_INFO("Executing named statement %s on server %s", stmt, rval->name()); MXS_FREE(stmt); } else if (qc_query_is_type(qtype, QUERY_TYPE_DEALLOC_PREPARE)) @@ -1786,7 +1786,7 @@ SERVER* SchemaRouterSession::get_ps_target(GWBUF* buffer, uint32_t qtype, qc_que if ((rval = m_shard.get_statement(stmt))) { - MXS_INFO("Closing named statement %s on server %s", stmt, rval->name); + MXS_INFO("Closing named statement %s on server %s", stmt, rval->name()); m_shard.remove_statement(stmt); } MXS_FREE(stmt); @@ -1801,7 +1801,7 @@ SERVER* SchemaRouterSession::get_ps_target(GWBUF* buffer, uint32_t qtype, qc_que rval = m_shard.get_location(tables[0]); MXS_FREE(tables[i]); } - rval ? MXS_INFO("Prepare statement on server %s", rval->name) : + rval ? MXS_INFO("Prepare statement on server %s", rval->name()) : MXS_INFO("Prepared statement targets no mapped tables"); MXS_FREE(tables); } diff --git a/server/modules/routing/schemarouter/schemaroutersession.hh b/server/modules/routing/schemarouter/schemaroutersession.hh index 88a783266..f1540d91e 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.hh +++ b/server/modules/routing/schemarouter/schemaroutersession.hh @@ -126,7 +126,7 @@ private: /** Helper functions */ SERVER* get_shard_target(GWBUF* buffer, uint32_t qtype); SSRBackend get_bref_from_dcb(DCB* dcb); - bool get_shard_dcb(DCB** dcb, char* name); + bool get_shard_dcb(DCB** dcb, const char* name); bool have_servers(); bool handle_default_db(); bool ignore_duplicate_database(const char* data); diff --git a/server/modules/routing/schemarouter/shard_map.cc b/server/modules/routing/schemarouter/shard_map.cc index 8c4f12f43..cdc92424c 100644 --- a/server/modules/routing/schemarouter/shard_map.cc +++ b/server/modules/routing/schemarouter/shard_map.cc @@ -38,7 +38,7 @@ void Shard::add_statement(std::string stmt, SERVER* target) void Shard::add_statement(uint32_t id, SERVER* target) { - MXS_DEBUG("ADDING ID: [%u] server: [%s]", id, target->name); + MXS_DEBUG("ADDING ID: [%u] server: [%s]", id, target->name()); m_binary_map[id] = target; } @@ -82,11 +82,11 @@ SERVER* Shard::get_location(std::string table) { if ((rval && rval != it->second)) { - MXS_DEBUG("There are 2 databases with same name on a different servers: '%s' and '%s'. Connecting to '%s'" - , - rval->name, - it->second->name, - rval->name); + MXS_DEBUG("There are 2 databases with same name on a different servers: '%s' and '%s'. " + "Connecting to '%s'", + rval->name(), + it->second->name(), + rval->name()); break; } else