Skip to content

Commit

Permalink
Assure that update_X give dedicated return codes for SIGTERM exit
Browse files Browse the repository at this point in the history
  • Loading branch information
drolbr committed May 18, 2023
1 parent 8eaac3d commit fbb7d91
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/overpass_api/osm-backend/update_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ int main(int argc, char* argv[])
catch (File_Error e)
{
report_file_error(e);
if (sigterm_status())
return SIGTERM;
return 2;
}

Expand Down
2 changes: 2 additions & 0 deletions src/overpass_api/osm-backend/update_from_dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ int main(int argc, char* argv[])
catch (const File_Error& e)
{
report_file_error(e);
if (sigterm_status())
return SIGTERM;
return -1;
}

Expand Down
13 changes: 8 additions & 5 deletions src/template_db/dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ void Dispatcher::standby_loop(uint64 milliseconds)

uint32 command = 0;
uint32 client_pid = 0;
if (sigterm_status())
if (sigterm_status() == Signal_Status::received)
command = TERMINATE;
else
connection_per_pid.poll_command_round_robin(command, client_pid);
Expand All @@ -695,10 +695,12 @@ void Dispatcher::standby_loop(uint64 milliseconds)
{
if (terminate_countdown < TERMINATE_COUNTDOWN_START)
{
if (logger)
logger->terminate_triggered(terminate_countdown, writing_process);
if (--terminate_countdown == 0 || writing_process == 0)
if (!terminate_countdown || !writing_process)
{
logger->terminate_triggered(terminate_countdown, writing_process);
break;
}
--terminate_countdown;

if (command == WRITE_ROLLBACK)
{
Expand All @@ -725,11 +727,12 @@ void Dispatcher::standby_loop(uint64 milliseconds)

if (command == TERMINATE)
{
--terminate_countdown;
if (logger)
logger->terminate_triggered(terminate_countdown, writing_process);
if (writing_process)
kill(writing_process, SIGTERM);
--terminate_countdown;
sigterm_status() = Signal_Status::processed;
}
}
else if (command == WRITE_START || command == WRITE_COMMIT
Expand Down
2 changes: 1 addition & 1 deletion src/template_db/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Dispatcher
static const int OFFSET_DB_1 = OFFSET_BACK+12;
static const int OFFSET_DB_2 = OFFSET_DB_1+(256+4);

static const int32 TERMINATE_COUNTDOWN_START = 100;
static const int32 TERMINATE_COUNTDOWN_START = 501;

static const uint32 TERMINATE = 1;
static const uint32 OUTPUT_STATUS = 2;
Expand Down
6 changes: 3 additions & 3 deletions src/template_db/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ int& global_read_counter()
}


bool& sigterm_status()
Signal_Status& sigterm_status()
{
static bool status = false;
static Signal_Status status = Signal_Status::absent;
return status;
}


void sigterm(int)
{
sigterm_status() = true;
sigterm_status() = Signal_Status::received;
}


Expand Down
3 changes: 2 additions & 1 deletion src/template_db/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ inline void zero_padding(uint8* from, uint32 bytes)

int& global_read_counter();

bool& sigterm_status();
enum Signal_Status { absent = 0, received, processed };
Signal_Status& sigterm_status();
void sigterm(int);


Expand Down

0 comments on commit fbb7d91

Please sign in to comment.