Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25688][CBRD-25687] CUBRID 유틸리티를 통한 PL 서버 재시작 시 동작 및 에러 메시지 수정 #5667

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions src/executables/pl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ static int pl_stop_server (const PL_SERVER_INFO pl_info, const std::string &db_n
static int pl_status_server (const PL_SERVER_INFO pl_info, const std::string &db_name);

static void pl_dump_status (FILE *fp, PL_STATUS_INFO status_info);
static int pl_ping_server (const int server_port, const char *db_name, char *buf);
static bool pl_is_running (const int server_port, const std::string &db_name);
static int pl_ping_server (const PL_SERVER_INFO pl_info, const char *db_name, char *buf);
static bool pl_is_running (const PL_SERVER_INFO pl_info, const std::string &db_name);

static int pl_get_server_info (const std::string &db_name, PL_SERVER_INFO &info);
static int pl_check_argument (int argc, char *argv[], std::string &command, std::string &db_name);
Expand Down Expand Up @@ -208,14 +208,13 @@ main (int argc, char *argv[])
if (pl_info.pid == PL_PID_DISABLED || is_terminated_process (pl_info.pid) == true)
{
// NO_CONNECTION
pl_reset_info (db_name.c_str ());
goto exit;
}

char buffer[PL_PING_LEN] = {0};
if (status == NO_ERROR)
{
status = pl_ping_server (pl_info.port, db_name.c_str (), buffer);
status = pl_ping_server (pl_info, db_name.c_str (), buffer);
}

if (status == NO_ERROR)
Expand Down Expand Up @@ -257,27 +256,27 @@ main (int argc, char *argv[])
{
command = "running";
pl_read_info (db_name.c_str(), running_info);
#if defined (WINDOWS)
DWORD parent_ppid = GetCurrentProcessId();
HANDLE hParent = OpenProcess (SYNCHRONIZE, FALSE, parent_ppid);
DWORD result = WaitForSingleObject (hParent, INFINITE);
CloseHandle (hParent);
if (result == WAIT_OBJECT_0)
{
ExitProcess (0);
}
#else
do
{
#if defined (WINDOWS)
DWORD parent_ppid = GetCurrentProcessId();
HANDLE hParent = OpenProcess (SYNCHRONIZE, FALSE, parent_ppid);
DWORD result = WaitForSingleObject (hParent, INFINITE);
CloseHandle (hParent);
if (result == WAIT_OBJECT_0)
{
ExitProcess (0);
}
#else
if (getppid () == 1)
{
// parent process is terminated
break;
}
#endif
sleep (1);
}
while (true);
#endif
}
}
else if (command.compare ("stop") == 0)
Expand Down Expand Up @@ -413,7 +412,7 @@ pl_start_server (const PL_SERVER_INFO pl_info, const std::string &db_name, const
{
int status = NO_ERROR;

if (pl_info.pid != PL_PID_DISABLED && pl_is_running (pl_info.port, db_name))
if (pl_info.pid != PL_PID_DISABLED && pl_is_running (pl_info, db_name))
{
status = ER_GENERIC_ERROR;
}
Expand Down Expand Up @@ -452,22 +451,24 @@ pl_start_server (const PL_SERVER_INFO pl_info, const std::string &db_name, const
static int
pl_stop_server (const PL_SERVER_INFO pl_info, const std::string &db_name)
{
int status = NO_ERROR;
#define MAX_RETRY_COUNT 10
int status = ER_FAILED;
int retry_count = 0;

cubpl::connection_pool connection_pool (1, db_name, pl_info.port);
cubpl::connection_view cv = connection_pool.claim ();
if (cv->is_valid())
if (pl_info.pid != -1 && !is_terminated_process (pl_info.pid))
{
cubmethod::header header (DB_EMPTY_SESSION, SP_CODE_UTIL_TERMINATE_SERVER, 0);
cv->send_buffer_args (header);
pl_reset_info (db_name.c_str ());
terminate_process (pl_info.pid);

if (pl_info.pid != -1 && !is_terminated_process (pl_info.pid))
while (retry_count < MAX_RETRY_COUNT)
{
terminate_process (pl_info.pid);
if (kill (pl_info.pid, 0) == -1)
{
status = NO_ERROR;
break;
}
usleep (10);
retry_count++;
}

pl_reset_info (db_name.c_str ());
}

return status;
Expand All @@ -479,7 +480,7 @@ pl_status_server (const PL_SERVER_INFO pl_info, const std::string &db_name)
int status = NO_ERROR;
cubmem::block buffer;

cubpl::connection_pool connection_pool (1, db_name, pl_info.port);
cubpl::connection_pool connection_pool (1, db_name, pl_info.port, true);
cubpl::connection_view cv = connection_pool.claim ();
if (cv->is_valid())
{
Expand Down Expand Up @@ -529,12 +530,12 @@ pl_status_server (const PL_SERVER_INFO pl_info, const std::string &db_name)
}

static int
pl_ping_server (const int server_port, const char *db_name, char *buf)
pl_ping_server (const PL_SERVER_INFO pl_info, const char *db_name, char *buf)
{
int status = NO_ERROR;
cubmem::block ping_blk {0, NULL};

cubpl::connection_pool connection_pool (1, db_name, server_port);
cubpl::connection_pool connection_pool (1, db_name, pl_info.port, true);
cubpl::connection_view cv = connection_pool.claim ();

if (cv->is_valid())
Expand Down Expand Up @@ -589,12 +590,12 @@ pl_dump_status (FILE *fp, PL_STATUS_INFO status_info)
}

static bool
pl_is_running (const int server_port, const std::string &db_name)
pl_is_running (const PL_SERVER_INFO pl_info, const std::string &db_name)
{
// check server running
bool result = false;
char buffer[PL_PING_LEN] = {0};
if (pl_ping_server (server_port, db_name.c_str (), buffer) == NO_ERROR)
if (pl_ping_server (pl_info, db_name.c_str (), buffer) == NO_ERROR)
{
if (db_name.compare (0, db_name.size (), buffer) == 0)
{
Expand Down
65 changes: 37 additions & 28 deletions src/executables/util_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static int process_gateway (int command_type, int argc, const char **argv, bool
static int process_manager (int command_type, bool process_window_service);
static int process_pl (int command_type, int argc, const char **argv, bool show_usage, bool suppress_message,
bool process_window_service, bool ha_mode);
static int process_pl_stop (const char *db_name, bool suppress_message, bool process_window_service);
static int process_pl_restart (const char *db_name, bool suppress_message, bool process_window_service);
static int process_pl_status (const char *db_name, bool suppress_message);
static int process_heartbeat (int command_type, int argc, const char **argv);
static int process_heartbeat_start (HA_CONF * ha_conf, int argc, const char **argv);
Expand Down Expand Up @@ -1364,8 +1364,6 @@ process_service (int command_type, bool process_window_service)
{
if (!are_all_services_stopped (0, process_window_service))
{
(void) process_pl (command_type, 0, NULL, false, true, process_window_service, false);

if (strcmp (get_property (SERVICE_START_SERVER), PROPERTY_ON) == 0
&& us_Property_map[SERVER_START_LIST].property_value != NULL
&& us_Property_map[SERVER_START_LIST].property_value[0] != '\0')
Expand Down Expand Up @@ -2822,15 +2820,24 @@ static int
process_pl_restart (const char *db_name, bool suppress_message, bool process_window_service)
{
int status = NO_ERROR;
static const int wait_timeout = 5;
static const int wait_timeout = 10;
int waited_secs = 0;

if (!suppress_message)
{
print_message (stdout, MSGCAT_UTIL_GENERIC_START_STOP_3S, PRINT_PL_NAME, PRINT_CMD_RESTART, db_name);
}
UTIL_PL_SERVER_STATUS_E pl_status = is_pl_running (db_name);
if (pl_status == PL_SERVER_RUNNING)

if (!is_server_running (CHECK_SERVER, db_name, 0))
{
status = ER_GENERIC_ERROR;
if (!suppress_message)
{
print_message (stdout, MSGCAT_UTIL_GENERIC_NOT_RUNNING_2S, PRINT_SERVER_NAME, db_name);
}
}

if (status == NO_ERROR)
{
if (process_window_service)
{
Expand All @@ -2846,32 +2853,25 @@ process_pl_restart (const char *db_name, bool suppress_message, bool process_win
{
const char *args[] = { UTIL_PL_NAME, COMMAND_TYPE_STOP, db_name, NULL };
status = proc_execute (UTIL_PL_NAME, args, true, false, false, NULL);
sleep (1);
do
{
status = (is_pl_running (db_name) == PL_SERVER_RUNNING) ? ER_GENERIC_ERROR : NO_ERROR;
/* The pl server needs a few seconds to accept ping request */
status = (is_pl_running (db_name) == PL_SERVER_RUNNING) ? NO_ERROR : ER_GENERIC_ERROR;
sleep (1); /* wait to stop */
waited_secs++;
}
while (status != NO_ERROR && waited_secs < wait_timeout);
}
}
else
{
status = ER_GENERIC_ERROR;
util_log_write_errid (MSGCAT_UTIL_GENERIC_NOT_RUNNING_2S, PRINT_PL_NAME, db_name);
}

if (!suppress_message)
{
if (status == ER_GENERIC_ERROR)
if (waited_secs == wait_timeout)
{
print_message (stdout, MSGCAT_UTIL_GENERIC_NOT_RUNNING_2S, PRINT_PL_NAME, db_name);
}
else
{
print_message (stdout, MSGCAT_UTIL_GENERIC_ALREADY_RUNNING_2S, PRINT_PL_NAME, db_name);
status = ER_GENERIC_ERROR;
}
}

if (!suppress_message)
{
print_result (PRINT_PL_NAME, status, RESTART);
}

Expand All @@ -2882,7 +2882,22 @@ static int
process_pl_status (const char *db_name)
{
int status = NO_ERROR;
UTIL_PL_SERVER_STATUS_E pl_status = is_pl_running (db_name);

static const int wait_timeout = 10;
int waited_secs = 0;
UTIL_PL_SERVER_STATUS_E pl_status;
do
{
pl_status = is_pl_running (db_name);
if (pl_status != PL_SERVER_RUNNING)
{
// retry
sleep (1);
waited_secs++;
}
}
while (pl_status != PL_SERVER_RUNNING && waited_secs < wait_timeout);

if (pl_status == PL_SERVER_RUNNING)
{
const char *args[] = { UTIL_PL_NAME, COMMAND_TYPE_STATUS, db_name, NULL };
Expand Down Expand Up @@ -3899,9 +3914,6 @@ us_hb_deactivate (const char *hostname, bool immediate_stop)
args[opt_idx++] = COMMDB_HB_DEACT_IMMEDIATELY;
}

/* stop pl server */
(void) process_pl (STOP, 0, NULL, false, true, false, true);

/* stop all HA processes including cub_server */
args[opt_idx] = COMMDB_HA_DEACT_STOP_ALL;
status = proc_execute (UTIL_COMMDB_NAME, args, true, false, false, NULL);
Expand Down Expand Up @@ -3950,9 +3962,6 @@ us_hb_process_stop (HA_CONF * ha_conf, const char *db_name)

print_message (stdout, MSGCAT_UTIL_GENERIC_START_STOP_2S, PRINT_HA_PROCS_NAME, PRINT_CMD_STOP);

/* stop pl server */
(void) process_pl (STOP, 1, (const char **) &db_name, false, true, false, true);

status = us_hb_copylogdb_stop (ha_conf, db_name, NULL, NULL);
if (status != NO_ERROR)
{
Expand Down
Loading