]> granicus.if.org Git - pgbouncer/commitdiff
Minor cleanups for ENABLE/DISABLE, add tests
authorMarko Kreen <markokr@gmail.com>
Mon, 3 Dec 2012 16:27:03 +0000 (18:27 +0200)
committerMarko Kreen <markokr@gmail.com>
Mon, 3 Dec 2012 17:16:50 +0000 (19:16 +0200)
src/admin.c
src/client.c
test/test.sh

index dbc4fa230bec050ee498aa9199287390beafdac8..693ba8372303437599a0bc3375292d53c6ae1bae 100644 (file)
@@ -364,9 +364,9 @@ static PgDatabase *find_or_register_database(PgSocket *admin, const char *name)
                if (db != NULL) {
                        slog_info(admin,
                                  "registered new auto-database: %s", name);
-                }
+               }
        }
-        return db;
+       return db;
 }
 
 /*
@@ -1006,7 +1006,7 @@ static bool admin_cmd_disable(PgSocket *admin, const char *arg)
        db = find_or_register_database(admin, arg);
        if (db == NULL)
                return admin_error(admin, "no such database: %s", arg);
-       if (db == admin->pool->db)
+       if (db->admin)
                return admin_error(admin, "cannot disable admin db: %s", arg);
 
        db->db_disabled = 1;
@@ -1028,7 +1028,7 @@ static bool admin_cmd_enable(PgSocket *admin, const char *arg)
        db = find_database(arg);
        if (db == NULL)
                return admin_error(admin, "no such database: %s", arg);
-       if (db == admin->pool->db)
+       if (db->admin)
                return admin_error(admin, "cannot disable admin db: %s", arg);
 
        db->db_disabled = 0;
index c28bd7f4841ada8e813f660c33b5d08b88b21138..4a8faf5ce919960af96907d73169f16e118f2c46 100644 (file)
@@ -76,6 +76,12 @@ bool set_pool(PgSocket *client, const char *dbname, const char *username)
                }
        }
 
+       /* are new connections allowed? */
+       if (db->db_disabled) {
+               disconnect_client(client, true, "database does not allow connections: %s", dbname);
+               return false;
+       }
+
        /* find user */
        if (cf_auth_type == AUTH_ANY) {
                /* ignore requested user */
@@ -105,10 +111,6 @@ bool set_pool(PgSocket *client, const char *dbname, const char *username)
                disconnect_client(client, true, "no memory for pool");
                return false;
        }
-       if (client->pool->db->db_disabled) {
-               disconnect_client(client, true, "pgbouncer database is disabled");
-               return false;
-       }
 
        return check_fast_fail(client);
 }
index 3cc0e8c236dd7ffcfd1f9880aa64cb4903c00d78..e5098afe7d9ea827ef910d8738dbcf2ede71628a 100755 (executable)
@@ -331,6 +331,23 @@ test_suspend_resume() {
        test `wc -l <$LOGDIR/test.tmp` -eq 50
 }
 
+# test pause/resume
+test_enable_disable() {
+       rm -f $LOGDIR/test.tmp
+       psql -tAq p0 -c "select 'enabled 1'" >>$LOGDIR/test.tmp 2>&1
+
+       admin "disable p0"
+       psql -tAq p0 -c "select 'disabled 1'" >>$LOGDIR/test.tmp 2>&1
+       admin "enable p0"
+       psql -tAq p0 -c "select 'enabled 2'" >>$LOGDIR/test.tmp 2>&1
+
+       grep -q "enabled 1" $LOGDIR/test.tmp || return 1
+       grep -q "enabled 2" $LOGDIR/test.tmp || return 1
+       grep -q "disabled 1" $LOGDIR/test.tmp && return 1
+       grep -q "does not allow" $LOGDIR/test.tmp || return 1
+       return 0
+}
+
 # test pool database restart
 test_database_restart() {
        admin "set server_login_retry=1"
@@ -396,6 +413,7 @@ test_pool_size
 test_online_restart
 test_pause_resume
 test_suspend_resume
+test_enable_disable
 test_database_restart
 test_database_change
 "