struct gridd_client_pool_s * gridd_client_pool_create(void) { int fdmon, fd[2]; struct gridd_client_pool_s *pool; if (0 != pipe(fd)) { GRID_WARN("pipe() error: (%d) %s", errno, strerror(errno)); metautils_pclose(&(fd[0])); metautils_pclose(&(fd[1])); return NULL; } if (0 > (fdmon = epoll_create(64))) { GRID_WARN("epoll_create error: (%d) %s", errno, strerror(errno)); metautils_pclose(&(fd[0])); metautils_pclose(&(fd[1])); return NULL; } // TODO FIXME factorize this in metautils struct rlimit limit; memset(&limit, 0, sizeof(limit)); if (0 != getrlimit(RLIMIT_NOFILE, &limit)) limit.rlim_cur = limit.rlim_max = 32768; pool = g_malloc0(sizeof(*pool)); pool->pending_clients = g_async_queue_new(); pool->fdmon = fdmon; pool->active_max = limit.rlim_cur; pool->active_clients_size = limit.rlim_cur; pool->active_clients = g_malloc0(pool->active_clients_size * sizeof(struct event_client_s*)); pool->fd_in = fd[0]; fd[0] = -1; metautils_syscall_shutdown(pool->fd_in, SHUT_WR); sock_set_non_blocking(pool->fd_in, TRUE); pool->fd_out = fd[1]; fd[1] = -1; metautils_syscall_shutdown(pool->fd_out, SHUT_RD); sock_set_non_blocking(pool->fd_out, TRUE); /* then monitors at least the notifications pipe's output */ struct epoll_event ev; memset(&ev, 0, sizeof(ev)); ev.events = EPOLLIN; ev.data.fd = pool->fd_in; if (0 > epoll_ctl(pool->fdmon, EPOLL_CTL_ADD, pool->fd_in, &ev)) { GRID_ERROR("epoll error: (%d) %s", errno, strerror(errno)); gridd_client_pool_destroy(pool); return NULL; } pool->vtable = &VTABLE; return pool; }
static void sqlx_service_specific_fini(void) { // soft stop if (SRV.gtq_reload) grid_task_queue_stop(SRV.gtq_reload); if (SRV.gtq_admin) grid_task_queue_stop(SRV.gtq_admin); if (SRV.server) { network_server_close_servers(SRV.server); network_server_stop(SRV.server); } if (SRV.thread_reload) g_thread_join(SRV.thread_reload); if (SRV.thread_admin) g_thread_join(SRV.thread_admin); if (SRV.thread_client) g_thread_join(SRV.thread_client); if (SRV.thread_queue) g_thread_join(SRV.thread_queue); if (SRV.repository) { sqlx_repository_stop(SRV.repository); struct sqlx_cache_s *cache = sqlx_repository_get_cache(SRV.repository); if (cache) sqlx_cache_expire(cache, G_MAXUINT, 0); } if (SRV.election_manager) election_manager_exit_all(SRV.election_manager, 0, TRUE); if (SRV.sync) sqlx_sync_close(SRV.sync); if (SRV.peering) sqlx_peering__destroy(SRV.peering); // Cleanup if (SRV.gtq_admin) { grid_task_queue_destroy(SRV.gtq_admin); SRV.gtq_admin = NULL; } if (SRV.gtq_reload) { grid_task_queue_destroy(SRV.gtq_reload); SRV.gtq_reload = NULL; } if (SRV.server) { network_server_clean(SRV.server); SRV.server = NULL; } if (SRV.dispatcher) { gridd_request_dispatcher_clean(SRV.dispatcher); SRV.dispatcher = NULL; } if (SRV.repository) { sqlx_repository_clean(SRV.repository); SRV.repository = NULL; } if (SRV.sync) { sqlx_sync_clear(SRV.sync); SRV.sync = NULL; } if (SRV.resolver) { hc_resolver_destroy(SRV.resolver); SRV.resolver = NULL; } if (SRV.announce) { g_string_free(SRV.announce, TRUE); SRV.announce = NULL; } if (SRV.url) { g_string_free(SRV.url, TRUE); SRV.url = NULL; } if (SRV.zk_url) oio_str_clean(&SRV.zk_url); if (SRV.clients_pool) { gridd_client_pool_destroy (SRV.clients_pool); SRV.clients_pool = NULL; } // Must be freed after SRV.clients_pool if (SRV.election_manager) { election_manager_clean(SRV.election_manager); SRV.election_manager = NULL; } if (SRV.lb) { grid_lbpool_destroy (SRV.lb); SRV.lb = NULL; } if (SRV.events_queue) { oio_events_queue__destroy (SRV.events_queue); SRV.events_queue = NULL; } if (SRV.nsinfo) { namespace_info_free(SRV.nsinfo); SRV.nsinfo = NULL; } if (all_options) { g_free (all_options); all_options = NULL; } }
static void sqlx_service_specific_fini(void) { // soft stop if (SRV.gtq_reload) grid_task_queue_stop(SRV.gtq_reload); if (SRV.gtq_register) grid_task_queue_stop(SRV.gtq_register); if (SRV.gtq_admin) grid_task_queue_stop(SRV.gtq_admin); if (SRV.server) { network_server_close_servers(SRV.server); network_server_stop(SRV.server); } if (SRV.thread_reload) g_thread_join(SRV.thread_reload); if (SRV.thread_register) g_thread_join(SRV.thread_register); if (SRV.thread_admin) g_thread_join(SRV.thread_admin); if (SRV.thread_client) g_thread_join(SRV.thread_client); if (SRV.thread_queue) g_thread_join(SRV.thread_queue); if (SRV.repository) { sqlx_repository_stop(SRV.repository); struct sqlx_cache_s *cache = sqlx_repository_get_cache(SRV.repository); if (cache) sqlx_cache_expire(cache, G_MAXUINT, 0); } if (SRV.election_manager) election_manager_exit_all(SRV.election_manager, 0, TRUE); if (SRV.sync) sqlx_sync_close(SRV.sync); // Cleanup if (SRV.gtq_admin) grid_task_queue_destroy(SRV.gtq_admin); if (SRV.gtq_reload) grid_task_queue_destroy(SRV.gtq_reload); if (SRV.gtq_register) grid_task_queue_destroy(SRV.gtq_register); if (SRV.server) network_server_clean(SRV.server); if (SRV.dispatcher) gridd_request_dispatcher_clean(SRV.dispatcher); if (SRV.repository) sqlx_repository_clean(SRV.repository); if (SRV.election_manager) election_manager_clean(SRV.election_manager); if (SRV.sync) sqlx_sync_clear(SRV.sync); if (SRV.resolver) hc_resolver_destroy(SRV.resolver); if (SRV.gsr_reqtime) grid_single_rrd_destroy(SRV.gsr_reqtime); if (SRV.gsr_reqcounter) grid_single_rrd_destroy(SRV.gsr_reqcounter); if (SRV.custom_tags) g_slist_free_full(SRV.custom_tags, g_free); if (SRV.si) service_info_clean(SRV.si); if (SRV.announce) g_string_free(SRV.announce, TRUE); if (SRV.url) g_string_free(SRV.url, TRUE); if (SRV.zk_url) oio_str_clean(&SRV.zk_url); if (SRV.clients_pool) gridd_client_pool_destroy (SRV.clients_pool); if (SRV.lb) grid_lbpool_destroy (SRV.lb); if (SRV.events_queue) oio_events_queue__destroy (SRV.events_queue); if (SRV.nsinfo) namespace_info_free(SRV.nsinfo); if (all_options) { g_free (all_options); all_options = NULL; } }