MXS-2546 Separate slave connection settings to its own class
The settings are different from the other fields in that they should not change on their own. Most manipulation functions only require the settings. Also takes into use a class for host and port data.
This commit is contained in:
@ -16,6 +16,7 @@
|
||||
#include <unordered_set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <maxbase/host.hh>
|
||||
#include <maxbase/stopwatch.hh>
|
||||
#include <maxscale/server.hh>
|
||||
|
||||
@ -168,10 +169,43 @@ private:
|
||||
std::vector<Gtid> m_triplets;
|
||||
};
|
||||
|
||||
// Helper class for host-port combinations
|
||||
class EndPoint
|
||||
{
|
||||
public:
|
||||
EndPoint(const std::string& host, int port);
|
||||
explicit EndPoint(const SERVER* server);
|
||||
EndPoint();
|
||||
|
||||
std::string host() const
|
||||
{
|
||||
return m_host.address();
|
||||
}
|
||||
|
||||
int port() const
|
||||
{
|
||||
return m_host.port();
|
||||
}
|
||||
|
||||
bool operator==(const EndPoint& rhs) const;
|
||||
bool operator!=(const EndPoint& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
mxb::Host m_host; /* Address and port */
|
||||
};
|
||||
|
||||
|
||||
// Contains data returned by one row of SHOW ALL SLAVES STATUS
|
||||
class SlaveStatus
|
||||
{
|
||||
public:
|
||||
explicit SlaveStatus(const std::string& owner);
|
||||
|
||||
enum slave_io_running_t
|
||||
{
|
||||
SLAVE_IO_YES,
|
||||
@ -179,16 +213,38 @@ public:
|
||||
SLAVE_IO_NO,
|
||||
};
|
||||
|
||||
std::string owning_server; /* Server name of the owner */
|
||||
bool seen_connected = false; /* Has this slave connection been seen connected,
|
||||
* meaning that the master server id is correct? */
|
||||
std::string name; /* Slave connection name. Must be unique for
|
||||
* the server.*/
|
||||
// Helper class for containing slave connection settings. These are modifiable by
|
||||
// a CHANGE MASTER TO-command and should not change on their own. The owning server
|
||||
// is included to simplify log message creation.
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
Settings(const std::string& name, const EndPoint& target, const std::string& owner);
|
||||
Settings(const std::string& name, const SERVER* target);
|
||||
explicit Settings(const std::string& owner);
|
||||
|
||||
/**
|
||||
* Create a short description in the form of "Slave connection from <owner> to <[host]:port>."
|
||||
*
|
||||
* @return Description
|
||||
*/
|
||||
std::string to_string() const;
|
||||
|
||||
std::string name; /* Slave connection name. Must be unique for the server. */
|
||||
EndPoint master_endpoint; /* Master server address & port */
|
||||
|
||||
private:
|
||||
std::string m_owner; /* Name of the owning server. Used for logging. */
|
||||
};
|
||||
|
||||
Settings settings; /* User-defined settings for the slave connection. */
|
||||
|
||||
bool seen_connected = false; /* Has this slave connection been seen connected,
|
||||
* meaning that the master server id is correct? */
|
||||
|
||||
int64_t master_server_id = SERVER_ID_UNKNOWN; /* The master's server_id value. Valid ids are
|
||||
* 32bit unsigned. -1 is unread/error. */
|
||||
std::string master_host; /* Master server host name. */
|
||||
int master_port = PORT_UNKNOWN; /* Master server port. */
|
||||
slave_io_running_t slave_io_running = SLAVE_IO_NO; /* Slave I/O thread running state: * "Yes",
|
||||
slave_io_running_t slave_io_running = SLAVE_IO_NO; /* Slave I/O thread running state: "Yes",
|
||||
* "Connecting" or "No" */
|
||||
bool slave_sql_running = false; /* Slave SQL thread running state, true if "Yes" */
|
||||
GtidList gtid_io_pos; /* Gtid I/O position of the slave thread. */
|
||||
@ -204,13 +260,6 @@ public:
|
||||
std::string to_string() const;
|
||||
json_t* to_json() const;
|
||||
|
||||
/**
|
||||
* Create a short description in the form of "Slave connection from <slave> to <master>"
|
||||
*
|
||||
* @return Description
|
||||
*/
|
||||
std::string to_short_string() const;
|
||||
|
||||
static slave_io_running_t slave_io_from_string(const std::string& str);
|
||||
static std::string slave_io_to_string(slave_io_running_t slave_io);
|
||||
bool should_be_copied(std::string* ignore_reason_out) const;
|
||||
|
Reference in New Issue
Block a user