odyssey/sources/grac_shutdown_worker.c

87 lines
2.0 KiB
C
Raw Normal View History

2020-11-03 08:12:06 +00:00
/*
* Odyssey.
*
* Scalable PostgreSQL connection pooler.
*/
#include <kiwi.h>
#include <machinarium.h>
#include <odyssey.h>
2020-07-26 07:58:15 +00:00
static inline int od_system_server_complete_stop(od_system_server_t *server)
2020-07-26 07:58:15 +00:00
{
/* shutdown */
int rc;
rc = machine_shutdown(server->io);
if (rc == -1)
return NOT_OK_RESPONSE;
return OK_RESPONSE;
}
void od_grac_shutdown_worker(void *arg)
2020-07-26 07:58:15 +00:00
{
od_system_t *system = arg;
2020-07-26 07:58:15 +00:00
od_instance_t *instance = system->global->instance;
od_log(&instance->logger, "config", NULL, NULL,
2020-07-26 07:58:15 +00:00
"stop to accepting new connections");
od_setproctitlef(
&instance->orig_argv_ptr,
"odyssey: version %s stop accepting any connections and "
"working with old transactions",
OD_VERSION_NUMBER);
2020-07-26 07:58:15 +00:00
od_router_t *router = system->global->router;
od_list_t *i;
od_list_foreach(&router->servers, i)
{
od_system_server_t *server;
server = od_container_of(i, od_system_server_t, link);
2020-07-26 07:58:15 +00:00
server->closed = true;
}
od_dbg_printf_on_dvl_lvl(1, "servers closed, errors: %d\n", 0);
2020-07-26 07:58:15 +00:00
/* wait for all servers to complete old transations */
od_list_foreach(&router->servers, i)
{
#if OD_DEVEL_LVL != OD_RELEASE_MODE
2020-07-26 07:58:15 +00:00
od_system_server_t *server;
server = od_container_of(i, od_system_server_t, link);
#else
od_attribute_unused() od_system_server_t *server;
server = od_container_of(i, od_system_server_t, link);
#endif
2020-07-26 07:58:15 +00:00
2020-08-08 16:00:31 +00:00
while (od_atomic_u32_of(&router->clients_routing) ||
od_atomic_u32_of(&router->clients)) {
od_dbg_printf_on_dvl_lvl(1, "waiting for %s\n",
server->sid.id);
2020-07-26 07:58:15 +00:00
machine_sleep(1000);
}
od_dbg_printf_on_dvl_lvl(1, "server shutdown ok %s\n",
server->sid.id);
2020-07-26 07:58:15 +00:00
}
od_dbg_printf_on_dvl_lvl(1, "shutting down sockets %s\n", "");
2020-07-26 07:58:15 +00:00
/* close sockets */
od_list_foreach(&router->servers, i)
{
od_system_server_t *server;
server = od_container_of(i, od_system_server_t, link);
od_system_server_complete_stop(server);
}
machine_stop(system->machine);
od_dbg_printf_on_dvl_lvl(
1, "waiting done, sending sigint to own process %d\n",
instance->pid.pid);
2020-07-26 07:58:15 +00:00
kill(instance->pid.pid, SIGTERM);
2020-07-26 07:58:15 +00:00
}