From: Marko Kreen Date: Mon, 3 Dec 2012 16:27:03 +0000 (+0200) Subject: Minor cleanups for ENABLE/DISABLE, add tests X-Git-Tag: pgbouncer_1_6_rc1~49 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf8a20b56b02f635f8b53c6a48572c7c4ba69637;p=pgbouncer Minor cleanups for ENABLE/DISABLE, add tests --- diff --git a/src/admin.c b/src/admin.c index dbc4fa2..693ba83 100644 --- a/src/admin.c +++ b/src/admin.c @@ -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; diff --git a/src/client.c b/src/client.c index c28bd7f..4a8faf5 100644 --- a/src/client.c +++ b/src/client.c @@ -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); } diff --git a/test/test.sh b/test/test.sh index 3cc0e8c..e5098af 100755 --- a/test/test.sh +++ b/test/test.sh @@ -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 "