Skip to content

Commit

Permalink
refactor:revise for early checking of DB server's status when waiting…
Browse files Browse the repository at this point in the history
… for PL serverr
  • Loading branch information
hgryoo committed Dec 5, 2024
1 parent 76f5c98 commit 53455fe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
10 changes: 4 additions & 6 deletions src/executables/pl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ main (int argc, char *argv[])
if ((redirect = freopen (NULL_DEVICE, "w", stderr)) == NULL)
{
assert (false);
return ER_GENERIC_ERROR;
goto exit;
}

// check process is running
if (pl_info.pid == PL_PID_DISABLED || is_terminated_process (pl_info.pid) == true)
{
// NO_CONNECTION
fprintf (stdout, "NO_PROCESS");
goto exit;
}

Expand All @@ -227,6 +227,8 @@ main (int argc, char *argv[])
}
else
{
fprintf (stdout, "NO_CONNECTION");
status = NO_ERROR;
goto exit;
}

Expand Down Expand Up @@ -299,10 +301,6 @@ main (int argc, char *argv[])
{
fprintf (stdout, "ERROR");
}
else
{
fprintf (stdout, "NO_CONNECTION");
}

if (redirect)
{
Expand Down
70 changes: 44 additions & 26 deletions src/executables/util_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ typedef enum
{
PL_SERVER_RUNNING = 0,
PL_SERVER_STOPPED,
PL_SERVER_STATUS_ERROR
PL_SERVER_STATUS_ERROR,
PL_SERVER_STARTING
} UTIL_PL_SERVER_STATUS_E;

typedef struct
Expand Down Expand Up @@ -2802,11 +2803,16 @@ is_pl_running (const char *server_name)
pclose (input);
return PL_SERVER_RUNNING;
}
else if (strcmp (buf, "NO_CONNECTION") == 0)
else if (strcmp (buf, "NO_PROCESS") == 0)
{
pclose (input);
return PL_SERVER_STOPPED;
}
else if (strcmp (buf, "NO_CONNECTION") == 0)
{
pclose (input);
return PL_SERVER_STARTING;
}
else
{
pclose (input);
Expand Down Expand Up @@ -2854,19 +2860,27 @@ process_pl_restart (const char *db_name, bool suppress_message, bool process_win
sleep (1);
}

UTIL_PL_SERVER_STATUS_E pl_status;
do
{
// 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;
pl_status = is_pl_running (db_name);
status = (pl_status == PL_SERVER_RUNNING) ? NO_ERROR : ER_GENERIC_ERROR;
sleep (1); // wait to stop

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);
}
break;
}

waited_secs++;
}
while (status != NO_ERROR && waited_secs < wait_timeout);

if (waited_secs == wait_timeout)
{
status = ER_GENERIC_ERROR;
}
}

if (!suppress_message)
Expand All @@ -2886,35 +2900,39 @@ process_pl_status (const char *db_name)
int waited_secs = 0;
UTIL_PL_SERVER_STATUS_E pl_status;

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

do
{

pl_status = is_pl_running (db_name);
if (pl_status != PL_SERVER_RUNNING)
if (pl_status == PL_SERVER_RUNNING)
{
// retry
sleep (1);
waited_secs++;
const char *args[] = { UTIL_PL_NAME, COMMAND_TYPE_STATUS, db_name, NULL };
status = proc_execute (UTIL_PL_NAME, args, true, false, false, NULL);
if (status == NO_ERROR)
{
break;
}
}
else
{
status = ER_GENERIC_ERROR;
}
}
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 };
status = proc_execute (UTIL_PL_NAME, args, true, false, false, NULL);
// retry
sleep (1);
waited_secs++;
}
else
while (status != NO_ERROR && waited_secs < wait_timeout);

if (status != NO_ERROR)
{
status = ER_GENERIC_ERROR;
print_message (stdout, MSGCAT_UTIL_GENERIC_NOT_RUNNING_2S, PRINT_PL_NAME, db_name);
util_log_write_errid (MSGCAT_UTIL_GENERIC_NOT_RUNNING_2S, PRINT_PL_NAME, db_name);
}
Expand Down

0 comments on commit 53455fe

Please sign in to comment.