Skip to content

Commit

Permalink
Change member name to last_revive_time
Browse files Browse the repository at this point in the history
  • Loading branch information
YeunjunLee committed Oct 14, 2024
1 parent f5fb7d9 commit 34481a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions src/executables/master_server_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ server_monitor::register_server_entry (int pid, const std::string &exec_path, co
{
entry->second.set_pid (pid);
entry->second.set_need_revive (false);
entry->second.set_registered_time (std::chrono::steady_clock::now ());
entry->second.set_last_revived_time (std::chrono::steady_clock::now ());
_er_log_debug (ARG_FILE_LINE,
"[Server Monitor] [%s] Server entry has been registered. (pid : %d)",
server_name.c_str(), pid);
Expand Down Expand Up @@ -158,7 +158,8 @@ server_monitor::revive_server (const std::string &server_name)

tv = std::chrono::steady_clock::now ();
auto timediff = std::chrono::duration_cast<std::chrono::seconds> (tv -
entry->second.get_registered_time()).count();
entry->second.get_last_revived_time()).count();
bool revived_before = entry->second.get_last_revived_time () != std::chrono::steady_clock::time_point ();

// If the server is abnormally terminated and revived within a short period of time, it is considered as a repeated failure.
// For HA server, heartbeat handle this case as demoting the server from master to slave and keep trying to revive the server.
Expand All @@ -169,10 +170,9 @@ server_monitor::revive_server (const std::string &server_name)
// TODO: Consider retry count for repeated failure case, and give up reviving the server after several retries.
// TODO: The timediff value continues to increase if REVIVE_SERVER handling is repeated. Thus, the if condition will always be
// true after the first evaluation. Therefore, evaluating the timediff only once when producing the REVIVE_SERVER job is needed.
// (Currently, it is impossible since registered_time is stored in server_entry, which is not synchronized structure between monitor and main thread.)
// (Currently, it is impossible since last_revived_time is stored in server_entry, which is not synchronized structure between monitor and main thread.)

if (entry->second.get_registered_time() == std::chrono::steady_clock::time_point ()
|| timediff > SERVER_MONITOR_UNACCEPTABLE_REVIVE_TIMEDIFF_IN_SECS)
if (!revived_before || timediff > SERVER_MONITOR_UNACCEPTABLE_REVIVE_TIMEDIFF_IN_SECS)
{
out_pid = try_revive_server (entry->second.get_exec_path(), entry->second.get_argv());
if (out_pid == -1)
Expand Down Expand Up @@ -366,7 +366,7 @@ server_entry (int pid, const std::string &exec_path, const std::string &args,
: m_pid {pid}
, m_exec_path {exec_path}
, m_need_revive {false}
, m_registered_time {revive_time}
, m_last_revived_time {revive_time}
{
if (args.size() > 0)
{
Expand Down Expand Up @@ -399,9 +399,9 @@ server_monitor::server_entry::get_need_revive () const
}

std::chrono::steady_clock::time_point
server_monitor::server_entry::get_registered_time () const
server_monitor::server_entry::get_last_revived_time () const
{
return m_registered_time;
return m_last_revived_time;
}

void
Expand All @@ -423,9 +423,9 @@ server_monitor::server_entry::set_need_revive (bool need_revive)
}

void
server_monitor::server_entry::set_registered_time (std::chrono::steady_clock::time_point revive_time)
server_monitor::server_entry::set_last_revived_time (std::chrono::steady_clock::time_point revive_time)
{
m_registered_time = revive_time;
m_last_revived_time = revive_time;
}

void
Expand Down
16 changes: 8 additions & 8 deletions src/executables/master_server_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class server_monitor
{
m_pid = other.m_pid;
m_need_revive = other.m_need_revive;
m_registered_time = other.m_registered_time;
m_last_revived_time = other.m_last_revived_time;
m_exec_path = other.m_exec_path;
m_argv = std::move (other.m_argv);
}
Expand All @@ -137,21 +137,21 @@ class server_monitor
std::string get_exec_path () const;
char *const *get_argv () const;
bool get_need_revive () const;
std::chrono::steady_clock::time_point get_registered_time () const;
std::chrono::steady_clock::time_point get_last_revived_time () const;

void set_pid (int pid);
void set_exec_path (const std::string &exec_path);
void set_need_revive (bool need_revive);
void set_registered_time (std::chrono::steady_clock::time_point revive_time);
void set_last_revived_time (std::chrono::steady_clock::time_point revive_time);

void proc_make_arg (const std::string &args);

private:
int m_pid; // process ID of server process
std::string m_exec_path; // executable path of server process
std::unique_ptr<char *[]> m_argv; // arguments of server process
volatile bool m_need_revive; // need to be revived by monitoring thread
std::chrono::steady_clock::time_point m_registered_time; // last revive time
int m_pid; // process ID of server process
std::string m_exec_path; // executable path of server process
std::unique_ptr<char *[]> m_argv; // arguments of server process
volatile bool m_need_revive; // need to be revived by monitoring thread
std::chrono::steady_clock::time_point m_last_revived_time; // last revived time
};

std::unordered_map <std::string, server_entry> m_server_entry_map; // map of server entries
Expand Down

0 comments on commit 34481a4

Please sign in to comment.