Use maxbase time and clock classes instead of std::chrono

This commit is contained in:
Esa Korhonen 2018-09-26 16:49:33 +03:00
parent 05d18e81ae
commit fe81b399b2
5 changed files with 10 additions and 22 deletions

View File

@ -13,7 +13,6 @@
#include "mariadbmon.hh"
#include <chrono>
#include <inttypes.h>
#include <sstream>
#include <maxscale/clock.h>
@ -22,7 +21,6 @@
using std::string;
using std::unique_ptr;
using std::chrono::steady_clock;
using maxscale::string_printf;
static const char RE_ENABLE_FMT[] = "To re-enable automatic %s, manually set '%s' to 'true' "
@ -1537,7 +1535,7 @@ void MariaDBMonitor::handle_auto_failover()
int master_down_count = m_master->m_server_base->mon_err_count;
const MariaDBServer* connected_slave = NULL;
Duration event_age;
maxbase::Duration event_age;
if (m_failcount > 1 && m_warn_master_down)
{
@ -1553,9 +1551,7 @@ void MariaDBMonitor::handle_auto_failover()
{
MXS_NOTICE("Slave '%s' is still connected to '%s' and received a new gtid or heartbeat event %.1f "
"seconds ago. Delaying failover.",
connected_slave->name(),
m_master->name(),
event_age.count());
connected_slave->name(), m_master->name(), event_age.secs());
}
else if (master_down_count >= m_failcount)
{
@ -1682,10 +1678,10 @@ void MariaDBMonitor::check_cluster_operations_support()
* @return The first connected slave or NULL if none found
*/
const MariaDBServer* MariaDBMonitor::slave_receiving_events(const MariaDBServer* demotion_target,
Duration* event_age_out)
maxbase::Duration* event_age_out)
{
steady_clock::time_point alive_after = steady_clock::now()
- std::chrono::seconds(m_master_failure_timeout);
auto time_now = maxbase::Clock::now();
maxbase::Clock::time_point alive_after = time_now - std::chrono::seconds(m_master_failure_timeout);
const MariaDBServer* connected_slave = NULL;
for (MariaDBServer* slave : demotion_target->m_node.children)
@ -1699,7 +1695,7 @@ const MariaDBServer* MariaDBMonitor::slave_receiving_events(const MariaDBServer*
// The slave is still connected to the correct master and has received events. This means that
// while MaxScale can't connect to the master, it's probably still alive.
connected_slave = slave;
*event_age_out = steady_clock::now() - slave_conn->last_data_time;
*event_age_out = time_now - slave_conn->last_data_time;
break;
}
}

View File

@ -15,13 +15,13 @@
* @file A MariaDB replication cluster monitor
*/
#include "mariadbmon.hh"
#include <inttypes.h>
#include <sstream>
#include <maxbase/assert.h>
#include <maxscale/alloc.h>
#include <maxscale/dcb.h>
#include <maxscale/modulecmd.h>
#include <maxscale/mysql_utils.h>
#include <maxscale/routingworker.h>
#include <maxscale/secrets.h>

View File

@ -12,15 +12,13 @@
*/
#pragma once
#include "mariadbmon_common.hh"
#include <chrono>
#include <condition_variable>
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
#include <maxscale/monitor.hh>
#include <maxbase/stopwatch.hh>
#include "mariadbserver.hh"
extern const char* const CN_AUTO_FAILOVER;
@ -106,8 +104,6 @@ protected:
void process_state_changes();
private:
typedef std::chrono::duration<double> Duration;
struct CycleInfo
{
int cycle_id = NodeData::CYCLE_NONE;
@ -250,7 +246,7 @@ private:
std::unique_ptr<ClusterOperation> failover_prepare(Log log_mode, json_t** error_out);
bool failover_perform(ClusterOperation& operation);
const MariaDBServer* slave_receiving_events(const MariaDBServer* demotion_target,
Duration* event_age_out);
maxbase::Duration* event_age_out);
bool manual_failover(json_t** output);
void handle_auto_failover();

View File

@ -12,9 +12,7 @@
*/
#include "mariadbserver.hh"
#include "maxbase/stopwatch.hh"
#include <chrono>
#include <fstream>
#include <inttypes.h>
#include <iomanip>
@ -23,7 +21,6 @@
#include <maxscale/utils.hh>
using std::string;
using std::chrono::steady_clock;
using maxscale::string_printf;
using maxbase::Duration;
using maxbase::StopWatch;

View File

@ -12,7 +12,6 @@
*/
#pragma once
#include "mariadbmon_common.hh"
#include <chrono>
#include <functional>
#include <string>
#include <memory>
@ -56,7 +55,7 @@ public:
* */
/* Time of the latest gtid event or heartbeat the slave connection has received, timed by the monitor. */
std::chrono::steady_clock::time_point last_data_time = std::chrono::steady_clock::now();
maxbase::Clock::time_point last_data_time = maxbase::Clock::now();
std::string to_string() const;