From 5260ac4e4ffc94c1b2de43121e04b8ba0df46b0c Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Fri, 18 Jan 2008 07:44:11 +0000 Subject: [PATCH] move ->admin flag from pool to db --- include/bouncer.h | 6 +++--- src/admin.c | 6 +++--- src/client.c | 4 ++-- src/janitor.c | 10 +++++----- src/main.c | 2 +- src/objects.c | 2 +- src/server.c | 6 +++--- src/takeover.c | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/bouncer.h b/include/bouncer.h index dffbb0e..85065c6 100644 --- a/include/bouncer.h +++ b/include/bouncer.h @@ -177,7 +177,6 @@ struct PgPool { usec_t last_connect_time; unsigned last_connect_failed:1; - unsigned admin:1; unsigned welcome_msg_ready:1; }; @@ -216,10 +215,11 @@ struct PgUser { */ struct PgDatabase { List head; - char name[MAX_DBNAME]; + char name[MAX_DBNAME]; /* db name for clients */ bool db_paused; /* PAUSE ; was issued */ bool db_dead; /* used on RELOAD/SIGHUP to later detect removed dbs */ + bool admin; /* internal console db */ uint8_t startup_params[256]; /* partial StartupMessage (without user) be sent to server */ unsigned startup_params_len; @@ -231,7 +231,7 @@ struct PgDatabase { int pool_size; /* max server connections in one pool */ - const char *dbname; /* pointer to inside startup_msg */ + const char *dbname; /* server-side name, pointer to inside startup_msg */ }; /* diff --git a/src/admin.c b/src/admin.c index 0c940fa..4df9c94 100644 --- a/src/admin.c +++ b/src/admin.c @@ -375,7 +375,7 @@ static bool admin_show_fds(PgSocket *admin, const char *arg) statlist_for_each(item, &pool_list) { pool = container_of(item, PgPool, head); - if (pool->admin) + if (pool->db->admin) continue; res = res && show_fds_from_list(admin, &pool->active_client_list); res = res && show_fds_from_list(admin, &pool->waiting_client_list); @@ -1119,14 +1119,14 @@ void admin_setup(void) db->addr.port = cf_listen_port; db->addr.is_unix = 1; db->pool_size = 2; + db->admin = 1; if (!force_user(db, "pgbouncer", "")) fatal("no mem on startup - cannot alloc pgbouncer user"); - /* fake pool, tag the it as special */ + /* fake pool */ pool = get_pool(db, db->forced_user); if (!pool) fatal("cannot create admin pool?"); - pool->admin = 1; admin_pool = pool; /* fake user, with disabled psw */ diff --git a/src/client.c b/src/client.c index a801680..5bd5087 100644 --- a/src/client.c +++ b/src/client.c @@ -220,7 +220,7 @@ static bool handle_client_startup(PgSocket *client, PktHdr *pkt) if (!decide_startup_pool(client, pkt)) return false; - if (client->pool->admin) { + if (client->pool->db->admin) { if (!admin_pre_login(client)) return false; } @@ -304,7 +304,7 @@ static bool handle_client_work(PgSocket *client, PktHdr *pkt) client->query_start = get_cached_time(); } - if (client->pool->admin) + if (client->pool->db->admin) return admin_handle_client(client, pkt); /* aquire server */ diff --git a/src/janitor.c b/src/janitor.c index 301e090..2964084 100644 --- a/src/janitor.c +++ b/src/janitor.c @@ -107,7 +107,7 @@ static void resume_sockets(void) statlist_for_each(item, &pool_list) { pool = container_of(item, PgPool, head); - if (pool->admin) + if (pool->db->admin) continue; resume_socket_list(&pool->active_client_list); resume_socket_list(&pool->active_server_list); @@ -207,7 +207,7 @@ static int per_loop_pause(PgPool *pool) { int active = 0; - if (pool->admin) + if (pool->db->admin) return 0; close_server_list(&pool->idle_server_list, "pause mode"); @@ -227,7 +227,7 @@ static int per_loop_suspend(PgPool *pool, bool force_suspend) { int active = 0; - if (pool->admin) + if (pool->db->admin) return 0; active += suspend_socket_list(&pool->active_client_list, force_suspend); @@ -268,7 +268,7 @@ void per_loop_maint(void) statlist_for_each(item, &pool_list) { pool = container_of(item, PgPool, head); - if (pool->admin) + if (pool->db->admin) continue; switch (cf_pause_mode) { case P_NONE: @@ -484,7 +484,7 @@ static void do_full_maint(int sock, short flags, void *arg) statlist_for_each(item, &pool_list) { pool = container_of(item, PgPool, head); - if (pool->admin) + if (pool->db->admin) continue; pool_server_maint(pool); pool_client_maint(pool); diff --git a/src/main.c b/src/main.c index 3c5d368..7235872 100644 --- a/src/main.c +++ b/src/main.c @@ -230,7 +230,7 @@ static void set_dbs_dead(bool flag) statlist_for_each(item, &database_list) { db = container_of(item, PgDatabase, head); - if (strcmp(db->name, "pgbouncer") == 0) + if (db->admin) continue; db->db_dead = flag; } diff --git a/src/objects.c b/src/objects.c index 7e15549..7335892 100644 --- a/src/objects.c +++ b/src/objects.c @@ -844,7 +844,7 @@ found: disconnect_client(req, false, "cancel request for idle client"); /* let administrative cancel be handled elsewhere */ - if (main_client->pool->admin) { + if (main_client->pool->db->admin) { admin_handle_cancel(main_client); return; } diff --git a/src/server.c b/src/server.c index bd6f1ee..8ceb063 100644 --- a/src/server.c +++ b/src/server.c @@ -126,7 +126,7 @@ static bool handle_server_startup(PgSocket *server, PktHdr *pkt) res = release_server(server); /* let the takeover process handle it */ - if (res && server->pool->admin) + if (res && server->pool->db->admin) res = takeover_login(server); break; @@ -159,7 +159,7 @@ static bool handle_server_work(PgSocket *server, PktHdr *pkt) SBuf *sbuf = &server->sbuf; PgSocket *client = server->link; - Assert(!server->pool->admin); + Assert(!server->pool->db->admin); switch (pkt->type) { default: @@ -385,7 +385,7 @@ bool server_proto(SBuf *sbuf, SBufEvent evtype, MBuf *data, void *arg) slog_warning(server, "SBUF_EV_PKT_CALLBACK with state=%d", server->state); break; } - if (!res && pool->admin) + if (!res && pool->db->admin) takeover_login_failed(); return res; } diff --git a/src/takeover.c b/src/takeover.c index ea7cad0..8533297 100644 --- a/src/takeover.c +++ b/src/takeover.c @@ -174,7 +174,7 @@ static void takeover_postprocess_fds(void) statlist_for_each(item, &pool_list) { pool = container_of(item, PgPool, head); - if (pool->admin) + if (pool->db->admin) continue; statlist_for_each(item2, &pool->active_client_list) { client = container_of(item2, PgSocket, head); -- 2.40.0