Implementation of server routing generic functionality and for readconnrouter
This commit is contained in:
@ -230,6 +230,8 @@ int error_count = 0;
|
||||
config_get_value(obj->parameters, "passwd");
|
||||
char *enable_root_user =
|
||||
config_get_value(obj->parameters, "enable_root_user");
|
||||
char *weightby =
|
||||
config_get_value(obj->parameters, "weightby");
|
||||
|
||||
char *version_string = config_get_value(obj->parameters, "version_string");
|
||||
|
||||
@ -259,6 +261,8 @@ int error_count = 0;
|
||||
|
||||
if (enable_root_user)
|
||||
serviceEnableRootUser(obj->element, config_truth_value(enable_root_user));
|
||||
if (weightby)
|
||||
serviceWeightBy(obj->element, weightby);
|
||||
|
||||
if (!auth)
|
||||
auth = config_get_value(obj->parameters, "auth");
|
||||
@ -362,6 +366,30 @@ int error_count = 0;
|
||||
"defined but no corresponding password.",
|
||||
obj->object)));
|
||||
}
|
||||
if (obj->element)
|
||||
{
|
||||
CONFIG_PARAMETER *params = obj->parameters;
|
||||
while (params)
|
||||
{
|
||||
if (strcmp(params->name, "address")
|
||||
&& strcmp(params->name, "port")
|
||||
&& strcmp(params->name,
|
||||
"protocol")
|
||||
&& strcmp(params->name,
|
||||
"monitoruser")
|
||||
&& strcmp(params->name,
|
||||
"monitorpw")
|
||||
&& strcmp(params->name,
|
||||
"type")
|
||||
)
|
||||
{
|
||||
serverAddParameter(obj->element,
|
||||
params->name,
|
||||
params->value);
|
||||
}
|
||||
params = params->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(type, "filter"))
|
||||
{
|
||||
@ -1238,8 +1266,6 @@ int i;
|
||||
{
|
||||
if (!strcmp(type, "service"))
|
||||
param_set = service_params;
|
||||
else if (!strcmp(type, "server"))
|
||||
param_set = server_params;
|
||||
else if (!strcmp(type, "listener"))
|
||||
param_set = listener_params;
|
||||
else if (!strcmp(type, "monitor"))
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
* 20/05/14 Massimiliano Pinto Addition of server_string
|
||||
* 21/05/14 Massimiliano Pinto Addition of node_id
|
||||
* 28/05/14 Massimiliano Pinto Addition of rlagd and node_ts fields
|
||||
* 26/06/14 Mark Riddoch Addition of server parameters
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -76,6 +77,7 @@ SERVER *server;
|
||||
server->node_id = -1;
|
||||
server->rlag = -1;
|
||||
server->node_ts = 0;
|
||||
server->parameters = NULL;
|
||||
|
||||
spinlock_acquire(&server_spin);
|
||||
server->next = allServers;
|
||||
@ -274,7 +276,8 @@ char *stat;
|
||||
void
|
||||
dprintServer(DCB *dcb, SERVER *server)
|
||||
{
|
||||
char *stat;
|
||||
char *stat;
|
||||
SERVER_PARAM *param;
|
||||
|
||||
dcb_printf(dcb, "Server %p (%s)\n", server, server->unique_name);
|
||||
dcb_printf(dcb, "\tServer: %s\n", server->name);
|
||||
@ -294,6 +297,16 @@ char *stat;
|
||||
if (server->node_ts > 0) {
|
||||
dcb_printf(dcb, "\tLast Repl Heartbeat:\t%lu\n", server->node_ts);
|
||||
}
|
||||
if ((param = server->parameters) != NULL)
|
||||
{
|
||||
dcb_printf(dcb, "\tServer Parameters:\n");
|
||||
while (param)
|
||||
{
|
||||
dcb_printf(dcb, "\t\t%-20s %s\n", param->name,
|
||||
param->value);
|
||||
param = param->next;
|
||||
}
|
||||
}
|
||||
dcb_printf(dcb, "\tNumber of connections: %d\n", server->stats.n_connections);
|
||||
dcb_printf(dcb, "\tCurrent no. of conns: %d\n", server->stats.n_current);
|
||||
}
|
||||
@ -444,3 +457,59 @@ server_update(SERVER *server, char *protocol, char *user, char *passwd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a server parameter to a server.
|
||||
*
|
||||
* Server parameters may be used by routing to weight the load
|
||||
* balancing they apply to the server.
|
||||
*
|
||||
* @param server The server we are adding the parameter to
|
||||
* @param name The parameter name
|
||||
* @param value The parameter value
|
||||
*/
|
||||
void
|
||||
serverAddParameter(SERVER *server, char *name, char *value)
|
||||
{
|
||||
SERVER_PARAM *param;
|
||||
|
||||
if ((param = (SERVER_PARAM *)malloc(sizeof(SERVER_PARAM))) == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((param->name = strdup(name)) == NULL)
|
||||
{
|
||||
free(param);
|
||||
return;
|
||||
}
|
||||
if ((param->value = strdup(value)) == NULL)
|
||||
{
|
||||
free(param->value);
|
||||
free(param);
|
||||
return;
|
||||
}
|
||||
|
||||
param->next = server->parameters;
|
||||
server->parameters = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive a parameter value from a server
|
||||
*
|
||||
* @param server The server we are looking for a parameter of
|
||||
* @param name The name of the parameter we require
|
||||
* @return The parameter value or NULL if not found
|
||||
*/
|
||||
char *
|
||||
serverGetParameter(SERVER *server, char *name)
|
||||
{
|
||||
SERVER_PARAM *param = server->parameters;
|
||||
|
||||
while (param)
|
||||
{
|
||||
if (strcmp(param->name, name) == 0)
|
||||
return param->value;
|
||||
param = param->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -114,6 +114,7 @@ SERVICE *service;
|
||||
service->svc_config_version = 0;
|
||||
service->filters = NULL;
|
||||
service->n_filters = 0;
|
||||
service->weightby = 0;
|
||||
spinlock_init(&service->spin);
|
||||
spinlock_init(&service->users_table_spin);
|
||||
memset(&service->rate_limit, 0, sizeof(SERVICE_REFRESH_RATE));
|
||||
@ -818,6 +819,8 @@ int i;
|
||||
server->protocol);
|
||||
server = server->nextdb;
|
||||
}
|
||||
if (service->weightby)
|
||||
dcb_printf(dcb, "\tRouting weight parameter: %s\n", service->weightby);
|
||||
dcb_printf(dcb, "\tUsers data: %p\n", service->users);
|
||||
dcb_printf(dcb, "\tTotal connections: %d\n", service->stats.n_sessions);
|
||||
dcb_printf(dcb, "\tCurrently connected: %d\n", service->stats.n_current);
|
||||
@ -1097,8 +1100,38 @@ static void service_add_qualified_param(
|
||||
spinlock_release(&svc->spin);
|
||||
}
|
||||
|
||||
char* service_get_name(
|
||||
SERVICE* svc)
|
||||
/**
|
||||
* Return the name of the service
|
||||
*
|
||||
* @param svc The service
|
||||
*/
|
||||
char *
|
||||
service_get_name(SERVICE *svc)
|
||||
{
|
||||
return svc->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the weighting parameter for the service
|
||||
*
|
||||
* @param service The service pointer
|
||||
* @param weightby The parameter name to weight the routing by
|
||||
*/
|
||||
void
|
||||
serviceWeightBy(SERVICE *service, char *weightby)
|
||||
{
|
||||
if (service->weightby)
|
||||
free(service->weightby);
|
||||
service->weightby = strdup(weightby);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parameter the wervice shoudl use to weight connections
|
||||
* by
|
||||
* @param service The Service pointer
|
||||
*/
|
||||
char *
|
||||
serviceGetWeightingParameter(SERVICE *service)
|
||||
{
|
||||
return service->weightby;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user