2020-11-03 08:12:06 +00:00
|
|
|
|
2020-11-27 18:03:42 +00:00
|
|
|
/*
|
|
|
|
* Odyssey.
|
|
|
|
*
|
|
|
|
* Scalable PostgreSQL connection pooler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kiwi.h>
|
|
|
|
#include <machinarium.h>
|
|
|
|
#include <odyssey.h>
|
2020-07-26 07:58:15 +00:00
|
|
|
|
2020-12-28 10:43:31 +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;
|
|
|
|
}
|
|
|
|
|
2020-12-28 10:43:31 +00:00
|
|
|
void od_grac_shutdown_worker(void *arg)
|
2020-07-26 07:58:15 +00:00
|
|
|
{
|
2020-12-28 10:43:31 +00:00
|
|
|
od_system_t *system = arg;
|
2020-07-26 07:58:15 +00:00
|
|
|
od_instance_t *instance = system->global->instance;
|
2020-12-28 10:43:31 +00:00
|
|
|
od_log(&instance->logger, "config", NULL, NULL,
|
2020-07-26 07:58:15 +00:00
|
|
|
"stop to accepting new connections");
|
|
|
|
|
2020-12-28 10:43:31 +00:00
|
|
|
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;
|
2020-12-28 10:43:31 +00:00
|
|
|
server = od_container_of(i, od_system_server_t, link);
|
2020-07-26 07:58:15 +00:00
|
|
|
server->closed = true;
|
|
|
|
}
|
|
|
|
|
2020-10-26 12:29:05 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-11-27 18:03:42 +00:00
|
|
|
#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);
|
2020-11-25 10:17:15 +00:00
|
|
|
#else
|
|
|
|
od_attribute_unused() od_system_server_t *server;
|
|
|
|
server = od_container_of(i, od_system_server_t, link);
|
2020-11-23 09:13:28 +00:00
|
|
|
#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)) {
|
2020-12-28 10:43:31 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-12-28 10:43:31 +00:00
|
|
|
od_dbg_printf_on_dvl_lvl(1, "server shutdown ok %s\n",
|
|
|
|
server->sid.id);
|
2020-07-26 07:58:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 12:29:05 +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(
|
2020-12-28 10:43:31 +00:00
|
|
|
1, "waiting done, sending sigint to own process %d\n",
|
|
|
|
instance->pid.pid);
|
2020-07-26 07:58:15 +00:00
|
|
|
|
2021-01-14 06:54:16 +00:00
|
|
|
kill(instance->pid.pid, SIGTERM);
|
2020-07-26 07:58:15 +00:00
|
|
|
}
|