MXS-2220 server_alloc returns internal type

Also adds default initializers to SERVER fields.
This commit is contained in:
Esa Korhonen
2018-12-11 15:27:52 +02:00
parent 3f81a37e70
commit 6209d737e9
16 changed files with 135 additions and 154 deletions

View File

@ -63,6 +63,7 @@
#include "internal/filter.hh"
#include "internal/modules.hh"
#include "internal/monitor.hh"
#include "internal/server.hh"
#include "internal/service.hh"
using std::set;
@ -3717,7 +3718,7 @@ int create_new_server(CONFIG_CONTEXT* obj)
return 1;
}
if (SERVER* server = server_alloc(obj->object, obj->parameters))
if (Server* server = Server::server_alloc(obj->object, obj->parameters))
{
const char* disk_space_threshold = config_get_value(obj->parameters, CN_DISK_SPACE_THRESHOLD);
if (disk_space_threshold)

View File

@ -39,6 +39,7 @@
#include "internal/modules.hh"
#include "internal/monitor.hh"
#include "internal/query_classifier.hh"
#include "internal/server.hh"
typedef std::set<std::string> StringSet;
typedef std::vector<std::string> StringVector;
@ -241,7 +242,7 @@ bool runtime_create_server(const char* name,
config_replace_param(&ctx, "authenticator", authenticator);
}
SERVER* server = server_alloc(name, ctx.parameters);
Server* server = Server::server_alloc(name, ctx.parameters);
if (server && server_serialize(server))
{

View File

@ -32,11 +32,8 @@ class Server : public SERVER
{
public:
Server()
: m_response_time(maxbase::EMAverage {0.04, 0.35, 500})
{
}
~Server() override
: SERVER()
, m_response_time(maxbase::EMAverage {0.04, 0.35, 500})
{
}
@ -77,6 +74,20 @@ public:
*/
void print_to_dcb(DCB* dcb) const;
/**
* @brief Allocate a new server
*
* This will create a new server that represents a backend server that services
* can use. This function will add the server to the running configuration but
* will not persist the changes.
*
* @param name Unique server name
* @param params Parameters for the server
*
* @return The newly created server or NULL if an error occurred
*/
static Server* server_alloc(const char* name, MXS_CONFIG_PARAMETER* params);
/**
* @brief Find a server with the specified name
*

View File

@ -1133,9 +1133,8 @@ static void mon_append_node_names(MXS_MONITOR* mon,
MXS_MONITORED_SERVER* servers = mon->monitored_servers;
const char* separator = "";
char arr[MAX_SERVER_MONUSER_LEN
+ MAX_SERVER_MONPW_LEN
+ MAX_SERVER_ADDRESS_LEN + 64]; // Some extra space for port and separator
// Some extra space for port and separator
char arr[SERVER::MAX_MONUSER_LEN + SERVER::MAX_MONPW_LEN + SERVER::MAX_ADDRESS_LEN + 64];
dest[0] = '\0';
while (servers && len)

View File

@ -63,9 +63,6 @@ using maxscale::RoutingWorker;
using std::string;
using Guard = std::lock_guard<std::mutex>;
/** The latin1 charset */
#define SERVER_DEFAULT_CHARSET 0x08
const char CN_MONITORPW[] = "monitorpw";
const char CN_MONITORUSER[] = "monitoruser";
const char CN_PERSISTMAXTIME[] = "persistmaxtime";
@ -81,7 +78,7 @@ static const char WRN_REQUEST_OVERWRITTEN[] = "Previous maintenance request was
static void server_parameter_free(SERVER_PARAM* tofree);
SERVER* server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
{
const char* monuser = config_get_string(params, CN_MONITORUSER);
const char* monpw = config_get_string(params, CN_MONITORPW);
@ -156,32 +153,15 @@ SERVER* server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
server->extra_port = config_get_integer(params, CN_EXTRA_PORT);
server->protocol = my_protocol;
server->authenticator = my_authenticator;
server->monuser[0] = '\0';
server->monpw[0] = '\0';
server->persistpoolmax = config_get_integer(params, CN_PERSISTPOOLMAX);
server->persistmaxtime = config_get_integer(params, CN_PERSISTMAXTIME);
server->proxy_protocol = config_get_bool(params, CN_PROXY_PROTOCOL);
server->parameters = NULL;
server->is_active = true;
server->auth_instance = auth_instance;
server->server_ssl = ssl;
server->persistent = persistent;
server->charset = SERVER_DEFAULT_CHARSET;
memset(&server->stats, 0, sizeof(server->stats));
server->persistmax = 0;
server->last_event = SERVER_UP_EVENT;
server->triggered_at = 0;
server->status = SERVER_RUNNING;
server->maint_request = MAINTENANCE_NO_CHANGE;
memset(server->version_string, '\0', MAX_SERVER_VERSION_LEN);
server->version = 0;
server->server_type = SERVER_TYPE_MARIADB;
server->node_id = -1;
server->rlag = MXS_RLAG_UNDEFINED;
server->node_ts = 0;
server->master_id = -1;
server->master_err_is_logged = false;
server->warn_ssl_not_enabled = true;
if (*monuser && *monpw)
{
@ -1064,9 +1044,9 @@ void server_set_version_string(SERVER* server, const char* version_string)
// Strictly speaking, this is not fool-proof as writes may not appear in order to the reader.
size_t old_len = strlen(server->version_string);
size_t new_len = strlen(version_string);
if (new_len >= MAX_SERVER_VERSION_LEN)
if (new_len >= SERVER::MAX_VERSION_LEN)
{
new_len = MAX_SERVER_VERSION_LEN - 1;
new_len = SERVER::MAX_VERSION_LEN - 1;
}
if (new_len < old_len)

View File

@ -57,14 +57,13 @@ static mxs::ParamList params(
*/
static int test1()
{
SERVER* server;
int result;
std::string status;
using mxs::server_status;
/* Server tests */
fprintf(stderr, "testserver : creating server called MyServer");
server = server_alloc("uniquename", params.params());
Server* server = Server::server_alloc("uniquename", params.params());
mxb_assert_message(server, "Allocating the server should not fail");
char buf[120];
@ -122,7 +121,7 @@ bool test_load_config(const char* input, SERVER* server)
TEST(strcmp(server->authenticator, config_get_param(param, "authenticator")->value) == 0,
"Server authenticators differ");
TEST(server->port == atoi(config_get_param(param, "port")->value), "Server ports differ");
TEST(server_alloc(obj->object, obj->parameters), "Failed to create server from loaded config");
TEST(Server::server_alloc(obj->object, obj->parameters), "Failed to create server from loaded config");
duplicate_context_finish(&dcontext);
config_context_free(obj);
}
@ -138,7 +137,7 @@ bool test_serialize()
char old_config_name[] = "serialized-server.cnf.old";
char* persist_dir = MXS_STRDUP_A("./");
set_config_persistdir(persist_dir);
SERVER* server = server_alloc(name, params.params());
Server* server = Server::server_alloc(name, params.params());
TEST(server, "Server allocation failed");
/** Make sure the files don't exist */