Move server disk space threshold setting to private Server-class
The setting can be read and written simultaneously and is protected with a mutex. The public SERVER-class is now abstract.
This commit is contained in:
@ -103,8 +103,9 @@ static uint64_t server_encode_version(const SERVER_VERSION* server_version)
|
|||||||
* the name of a protocol module that is loaded to implement the protocol
|
* the name of a protocol module that is loaded to implement the protocol
|
||||||
* between the gateway and the server.
|
* between the gateway and the server.
|
||||||
*/
|
*/
|
||||||
struct SERVER
|
class SERVER
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
// Base settings
|
// Base settings
|
||||||
char* name; /**< Server config name */
|
char* name; /**< Server config name */
|
||||||
char address[MAX_SERVER_ADDRESS_LEN]; /**< Server hostname/IP-address */
|
char address[MAX_SERVER_ADDRESS_LEN]; /**< Server hostname/IP-address */
|
||||||
@ -151,7 +152,31 @@ struct SERVER
|
|||||||
* used
|
* used
|
||||||
* by rwsplit. TODO: Move to rwsplit */
|
* by rwsplit. TODO: Move to rwsplit */
|
||||||
bool warn_ssl_not_enabled;/**< SSL not used for an SSL enabled server */
|
bool warn_ssl_not_enabled;/**< SSL not used for an SSL enabled server */
|
||||||
MxsDiskSpaceThreshold* disk_space_threshold;/**< Disk space thresholds */
|
|
||||||
|
virtual ~SERVER()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if server has disk space threshold settings.
|
||||||
|
*
|
||||||
|
* @return True if limits exist
|
||||||
|
*/
|
||||||
|
virtual bool have_disk_space_limits() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a copy of disk space limit settings.
|
||||||
|
*
|
||||||
|
* @return A copy of settings
|
||||||
|
*/
|
||||||
|
virtual MxsDiskSpaceThreshold get_disk_space_limits() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set new disk space limits for the server.
|
||||||
|
*
|
||||||
|
* @param new_limits New limits
|
||||||
|
*/
|
||||||
|
virtual void set_disk_space_limits(const MxsDiskSpaceThreshold& new_limits) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +36,10 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Server() override
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int response_time_num_samples() const
|
int response_time_num_samples() const
|
||||||
{
|
{
|
||||||
return m_response_time.num_samples();
|
return m_response_time.num_samples();
|
||||||
@ -51,10 +55,35 @@ public:
|
|||||||
static void dprintServer(DCB*, const Server*);
|
static void dprintServer(DCB*, const Server*);
|
||||||
static void dprintPersistentDCBs(DCB*, const Server*);
|
static void dprintPersistentDCBs(DCB*, const Server*);
|
||||||
|
|
||||||
|
bool have_disk_space_limits() const override
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(m_settings.lock);
|
||||||
|
return !m_settings.disk_space_limits.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
MxsDiskSpaceThreshold get_disk_space_limits() const override
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(m_settings.lock);
|
||||||
|
return m_settings.disk_space_limits;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_disk_space_limits(const MxsDiskSpaceThreshold& new_limits) override
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(m_settings.lock);
|
||||||
|
m_settings.disk_space_limits = new_limits;
|
||||||
|
}
|
||||||
|
|
||||||
mutable std::mutex m_lock;
|
mutable std::mutex m_lock;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
maxbase::EMAverage m_response_time;
|
struct Settings
|
||||||
|
{
|
||||||
|
mutable std::mutex lock; /**< Protects array-like settings from concurrent access */
|
||||||
|
MxsDiskSpaceThreshold disk_space_limits; /**< Disk space thresholds */
|
||||||
|
};
|
||||||
|
|
||||||
|
maxbase::EMAverage m_response_time; /**< Response time calculations for this server */
|
||||||
|
Settings m_settings; /**< Server settings */
|
||||||
};
|
};
|
||||||
|
|
||||||
void server_free(Server* server);
|
void server_free(Server* server);
|
||||||
|
@ -2623,12 +2623,11 @@ bool MonitorInstance::should_update_disk_space_status(const MXS_MONITORED_SERVER
|
|||||||
{
|
{
|
||||||
bool should_check = false;
|
bool should_check = false;
|
||||||
|
|
||||||
if (m_monitor->disk_space_check_interval
|
if ((m_monitor->disk_space_check_interval > 0)
|
||||||
&& (m_monitor->disk_space_threshold || pMs->server->disk_space_threshold)
|
&& (pMs->disk_space_checked != -1) // -1 means disabled
|
||||||
&& (pMs->disk_space_checked != -1)) // -1 means disabled
|
&& (m_monitor->disk_space_threshold || pMs->server->have_disk_space_limits()))
|
||||||
{
|
{
|
||||||
int64_t now = get_time_ms();
|
int64_t now = get_time_ms();
|
||||||
|
|
||||||
if (now - pMs->disk_space_checked > m_monitor->disk_space_check_interval)
|
if (now - pMs->disk_space_checked > m_monitor->disk_space_check_interval)
|
||||||
{
|
{
|
||||||
should_check = true;
|
should_check = true;
|
||||||
@ -2674,21 +2673,21 @@ void MonitorInstance::update_disk_space_status(MXS_MONITORED_SERVER* pMs)
|
|||||||
|
|
||||||
if (rv == 0)
|
if (rv == 0)
|
||||||
{
|
{
|
||||||
|
// Server-specific setting takes precedence.
|
||||||
|
MxsDiskSpaceThreshold dst = pMs->server->get_disk_space_limits();
|
||||||
|
if (dst.empty())
|
||||||
|
{
|
||||||
|
dst = *m_monitor->disk_space_threshold;
|
||||||
|
}
|
||||||
|
|
||||||
bool disk_space_exhausted = false;
|
bool disk_space_exhausted = false;
|
||||||
|
|
||||||
MxsDiskSpaceThreshold* pDst =
|
|
||||||
pMs->server->disk_space_threshold ?
|
|
||||||
pMs->server->disk_space_threshold : m_monitor->disk_space_threshold;
|
|
||||||
mxb_assert(pDst);
|
|
||||||
|
|
||||||
int32_t star_max_percentage = -1;
|
int32_t star_max_percentage = -1;
|
||||||
|
|
||||||
std::set<std::string> checked_paths;
|
std::set<std::string> checked_paths;
|
||||||
|
|
||||||
for (auto i = pDst->begin(); i != pDst->end(); ++i)
|
for (const auto& dst_item : dst)
|
||||||
{
|
{
|
||||||
string path = i->first;
|
string path = dst_item.first;
|
||||||
int32_t max_percentage = i->second;
|
int32_t max_percentage = dst_item.second;
|
||||||
|
|
||||||
if (path == "*")
|
if (path == "*")
|
||||||
{
|
{
|
||||||
|
@ -182,7 +182,6 @@ SERVER* server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
|
|||||||
server->master_id = -1;
|
server->master_id = -1;
|
||||||
server->master_err_is_logged = false;
|
server->master_err_is_logged = false;
|
||||||
server->warn_ssl_not_enabled = true;
|
server->warn_ssl_not_enabled = true;
|
||||||
server->disk_space_threshold = NULL;
|
|
||||||
|
|
||||||
if (*monuser && *monpw)
|
if (*monuser && *monpw)
|
||||||
{
|
{
|
||||||
@ -236,7 +235,6 @@ void server_free(Server* server)
|
|||||||
MXS_FREE(server->persistent);
|
MXS_FREE(server->persistent);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete server->disk_space_threshold;
|
|
||||||
delete server;
|
delete server;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1513,29 +1511,12 @@ json_t* server_list_to_json(const char* host)
|
|||||||
|
|
||||||
bool server_set_disk_space_threshold(SERVER* server, const char* disk_space_threshold)
|
bool server_set_disk_space_threshold(SERVER* server, const char* disk_space_threshold)
|
||||||
{
|
{
|
||||||
bool rv = false;
|
|
||||||
|
|
||||||
MxsDiskSpaceThreshold dst;
|
MxsDiskSpaceThreshold dst;
|
||||||
|
bool rv = config_parse_disk_space_threshold(&dst, disk_space_threshold);
|
||||||
rv = config_parse_disk_space_threshold(&dst, disk_space_threshold);
|
|
||||||
|
|
||||||
if (rv)
|
if (rv)
|
||||||
{
|
{
|
||||||
if (!server->disk_space_threshold)
|
server->set_disk_space_limits(dst);
|
||||||
{
|
|
||||||
server->disk_space_threshold = new(std::nothrow) MxsDiskSpaceThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (server->disk_space_threshold)
|
|
||||||
{
|
|
||||||
server->disk_space_threshold->swap(dst);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rv = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <maxscale/config.hh>
|
#include <maxscale/config.hh>
|
||||||
#include <maxscale/mysql_utils.hh>
|
#include <maxscale/mysql_utils.hh>
|
||||||
|
#include "../internal/server.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -78,9 +79,7 @@ int test(bool success, const char* zHost, const char* zUser, const char* zPasswo
|
|||||||
MXS_CONFIG* config = config_get_global_options();
|
MXS_CONFIG* config = config_get_global_options();
|
||||||
config->local_address = const_cast<char*>(zAddress);
|
config->local_address = const_cast<char*>(zAddress);
|
||||||
|
|
||||||
SERVER server;
|
Server server;
|
||||||
memset(&server, 0, sizeof(server));
|
|
||||||
|
|
||||||
strcpy(server.address, zHost);
|
strcpy(server.address, zHost);
|
||||||
server.port = 3306;
|
server.port = 3306;
|
||||||
|
|
||||||
|
@ -15,12 +15,13 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <maxbase/log.hh>
|
#include <maxbase/log.hh>
|
||||||
#include <maxbase/maxbase.hh>
|
#include <maxbase/maxbase.hh>
|
||||||
#include <maxscale/alloc.h>
|
#include <maxscale/alloc.h>
|
||||||
#include <set>
|
#include "../../../../core/internal/server.hh"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
@ -155,7 +156,7 @@ void MariaDBMonitor::Test::init_servers(int count)
|
|||||||
|
|
||||||
for (int i = 1; i < count + 1; i++)
|
for (int i = 1; i < count + 1; i++)
|
||||||
{
|
{
|
||||||
SERVER* base_server = new SERVER; // Contents mostly undefined
|
auto base_server = new Server; // Contents mostly undefined
|
||||||
string server_name = create_servername(i);
|
string server_name = create_servername(i);
|
||||||
base_server->name = MXS_STRDUP(server_name.c_str());
|
base_server->name = MXS_STRDUP(server_name.c_str());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user