From: Marko Kreen Date: Tue, 8 Jan 2008 14:13:25 +0000 (+0000) Subject: less scary -R: move takever before fork X-Git-Tag: pgbouncer_1_2_rc2~79 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa4a7fd88ae0d28f7f3c7ab0d263ed56ec8722b2;p=pgbouncer less scary -R: move takever before fork --- diff --git a/src/janitor.c b/src/janitor.c index 06fd710..07b2d6e 100644 --- a/src/janitor.c +++ b/src/janitor.c @@ -240,10 +240,6 @@ void per_loop_maint(void) int active = 0; int partial_pause = 0; - /* don't touch anything if takeover is in progress */ - if (cf_reboot) - return; - statlist_for_each(item, &pool_list) { pool = container_of(item, PgPool, head); if (pool->admin) @@ -457,10 +453,6 @@ static void do_full_maint(int sock, short flags, void *arg) List *item; PgPool *pool; - /* don't touch anything if takeover is in progress */ - if (cf_reboot) - goto skip; - statlist_for_each(item, &pool_list) { pool = container_of(item, PgPool, head); if (pool->admin) diff --git a/src/main.c b/src/main.c index 769c075..26e680d 100644 --- a/src/main.c +++ b/src/main.c @@ -465,8 +465,7 @@ static void daemon_setup(void) check_pidfile(); if (cf_daemon) go_daemon(); - if (!cf_reboot) - write_pidfile(); + write_pidfile(); } static void main_loop_once(void) @@ -489,6 +488,7 @@ static void main_loop_once(void) int main(int argc, char *argv[]) { int c; + int did_takeover = 0; /* parse cmdline */ while ((c = getopt(argc, argv, "avhdVR")) != EOF) { @@ -518,10 +518,9 @@ int main(int argc, char *argv[]) cf_config_file = argv[optind]; init_objects(); - load_config(false); - init_caches(); + admin_setup(); /* need to do that after loading config */ check_limits(); @@ -529,21 +528,27 @@ int main(int argc, char *argv[]) /* init random */ srandom(time(NULL) ^ getpid()); + if (cf_reboot) { + /* use temporary libevent base */ + void *evtmp = event_init(); + takeover_init(); + while (cf_reboot) + main_loop_once(); + did_takeover = 1; + event_base_free(evtmp); + } + /* initialize subsystems, order important */ daemon_setup(); event_init(); signal_setup(); janitor_setup(); stats_setup(); - admin_setup(); - if (cf_reboot) { - takeover_init(); - while (cf_reboot) - main_loop_once(); - write_pidfile(); - } else + if (!did_takeover) pooler_setup(); + else + resume_all(); /* main loop */ while (1) diff --git a/src/objects.c b/src/objects.c index f46ecbc..f29c376 100644 --- a/src/objects.c +++ b/src/objects.c @@ -110,11 +110,13 @@ static int user_node_cmp(long userptr, Node *node) return strcmp(name, user->name); } +/* initialization before config loading */ void init_objects(void) { tree_init(&user_tree, user_node_cmp, NULL); } +/* initialization after config loading */ void init_caches(void) { server_cache = objcache_create("server_cache", PG_SOCKET_SIZE, 8, diff --git a/src/takeover.c b/src/takeover.c index 94654de..e2b3458 100644 --- a/src/takeover.c +++ b/src/takeover.c @@ -35,7 +35,6 @@ static void takeover_finish(PgSocket *bouncer) { disconnect_server(bouncer, false, "disko over"); cf_reboot = 0; - resume_all(); log_info("disko over, resuming work"); }