]> granicus.if.org Git - pgbouncer/commitdiff
less scary -R: move takever before fork
authorMarko Kreen <markokr@gmail.com>
Tue, 8 Jan 2008 14:13:25 +0000 (14:13 +0000)
committerMarko Kreen <markokr@gmail.com>
Tue, 8 Jan 2008 14:13:25 +0000 (14:13 +0000)
src/janitor.c
src/main.c
src/objects.c
src/takeover.c

index 06fd7107380ad46d72f7f53db2bb1c0bb225dda1..07b2d6eafd627115acf4ada7c2d3f7210c686b8d 100644 (file)
@@ -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)
index 769c0753e8fdad180f1f4897c41eaf67942b4227..26e680d5ba792989b6f725b8661f3aa96a63c975 100644 (file)
@@ -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)
index f46ecbc75dc180984b1ca274b34cf4fcdab7899f..f29c376615473f9ba80bd9cb9afa766079c613f9 100644 (file)
@@ -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,
index 94654de1b1b86ca0c79ea0064e89c5161d001ffe..e2b34581263d0daecd7299b2cf7ed0609a2ab0cf 100644 (file)
@@ -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");
 }