pgpool2.git / summary / log / commit / refs
commit f12b15506df074f48eb8ddd21bad19b24dcaeabe
Author: Yoshiyuki Asaba <y-asaba at pgfoundry.org>
Date: Mon Jul 23 04:37:35 2007 +0000
Add reloading config files. pgpool can reload pgpool.conf,
pool_hba.conf and distributed rules from system DB. If reload, you
type the following command.
% pgpool reload
Or you send SIGHUP signal to the pgpool parent process.
child.c | 26 ++++++-
main.c | 135 ++++++++++++++++++++++++++-------
pool.h | 14 +++-
pool_config.c | 208 ++++++++++++++++++++++++++++++++-------------------
pool_config.l | 176 ++++++++++++++++++++++++++++---------------
pool_process_query.c | 27 +++++--
pool_type.h | 1 +
7 files changed, 409 insertions(+), 178 deletions(-)
diff --git a/child.c b/child.c
index 49c2f41e4..c00c6b384 100644
--- a/child.c
+++ b/child.c
@@ -67,6 +67,7 @@ static void cancel_request(CancelPacket *sp, int secondary_backend);
static RETSIGTYPE die(int sig);
static RETSIGTYPE close_idle_connection(int sig);
static RETSIGTYPE wakeup_handler(int sig);
+static RETSIGTYPE reload_config_handler(int sig);
static int send_params(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
static void send_frontend_exits(void);
static int s_do_auth(POOL_CONNECTION_POOL_SLOT *cp, char *password);
@@ -85,6 +86,8 @@ extern char **myargv;
char remote_ps_data[NI_MAXHOST]; /* used for set_ps_display */
+volatile sig_atomic_t got_sighup = 0;
+
/*
* child main loop
*/
@@ -111,10 +114,10 @@ void do_child(int unix_fd, int inet_fd)
signal(SIGALRM, SIG_DFL);
signal(SIGTERM, die);
signal(SIGINT, die);
- signal(SIGHUP, close_idle_connection);
+ signal(SIGHUP, reload_config_handler);
signal(SIGQUIT, die);
signal(SIGCHLD, SIG_DFL);
- signal(SIGUSR1, SIG_DFL);
+ signal(SIGUSR1, close_idle_connection);
signal(SIGUSR2, wakeup_handler);
signal(SIGPIPE, SIG_IGN);
@@ -716,6 +719,17 @@ static POOL_CONNECTION *do_accept(int unix_fd, int inet_fd, struct timeval *time
}
#endif
+ /* reload config file */
+ if (got_sighup)
+ {
+ pool_get_config(get_config_file_name(), RELOAD_CONFIG);
+ if (pool_config->enable_pool_hba)
+ load_hba(get_hba_file_name());
+ if (pool_config->parallel_mode)
+ pool_memset_system_db_info(system_db_info->info);
+ got_sighup = 0;
+ }
+
connection_count_up();
accepted = 1;
@@ -1143,7 +1157,7 @@ static RETSIGTYPE die(int sig)
}
/*
- * signal handler for SIGHUP
+ * signal handler for SIGUSR1
* close all idle connections
*/
static RETSIGTYPE close_idle_connection(int sig)
@@ -1713,3 +1727,9 @@ static int select_load_balancing_node(void)
pool_debug("select_load_balancing_node: selected backend id is %d", selected_slot);
return selected_slot;
}
+
+/* SIGHUP handler */
+static RETSIGTYPE reload_config_handler(int sig)
+{
+ got_sighup = 1;
+}
diff --git a/main.c b/main.c
index e63187338..2494cf5a3 100644
--- a/main.c
+++ b/main.c
@@ -67,6 +67,11 @@
{ \
reaper(); \
} \
+ if (reload_config_request) \
+ { \
+ reload_config(); \
+ reload_config_request = 0; \
+ } \
} while (0)
@@ -82,12 +87,15 @@ static void myexit(int code);
static void failover(void);
static void reaper(void);
static void wakeup_children(void);
+static void reload_config(void);
static int pool_pause(struct timeval *timeout);
static void pool_sleep(unsigned int second);
+static void kill_all_children(int sig);
static RETSIGTYPE exit_handler(int sig);
static RETSIGTYPE reap_handler(int sig);
static RETSIGTYPE failover_handler(int sig);
+static RETSIGTYPE reload_config_handler(int sig);
static RETSIGTYPE health_check_timer_handler(int sig);
static RETSIGTYPE wakeup_handler(int sig);
@@ -106,6 +114,8 @@ static int pcp_pid; /* pid for child process handling PCP */
static int pcp_unix_fd; /* unix domain socket fd for PCP (not used) */
static int pcp_inet_fd; /* inet domain socket fd for PCP */
static char pcp_conf_file[POOLMAXPATHLEN+1]; /* path for pcp.conf */
+static char conf_file[POOLMAXPATHLEN+1];
+static char hba_file[POOLMAXPATHLEN+1];
static int exiting = 0; /* non 0 if I'm exiting */
static int switching = 0; /* non 0 if I'm fail overing or degenerating */
@@ -118,7 +128,7 @@ static int clear_cache = 0; /* non 0 if clear chache option (-c) is given */
static int not_detach = 0; /* non 0 if non detach option (-n) is given */
int debug = 0; /* non 0 if debug option is given (-d) */
-static pid_t mypid; /* pgpool parent process id */
+pid_t mypid; /* pgpool parent process id */
long int weight_master; /* normalized weight of master (0-RAND_MAX range) */
@@ -128,9 +138,11 @@ static int health_check_timer_expired; /* non 0 if health check timer expired *
POOL_REQUEST_INFO *Req_info; /* request info area in shared memory */
volatile sig_atomic_t *InRecovery; /* non 0 if recovery is started */
+volatile sig_atomic_t reload_config_request = 0;
static volatile sig_atomic_t failover_request = 0;
static volatile sig_atomic_t sigchld_request = 0;
static volatile sig_atomic_t wakeup_request = 0;
+
static int pipe_fds[2]; /* for delivering signals */
int my_proc_id;
@@ -144,8 +156,6 @@ char **myargv;
int main(int argc, char **argv)
{
int opt;
- char conf_file[POOLMAXPATHLEN+1];
- char hba_file[POOLMAXPATHLEN+1];
int i;
int pid;
int size;
@@ -233,7 +243,12 @@ int main(int argc, char **argv)
}
}
- if (pool_get_config(conf_file))
+ mypid = getpid();
+
+ if (pool_init_config())
+ exit(1);
+
+ if (pool_get_config(conf_file, INIT_CONFIG))
{
pool_error("Unable to get configuration. Exiting...");
exit(1);
@@ -243,10 +258,32 @@ int main(int argc, char **argv)
load_hba(hba_file);
/*
- * if a non-switch argument remains, then it should be either "stop" or "switch"
+ * if a non-switch argument remains, then it should be either "reload", "stop" or "switch"
*/
if (optind == (argc - 1))
{
+ if (!strcmp(argv[optind], "reload"))
+ {
+ pid_t pid;
+
+ pid = read_pid_file();
+ if (pid < 0)
+ {
+ pool_error("could not read pid file");
+ pool_shmem_exit(1);
+ exit(1);
+ }
+
+ if (kill(pid, SIGHUP) == -1)
+ {
+ pool_error("could not stop pid: %d. reason: %s", pid, strerror(errno));
+ pool_shmem_exit(1);
+ exit(1);
+ }
+ pool_log("xxx %d", pid);
+ pool_shmem_exit(0);
+ exit(0);
+ }
if (!strcmp(argv[optind], "stop"))
{
stop_me();
@@ -301,8 +338,6 @@ int main(int argc, char **argv)
exit(1);
}
- mypid = getpid();
-
/* clear cache */
if (clear_cache && pool_config->enable_query_cache && SYSDB_STATUS == CON_UP)
{
@@ -390,7 +425,7 @@ int main(int argc, char **argv)
pool_signal(SIGCHLD, reap_handler);
pool_signal(SIGUSR1, failover_handler);
pool_signal(SIGUSR2, wakeup_handler);
- pool_signal(SIGHUP, exit_handler);
+ pool_signal(SIGHUP, reload_config_handler);
/* create pipe for delivering event */
if (pipe(pipe_fds) < 0)
@@ -590,6 +625,8 @@ static void daemonize(void)
}
#endif
+ mypid = getpid();
+
i = open("/dev/null", O_RDWR);
dup2(i, 0);
dup2(i, 1);
@@ -705,6 +742,7 @@ pid_t pcp_fork_a_child(int unix_fd, int inet_fd, char *pcp_conf_file)
/* call PCP child main */
POOL_SETMASK(&UnBlockSig);
+ reload_config_request = 0;
pcp_do_child(unix_fd, inet_fd, pcp_conf_file);
}
else if (pid == -1)
@@ -733,6 +771,7 @@ pid_t fork_a_child(int unix_fd, int inet_fd, int id)
/* call child main */
POOL_SETMASK(&UnBlockSig);
+ reload_config_request = 0;
my_proc_id = id;
do_child(unix_fd, inet_fd);
}
@@ -949,8 +988,6 @@ static RETSIGTYPE exit_handler(int sig)
pool_log("received fast shutdown request");
else if (sig == SIGQUIT)
pool_log("received immediate shutdown request");
- else if (sig == SIGHUP)
- pool_log("received idle connection close request");
else
{
pool_error("exit_handler: unknown signal received %d", sig);
@@ -971,13 +1008,6 @@ static RETSIGTYPE exit_handler(int sig)
kill(pcp_pid, sig);
- if (sig == SIGHUP)
- {
- exiting = 0;
- POOL_SETMASK(&UnBlockSig);
- return;
- }
-
POOL_SETMASK(&UnBlockSig);
while (wait(NULL) > 0)
@@ -1045,6 +1075,13 @@ static void failover(void)
return;
}
+ if (Req_info->kind == CLOSE_IDLE_REQUEST)
+ {
+ kill_all_children(SIGUSR1);
+ kill(pcp_pid, SIGUSR2);
+ return;
+ }
+
node_id = Req_info->node_id;
if (node_id < 0)
@@ -1483,6 +1520,43 @@ pool_get_system_db_info(void)
* Wakeup all processes
*/
static void wakeup_children(void)
+{
+ kill_all_children(SIGUSR2);
+}
+
+
+static RETSIGTYPE wakeup_handler(int sig)
+{
+ POOL_SETMASK(&BlockSig);
+ wakeup_request = 1;
+ write(pipe_fds[1], "\0", 1);
+ POOL_SETMASK(&UnBlockSig);
+}
+
+/*
+ * handle SIGHUP
+ *
+ */
+static RETSIGTYPE reload_config_handler(int sig)
+{
+ POOL_SETMASK(&BlockSig);
+ reload_config_request = 1;
+ write(pipe_fds[1], "\0", 1);
+ POOL_SETMASK(&UnBlockSig);
+}
+
+static void reload_config(void)
+{
+ pool_log("reload config files.");
+ pool_get_config(conf_file, RELOAD_CONFIG);
+ if (pool_config->enable_pool_hba)
+ load_hba(hba_file);
+ if (pool_config->parallel_mode)
+ pool_memset_system_db_info(system_db_info->info);
+ kill_all_children(SIGHUP);
+}
+
+static void kill_all_children(int sig)
{
int i;
@@ -1492,20 +1566,11 @@ static void wakeup_children(void)
pid_t pid = pids[i].pid;
if (pid)
{
- kill(pid, SIGUSR2);
+ kill(pid, sig);
}
}
}
-
-static RETSIGTYPE wakeup_handler(int sig)
-{
- POOL_SETMASK(&BlockSig);
- wakeup_request = 1;
- write(pipe_fds[1], "\0", 1);
- POOL_SETMASK(&UnBlockSig);
-}
-
/*
* pool_pause: A process pauses by select().
*/
@@ -1559,3 +1624,19 @@ static void pool_sleep(unsigned int second)
}
POOL_SETMASK(&BlockSig);
}
+
+/*
+ * get_config_file_name: return full path of pgpool.conf.
+ */
+char *get_config_file_name(void)
+{
+ return conf_file;
+}
+
+/*
+ * get_config_file_name: return full path of pool_hba.conf.
+ */
+char *get_hba_file_name(void)
+{
+ return hba_file;
+}
diff --git a/pool.h b/pool.h
index 32c8d9b9e..c4fdefbdb 100644
--- a/pool.h
+++ b/pool.h
@@ -71,6 +71,13 @@ typedef enum {
POOL_FATAL
} POOL_STATUS;
+
+typedef enum {
+ INIT_CONFIG = 1, /* 0x01 */
+ RELOAD_CONFIG = 2 /* 0x02 */
+} POOL_CONFIG_CONTEXT;
+
+
/* protocol major version numbers */
#define PROTO_MAJOR_V2 2
#define PROTO_MAJOR_V3 3
@@ -365,6 +372,7 @@ typedef struct {
/*
* global variables
*/
+extern pid_t mypid; /* parent pid */
extern POOL_CONFIG *pool_config; /* configuration values */
extern POOL_CONNECTION_POOL *pool_connection_pool; /* connection pool */
extern long int weight_master; /* normalized weight of master (0-RAND_MAX range) */
@@ -377,14 +385,18 @@ extern int master_slave_dml; /* non 0 if master/slave mode is specified in confi
extern POOL_REQUEST_INFO *Req_info;
extern volatile sig_atomic_t *InRecovery;
extern char remote_ps_data[]; /* used for set_ps_display */
+extern volatile sig_atomic_t got_sighup;
/*
* public functions
*/
+extern char *get_config_file_name(void);
+extern char *get_hba_file_name(void);
extern void pool_error(const char *fmt,...);
extern void pool_debug(const char *fmt,...);
extern void pool_log(const char *fmt,...);
-extern int pool_get_config(char *confpath);
+extern int pool_init_config(void);
+extern int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context);
extern void do_child(int unix_fd, int inet_fd);
extern void pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file);
extern int pool_init_cp(void);
diff --git a/pool_config.c b/pool_config.c
index 50bf26fe7..ef7e6cfe0 100644
--- a/pool_config.c
+++ b/pool_config.c
@@ -517,12 +517,15 @@ char *yytext;
#include <stdio.h>
#include <string.h>
+#define CHECK_CONTEXT(mask, context) ((mask) & (context))
+
/* to shut off compiler warnings */
int yylex(void);
POOL_CONFIG *pool_config; /* configuration values */
POOL_SYSTEMDB_CONNECTION_POOL *system_db_info;
static unsigned Lineno;
+static char *default_reset_query_list[] = {"ABORT", "RESET ALL", "SET SESSION AUTHORIZATION DEFAULT"};
typedef enum {
POOL_KEY = 1,
@@ -540,7 +543,7 @@ static char **extract_string_tokens(char *str, char *delim, int *n);
static int eval_logical(char *str);
static void clear_host_entry(int slot);
-#line 544 "pool_config.c"
+#line 547 "pool_config.c"
#define INITIAL 0
@@ -691,10 +694,10 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
-#line 80 "pool_config.l"
+#line 83 "pool_config.l"
-#line 698 "pool_config.c"
+#line 701 "pool_config.c"
if ( !(yy_init) )
{
@@ -776,12 +779,12 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
/* rule 1 can match eol */
YY_RULE_SETUP
-#line 82 "pool_config.l"
+#line 85 "pool_config.l"
Lineno++; return POOL_EOL;
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 83 "pool_config.l"
+#line 86 "pool_config.l"
/* eat whitespace */
YY_BREAK
case 3:
@@ -789,50 +792,50 @@ case 3:
(yy_c_buf_p) = yy_cp -= 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
-#line 84 "pool_config.l"
+#line 87 "pool_config.l"
/* eat comment */
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 86 "pool_config.l"
+#line 89 "pool_config.l"
return POOL_KEY;
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 87 "pool_config.l"
+#line 90 "pool_config.l"
return POOL_STRING;
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 88 "pool_config.l"
+#line 91 "pool_config.l"
return POOL_UNQUOTED_STRING;
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 89 "pool_config.l"
+#line 92 "pool_config.l"
return POOL_INTEGER;
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 90 "pool_config.l"
+#line 93 "pool_config.l"
return POOL_REAL;
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 91 "pool_config.l"
+#line 94 "pool_config.l"
return POOL_EQUALS;
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 93 "pool_config.l"
+#line 96 "pool_config.l"
return POOL_PARSE_ERROR;
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 95 "pool_config.l"
+#line 98 "pool_config.l"
ECHO;
YY_BREAK
-#line 836 "pool_config.c"
+#line 839 "pool_config.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
@@ -1778,19 +1781,14 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
-#line 95 "pool_config.l"
+#line 98 "pool_config.l"
-int pool_get_config(char *confpath)
+int pool_init_config(void)
{
- FILE *fd;
- int token;
- char key[1024];
- static char *default_reset_query_list[] = {"ABORT", "RESET ALL", "SET SESSION AUTHORIZATION DEFAULT"};
- static char localhostname[256];
int res;
- double total_weight;
+ static char localhostname[256];
int i;
pool_config = malloc(sizeof(POOL_CONFIG));
@@ -1865,6 +1863,16 @@ int pool_get_config(char *confpath)
{
clear_host_entry(i);
}
+ return 0;
+}
+
+int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
+{
+ FILE *fd;
+ int token;
+ char key[1024];
+ double total_weight;
+ int i;
#define PARSE_ERROR() pool_error("pool_config: parse error at line %d '%s'", Lineno, yytext)
@@ -1910,7 +1918,7 @@ int pool_get_config(char *confpath)
pool_debug("value: %s kind: %d", yytext, token);
- if (!strcmp(key, "allow_inet_domain_socket"))
+ if (!strcmp(key, "allow_inet_domain_socket") && CHECK_CONTEXT(INIT_CONFIG, context))
{
/* for backward compatibility */
int v = eval_logical(yytext);
@@ -1926,7 +1934,7 @@ int pool_get_config(char *confpath)
else
pool_config->listen_addresses = strdup("");
}
- else if (!strcmp(key, "listen_addresses"))
+ else if (!strcmp(key, "listen_addresses") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -1945,7 +1953,7 @@ int pool_get_config(char *confpath)
pool_config->listen_addresses = str;
}
- else if (!strcmp(key, "port"))
+ else if (!strcmp(key, "port") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -1957,7 +1965,7 @@ int pool_get_config(char *confpath)
}
pool_config->port = v;
}
- else if (!strcmp(key, "pcp_port"))
+ else if (!strcmp(key, "pcp_port") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -1969,7 +1977,7 @@ int pool_get_config(char *confpath)
}
pool_config->pcp_port = v;
}
- else if (!strcmp(key, "socket_dir"))
+ else if (!strcmp(key, "socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -1987,7 +1995,7 @@ int pool_get_config(char *confpath)
}
pool_config->socket_dir = str;
}
- else if (!strcmp(key, "pcp_socket_dir"))
+ else if (!strcmp(key, "pcp_socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2005,7 +2013,7 @@ int pool_get_config(char *confpath)
}
pool_config->pcp_socket_dir = str;
}
- else if (!strcmp(key, "pcp_timeout"))
+ else if (!strcmp(key, "pcp_timeout") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -2017,7 +2025,7 @@ int pool_get_config(char *confpath)
}
pool_config->pcp_timeout = v;
}
- else if (!strcmp(key, "num_init_children"))
+ else if (!strcmp(key, "num_init_children") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -2029,7 +2037,8 @@ int pool_get_config(char *confpath)
}
pool_config->num_init_children = v;
}
- else if (!strcmp(key, "child_life_time"))
+ else if (!strcmp(key, "child_life_time") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -2041,7 +2050,8 @@ int pool_get_config(char *confpath)
}
pool_config->child_life_time = v;
}
- else if (!strcmp(key, "connection_life_time"))
+ else if (!strcmp(key, "connection_life_time") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -2053,7 +2063,8 @@ int pool_get_config(char *confpath)
}
pool_config->connection_life_time = v;
}
- else if (!strcmp(key, "child_max_connections"))
+ else if (!strcmp(key, "child_max_connections") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -2065,7 +2076,7 @@ int pool_get_config(char *confpath)
}
pool_config->child_max_connections = v;
}
- else if (!strcmp(key, "max_pool"))
+ else if (!strcmp(key, "max_pool") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -2077,7 +2088,7 @@ int pool_get_config(char *confpath)
}
pool_config->max_pool = v;
}
- else if (!strcmp(key, "logdir"))
+ else if (!strcmp(key, "logdir") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2095,7 +2106,8 @@ int pool_get_config(char *confpath)
}
pool_config->logdir = str;
}
- else if (!strcmp(key, "log_connections"))
+ else if (!strcmp(key, "log_connections") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2107,7 +2119,8 @@ int pool_get_config(char *confpath)
}
pool_config->log_connections = v;
}
- else if (!strcmp(key, "log_hostname"))
+ else if (!strcmp(key, "log_hostname") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2119,7 +2132,8 @@ int pool_get_config(char *confpath)
}
pool_config->log_hostname = v;
}
- else if (!strcmp(key, "enable_pool_hba"))
+ else if (!strcmp(key, "enable_pool_hba") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2131,7 +2145,7 @@ int pool_get_config(char *confpath)
}
pool_config->enable_pool_hba = v;
}
- else if (!strcmp(key, "backend_socket_dir"))
+ else if (!strcmp(key, "backend_socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2149,7 +2163,7 @@ int pool_get_config(char *confpath)
}
pool_config->backend_socket_dir = str;
}
- else if (!strcmp(key, "replication_mode"))
+ else if (!strcmp(key, "replication_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2169,7 +2183,7 @@ int pool_get_config(char *confpath)
}
}
- else if (!strcmp(key, "replication_strict"))
+ else if (!strcmp(key, "replication_strict") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2181,7 +2195,8 @@ int pool_get_config(char *confpath)
}
pool_config->replication_strict = v;
}
- else if (!strcmp(key, "replication_timeout"))
+ else if (!strcmp(key, "replication_timeout") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -2193,7 +2208,7 @@ int pool_get_config(char *confpath)
}
pool_config->replication_timeout = v;
}
- else if (!strcmp(key, "load_balance_mode"))
+ else if (!strcmp(key, "load_balance_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2205,7 +2220,8 @@ int pool_get_config(char *confpath)
}
pool_config->load_balance_mode = v;
}
- else if (!strcmp(key, "replication_stop_on_mismatch"))
+ else if (!strcmp(key, "replication_stop_on_mismatch") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2218,7 +2234,8 @@ int pool_get_config(char *confpath)
pool_debug("replication_stop_on_mismatch: %d", v);
pool_config->replication_stop_on_mismatch = v;
}
- else if (!strcmp(key, "reset_query_list"))
+ else if (!strcmp(key, "reset_query_list") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
char *str;
@@ -2242,7 +2259,7 @@ int pool_get_config(char *confpath)
}
}
- else if (!strcmp(key, "print_timestamp"))
+ else if (!strcmp(key, "print_timestamp") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2255,7 +2272,7 @@ int pool_get_config(char *confpath)
pool_config->print_timestamp = v;
}
- else if (!strcmp(key, "master_slave_mode"))
+ else if (!strcmp(key, "master_slave_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2275,7 +2292,7 @@ int pool_get_config(char *confpath)
}
}
- else if (!strcmp(key, "connection_cache"))
+ else if (!strcmp(key, "connection_cache") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2288,7 +2305,8 @@ int pool_get_config(char *confpath)
pool_config->connection_cache = v;
}
- else if (!strcmp(key, "health_check_timeout"))
+ else if (!strcmp(key, "health_check_timeout") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -2301,7 +2319,8 @@ int pool_get_config(char *confpath)
pool_config->health_check_timeout = v;
}
- else if (!strcmp(key, "health_check_period"))
+ else if (!strcmp(key, "health_check_period") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -2314,7 +2333,8 @@ int pool_get_config(char *confpath)
pool_config->health_check_period = v;
}
- else if (!strcmp(key, "health_check_user"))
+ else if (!strcmp(key, "health_check_user") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
char *str;
@@ -2333,7 +2353,8 @@ int pool_get_config(char *confpath)
pool_config->health_check_user = str;
}
- else if (!strcmp(key, "recovery_user"))
+ else if (!strcmp(key, "recovery_user") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
char *str;
@@ -2352,7 +2373,8 @@ int pool_get_config(char *confpath)
pool_config->recovery_user = str;
}
- else if (!strcmp(key, "recovery_password"))
+ else if (!strcmp(key, "recovery_password") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
char *str;
@@ -2371,7 +2393,8 @@ int pool_get_config(char *confpath)
pool_config->recovery_password = str;
}
- else if (!strcmp(key, "insert_lock"))
+ else if (!strcmp(key, "insert_lock") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2384,7 +2407,8 @@ int pool_get_config(char *confpath)
pool_config->insert_lock = v;
}
- else if (!strcmp(key, "ignore_leading_white_space"))
+ else if (!strcmp(key, "ignore_leading_white_space") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2397,7 +2421,7 @@ int pool_get_config(char *confpath)
pool_config->ignore_leading_white_space = v;
}
- else if (!strcmp(key, "parallel_mode"))
+ else if (!strcmp(key, "parallel_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2410,7 +2434,7 @@ int pool_get_config(char *confpath)
pool_config->parallel_mode = v;
}
- else if (!strcmp(key, "enable_query_cache"))
+ else if (!strcmp(key, "enable_query_cache") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2423,7 +2447,7 @@ int pool_get_config(char *confpath)
pool_config->enable_query_cache = v;
}
- else if (!strcmp(key, "pgpool2_hostname"))
+ else if (!strcmp(key, "pgpool2_hostname") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2443,7 +2467,7 @@ int pool_get_config(char *confpath)
pool_config->pgpool2_hostname = str;
}
- else if (!strcmp(key, "system_db_hostname"))
+ else if (!strcmp(key, "system_db_hostname") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2462,7 +2486,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_hostname = str;
}
- else if (!strcmp(key, "system_db_port"))
+ else if (!strcmp(key, "system_db_port") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -2475,7 +2499,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_port = v;
}
- else if (!strcmp(key, "system_db_dbname"))
+ else if (!strcmp(key, "system_db_dbname") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2494,7 +2518,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_dbname = str;
}
- else if (!strcmp(key, "system_db_schema"))
+ else if (!strcmp(key, "system_db_schema") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2513,7 +2537,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_schema = str;
}
- else if (!strcmp(key, "system_db_user"))
+ else if (!strcmp(key, "system_db_user") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2532,7 +2556,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_user = str;
}
- else if (!strcmp(key, "system_db_password"))
+ else if (!strcmp(key, "system_db_password") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2551,7 +2575,9 @@ int pool_get_config(char *confpath)
pool_config->system_db_password = str;
}
- else if (!strncmp(key, "backend_hostname", 16))
+ else if (!strncmp(key, "backend_hostname", 16) &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
+ mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
char *str;
@@ -2570,10 +2596,14 @@ int pool_get_config(char *confpath)
fclose(fd);
return(-1);
}
- strncpy(BACKEND_INFO(slot).backend_hostname, str, MAX_DB_HOST_NAMELEN);
+ if (context == INIT_CONFIG ||
+ (context == RELOAD_CONFIG && BACKEND_INFO(slot).backend_status == CON_UNUSED))
+ strncpy(BACKEND_INFO(slot).backend_hostname, str, MAX_DB_HOST_NAMELEN);
}
- else if (!strncmp(key, "backend_port", 12))
+ else if (!strncmp(key, "backend_port", 12) &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
+ mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
@@ -2585,14 +2615,25 @@ int pool_get_config(char *confpath)
return(-1);
}
pool_debug("pool_config: port slot number %d ", slot);
- BACKEND_INFO(slot).backend_port = atoi(yytext);
- BACKEND_INFO(slot).backend_status = CON_CONNECT_WAIT;
+ if (context == INIT_CONFIG)
+ {
+ BACKEND_INFO(slot).backend_port = atoi(yytext);
+ BACKEND_INFO(slot).backend_status = CON_CONNECT_WAIT;
+ }
+ else if (context == RELOAD_CONFIG && BACKEND_INFO(slot).backend_status == CON_UNUSED)
+ {
+ BACKEND_INFO(slot).backend_port = atoi(yytext);
+ BACKEND_INFO(slot).backend_status = CON_DOWN;
+ }
}
- else if (!strncmp(key, "backend_weight", 14))
+ else if (!strncmp(key, "backend_weight", 14) &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
+ mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
double v;
+ BACKEND_STATUS status;
slot = atoi(key + 14);
if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
@@ -2610,13 +2651,21 @@ int pool_get_config(char *confpath)
fclose(fd);
return(-1);
}
+
pool_debug("pool_config: weight slot number %d weight: %f", slot, v);
- pool_config->backend_desc->backend_info[slot].backend_weight = v;
+ if (context == INIT_CONFIG ||
+ (context == RELOAD_CONFIG && (context == RELOAD_CONFIG && (status == CON_UNUSED || status == CON_DOWN))))
+ {
+ pool_config->backend_desc->backend_info[slot].unnormalized_weight = v;
+ }
}
- else if (!strncmp(key, "backend_data_directory", 22))
+ else if (!strncmp(key, "backend_data_directory", 22) &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
+ mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
char *str;
+ BACKEND_STATUS status;
slot = atoi(key + 22);
if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
@@ -2632,9 +2681,12 @@ int pool_get_config(char *confpath)
fclose(fd);
return(-1);
}
- strncpy(BACKEND_INFO(slot).backend_data_directory, str, MAX_PATH_LENGTH);
+ status = BACKEND_INFO(slot).backend_status;
+ if (context == INIT_CONFIG ||
+ (context == RELOAD_CONFIG && (status == CON_UNUSED || status == CON_DOWN)))
+ strncpy(BACKEND_INFO(slot).backend_data_directory, str, MAX_PATH_LENGTH);
}
- else if (!strcmp(key, "log_statement"))
+ else if (!strcmp(key, "log_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2645,7 +2697,7 @@ int pool_get_config(char *confpath)
}
pool_config->log_statement = v;
}
- else if (!strcmp(key, "log_statement"))
+ else if (!strcmp(key, "log_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -2673,7 +2725,7 @@ int pool_get_config(char *confpath)
else
{
- total_weight += BACKEND_INFO(i).backend_weight;
+ total_weight += BACKEND_INFO(i).unnormalized_weight;
pool_config->backend_desc->num_backends = i+1;
}
}
@@ -2695,7 +2747,7 @@ int pool_get_config(char *confpath)
if (pool_config->backend_desc->backend_info[i].backend_port != 0)
{
pool_config->backend_desc->backend_info[i].backend_weight =
- (RAND_MAX) * pool_config->backend_desc->backend_info[i].backend_weight / total_weight;
+ (RAND_MAX) * pool_config->backend_desc->backend_info[i].unnormalized_weight / total_weight;
pool_debug("backend %d weight: %f", i, pool_config->backend_desc->backend_info[i].backend_weight);
}
}
diff --git a/pool_config.l b/pool_config.l
index d2a0be44a..2149f29d8 100644
--- a/pool_config.l
+++ b/pool_config.l
@@ -30,12 +30,15 @@
#include <stdio.h>
#include <string.h>
+#define CHECK_CONTEXT(mask, context) ((mask) & (context))
+
/* to shut off compiler warnings */
int yylex(void);
POOL_CONFIG *pool_config; /* configuration values */
POOL_SYSTEMDB_CONNECTION_POOL *system_db_info;
static unsigned Lineno;
+static char *default_reset_query_list[] = {"ABORT", "RESET ALL", "SET SESSION AUTHORIZATION DEFAULT"};
typedef enum {
POOL_KEY = 1,
@@ -94,15 +97,10 @@ STRING \'([^'\n]|\\.)*\'
%%
-int pool_get_config(char *confpath)
+int pool_init_config(void)
{
- FILE *fd;
- int token;
- char key[1024];
- static char *default_reset_query_list[] = {"ABORT", "RESET ALL", "SET SESSION AUTHORIZATION DEFAULT"};
- static char localhostname[256];
int res;
- double total_weight;
+ static char localhostname[256];
int i;
pool_config = malloc(sizeof(POOL_CONFIG));
@@ -177,6 +175,16 @@ int pool_get_config(char *confpath)
{
clear_host_entry(i);
}
+ return 0;
+}
+
+int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
+{
+ FILE *fd;
+ int token;
+ char key[1024];
+ double total_weight;
+ int i;
#define PARSE_ERROR() pool_error("pool_config: parse error at line %d '%s'", Lineno, yytext)
@@ -222,7 +230,7 @@ int pool_get_config(char *confpath)
pool_debug("value: %s kind: %d", yytext, token);
- if (!strcmp(key, "allow_inet_domain_socket"))
+ if (!strcmp(key, "allow_inet_domain_socket") && CHECK_CONTEXT(INIT_CONFIG, context))
{
/* for backward compatibility */
int v = eval_logical(yytext);
@@ -238,7 +246,7 @@ int pool_get_config(char *confpath)
else
pool_config->listen_addresses = strdup("");
}
- else if (!strcmp(key, "listen_addresses"))
+ else if (!strcmp(key, "listen_addresses") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -257,7 +265,7 @@ int pool_get_config(char *confpath)
pool_config->listen_addresses = str;
}
- else if (!strcmp(key, "port"))
+ else if (!strcmp(key, "port") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -269,7 +277,7 @@ int pool_get_config(char *confpath)
}
pool_config->port = v;
}
- else if (!strcmp(key, "pcp_port"))
+ else if (!strcmp(key, "pcp_port") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -281,7 +289,7 @@ int pool_get_config(char *confpath)
}
pool_config->pcp_port = v;
}
- else if (!strcmp(key, "socket_dir"))
+ else if (!strcmp(key, "socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -299,7 +307,7 @@ int pool_get_config(char *confpath)
}
pool_config->socket_dir = str;
}
- else if (!strcmp(key, "pcp_socket_dir"))
+ else if (!strcmp(key, "pcp_socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -317,7 +325,7 @@ int pool_get_config(char *confpath)
}
pool_config->pcp_socket_dir = str;
}
- else if (!strcmp(key, "pcp_timeout"))
+ else if (!strcmp(key, "pcp_timeout") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -329,7 +337,7 @@ int pool_get_config(char *confpath)
}
pool_config->pcp_timeout = v;
}
- else if (!strcmp(key, "num_init_children"))
+ else if (!strcmp(key, "num_init_children") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -341,7 +349,8 @@ int pool_get_config(char *confpath)
}
pool_config->num_init_children = v;
}
- else if (!strcmp(key, "child_life_time"))
+ else if (!strcmp(key, "child_life_time") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -353,7 +362,8 @@ int pool_get_config(char *confpath)
}
pool_config->child_life_time = v;
}
- else if (!strcmp(key, "connection_life_time"))
+ else if (!strcmp(key, "connection_life_time") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -365,7 +375,8 @@ int pool_get_config(char *confpath)
}
pool_config->connection_life_time = v;
}
- else if (!strcmp(key, "child_max_connections"))
+ else if (!strcmp(key, "child_max_connections") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -377,7 +388,7 @@ int pool_get_config(char *confpath)
}
pool_config->child_max_connections = v;
}
- else if (!strcmp(key, "max_pool"))
+ else if (!strcmp(key, "max_pool") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -389,7 +400,7 @@ int pool_get_config(char *confpath)
}
pool_config->max_pool = v;
}
- else if (!strcmp(key, "logdir"))
+ else if (!strcmp(key, "logdir") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -407,7 +418,8 @@ int pool_get_config(char *confpath)
}
pool_config->logdir = str;
}
- else if (!strcmp(key, "log_connections"))
+ else if (!strcmp(key, "log_connections") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -419,7 +431,8 @@ int pool_get_config(char *confpath)
}
pool_config->log_connections = v;
}
- else if (!strcmp(key, "log_hostname"))
+ else if (!strcmp(key, "log_hostname") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -431,7 +444,8 @@ int pool_get_config(char *confpath)
}
pool_config->log_hostname = v;
}
- else if (!strcmp(key, "enable_pool_hba"))
+ else if (!strcmp(key, "enable_pool_hba") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -443,7 +457,7 @@ int pool_get_config(char *confpath)
}
pool_config->enable_pool_hba = v;
}
- else if (!strcmp(key, "backend_socket_dir"))
+ else if (!strcmp(key, "backend_socket_dir") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -461,7 +475,7 @@ int pool_get_config(char *confpath)
}
pool_config->backend_socket_dir = str;
}
- else if (!strcmp(key, "replication_mode"))
+ else if (!strcmp(key, "replication_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -481,7 +495,7 @@ int pool_get_config(char *confpath)
}
}
- else if (!strcmp(key, "replication_strict"))
+ else if (!strcmp(key, "replication_strict") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -493,7 +507,8 @@ int pool_get_config(char *confpath)
}
pool_config->replication_strict = v;
}
- else if (!strcmp(key, "replication_timeout"))
+ else if (!strcmp(key, "replication_timeout") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -505,7 +520,7 @@ int pool_get_config(char *confpath)
}
pool_config->replication_timeout = v;
}
- else if (!strcmp(key, "load_balance_mode"))
+ else if (!strcmp(key, "load_balance_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -517,7 +532,8 @@ int pool_get_config(char *confpath)
}
pool_config->load_balance_mode = v;
}
- else if (!strcmp(key, "replication_stop_on_mismatch"))
+ else if (!strcmp(key, "replication_stop_on_mismatch") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -530,7 +546,8 @@ int pool_get_config(char *confpath)
pool_debug("replication_stop_on_mismatch: %d", v);
pool_config->replication_stop_on_mismatch = v;
}
- else if (!strcmp(key, "reset_query_list"))
+ else if (!strcmp(key, "reset_query_list") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
char *str;
@@ -554,7 +571,7 @@ int pool_get_config(char *confpath)
}
}
- else if (!strcmp(key, "print_timestamp"))
+ else if (!strcmp(key, "print_timestamp") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -567,7 +584,7 @@ int pool_get_config(char *confpath)
pool_config->print_timestamp = v;
}
- else if (!strcmp(key, "master_slave_mode"))
+ else if (!strcmp(key, "master_slave_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -587,7 +604,7 @@ int pool_get_config(char *confpath)
}
}
- else if (!strcmp(key, "connection_cache"))
+ else if (!strcmp(key, "connection_cache") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -600,7 +617,8 @@ int pool_get_config(char *confpath)
pool_config->connection_cache = v;
}
- else if (!strcmp(key, "health_check_timeout"))
+ else if (!strcmp(key, "health_check_timeout") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -613,7 +631,8 @@ int pool_get_config(char *confpath)
pool_config->health_check_timeout = v;
}
- else if (!strcmp(key, "health_check_period"))
+ else if (!strcmp(key, "health_check_period") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = atoi(yytext);
@@ -626,7 +645,8 @@ int pool_get_config(char *confpath)
pool_config->health_check_period = v;
}
- else if (!strcmp(key, "health_check_user"))
+ else if (!strcmp(key, "health_check_user") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
char *str;
@@ -645,7 +665,8 @@ int pool_get_config(char *confpath)
pool_config->health_check_user = str;
}
- else if (!strcmp(key, "recovery_user"))
+ else if (!strcmp(key, "recovery_user") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
char *str;
@@ -664,7 +685,8 @@ int pool_get_config(char *confpath)
pool_config->recovery_user = str;
}
- else if (!strcmp(key, "recovery_password"))
+ else if (!strcmp(key, "recovery_password") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
char *str;
@@ -683,7 +705,8 @@ int pool_get_config(char *confpath)
pool_config->recovery_password = str;
}
- else if (!strcmp(key, "insert_lock"))
+ else if (!strcmp(key, "insert_lock") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -696,7 +719,8 @@ int pool_get_config(char *confpath)
pool_config->insert_lock = v;
}
- else if (!strcmp(key, "ignore_leading_white_space"))
+ else if (!strcmp(key, "ignore_leading_white_space") &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -709,7 +733,7 @@ int pool_get_config(char *confpath)
pool_config->ignore_leading_white_space = v;
}
- else if (!strcmp(key, "parallel_mode"))
+ else if (!strcmp(key, "parallel_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -722,7 +746,7 @@ int pool_get_config(char *confpath)
pool_config->parallel_mode = v;
}
- else if (!strcmp(key, "enable_query_cache"))
+ else if (!strcmp(key, "enable_query_cache") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -735,7 +759,7 @@ int pool_get_config(char *confpath)
pool_config->enable_query_cache = v;
}
- else if (!strcmp(key, "pgpool2_hostname"))
+ else if (!strcmp(key, "pgpool2_hostname") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -755,7 +779,7 @@ int pool_get_config(char *confpath)
pool_config->pgpool2_hostname = str;
}
- else if (!strcmp(key, "system_db_hostname"))
+ else if (!strcmp(key, "system_db_hostname") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -774,7 +798,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_hostname = str;
}
- else if (!strcmp(key, "system_db_port"))
+ else if (!strcmp(key, "system_db_port") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -787,7 +811,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_port = v;
}
- else if (!strcmp(key, "system_db_dbname"))
+ else if (!strcmp(key, "system_db_dbname") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -806,7 +830,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_dbname = str;
}
- else if (!strcmp(key, "system_db_schema"))
+ else if (!strcmp(key, "system_db_schema") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -825,7 +849,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_schema = str;
}
- else if (!strcmp(key, "system_db_user"))
+ else if (!strcmp(key, "system_db_user") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -844,7 +868,7 @@ int pool_get_config(char *confpath)
pool_config->system_db_user = str;
}
- else if (!strcmp(key, "system_db_password"))
+ else if (!strcmp(key, "system_db_password") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -863,7 +887,9 @@ int pool_get_config(char *confpath)
pool_config->system_db_password = str;
}
- else if (!strncmp(key, "backend_hostname", 16))
+ else if (!strncmp(key, "backend_hostname", 16) &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
+ mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
char *str;
@@ -882,10 +908,14 @@ int pool_get_config(char *confpath)
fclose(fd);
return(-1);
}
- strncpy(BACKEND_INFO(slot).backend_hostname, str, MAX_DB_HOST_NAMELEN);
+ if (context == INIT_CONFIG ||
+ (context == RELOAD_CONFIG && BACKEND_INFO(slot).backend_status == CON_UNUSED))
+ strncpy(BACKEND_INFO(slot).backend_hostname, str, MAX_DB_HOST_NAMELEN);
}
- else if (!strncmp(key, "backend_port", 12))
+ else if (!strncmp(key, "backend_port", 12) &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
+ mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
@@ -897,14 +927,25 @@ int pool_get_config(char *confpath)
return(-1);
}
pool_debug("pool_config: port slot number %d ", slot);
- BACKEND_INFO(slot).backend_port = atoi(yytext);
- BACKEND_INFO(slot).backend_status = CON_CONNECT_WAIT;
+ if (context == INIT_CONFIG)
+ {
+ BACKEND_INFO(slot).backend_port = atoi(yytext);
+ BACKEND_INFO(slot).backend_status = CON_CONNECT_WAIT;
+ }
+ else if (context == RELOAD_CONFIG && BACKEND_INFO(slot).backend_status == CON_UNUSED)
+ {
+ BACKEND_INFO(slot).backend_port = atoi(yytext);
+ BACKEND_INFO(slot).backend_status = CON_DOWN;
+ }
}
- else if (!strncmp(key, "backend_weight", 14))
+ else if (!strncmp(key, "backend_weight", 14) &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
+ mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
double v;
+ BACKEND_STATUS status;
slot = atoi(key + 14);
if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
@@ -922,13 +963,21 @@ int pool_get_config(char *confpath)
fclose(fd);
return(-1);
}
+
pool_debug("pool_config: weight slot number %d weight: %f", slot, v);
- pool_config->backend_desc->backend_info[slot].backend_weight = v;
+ if (context == INIT_CONFIG ||
+ (context == RELOAD_CONFIG && (context == RELOAD_CONFIG && (status == CON_UNUSED || status == CON_DOWN))))
+ {
+ pool_config->backend_desc->backend_info[slot].unnormalized_weight = v;
+ }
}
- else if (!strncmp(key, "backend_data_directory", 22))
+ else if (!strncmp(key, "backend_data_directory", 22) &&
+ CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
+ mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
char *str;
+ BACKEND_STATUS status;
slot = atoi(key + 22);
if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
@@ -944,9 +993,12 @@ int pool_get_config(char *confpath)
fclose(fd);
return(-1);
}
- strncpy(BACKEND_INFO(slot).backend_data_directory, str, MAX_PATH_LENGTH);
+ status = BACKEND_INFO(slot).backend_status;
+ if (context == INIT_CONFIG ||
+ (context == RELOAD_CONFIG && (status == CON_UNUSED || status == CON_DOWN)))
+ strncpy(BACKEND_INFO(slot).backend_data_directory, str, MAX_PATH_LENGTH);
}
- else if (!strcmp(key, "log_statement"))
+ else if (!strcmp(key, "log_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -957,7 +1009,7 @@ int pool_get_config(char *confpath)
}
pool_config->log_statement = v;
}
- else if (!strcmp(key, "log_statement"))
+ else if (!strcmp(key, "log_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
@@ -985,7 +1037,7 @@ int pool_get_config(char *confpath)
else
{
- total_weight += BACKEND_INFO(i).backend_weight;
+ total_weight += BACKEND_INFO(i).unnormalized_weight;
pool_config->backend_desc->num_backends = i+1;
}
}
@@ -1007,7 +1059,7 @@ int pool_get_config(char *confpath)
if (pool_config->backend_desc->backend_info[i].backend_port != 0)
{
pool_config->backend_desc->backend_info[i].backend_weight =
- (RAND_MAX) * pool_config->backend_desc->backend_info[i].backend_weight / total_weight;
+ (RAND_MAX) * pool_config->backend_desc->backend_info[i].unnormalized_weight / total_weight;
pool_debug("backend %d weight: %f", i, pool_config->backend_desc->backend_info[i].backend_weight);
}
}
diff --git a/pool_process_query.c b/pool_process_query.c
index 981e14523..539148df5 100644
--- a/pool_process_query.c
+++ b/pool_process_query.c
@@ -385,6 +385,17 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
return status;
}
+ /* reload config file */
+ if (got_sighup)
+ {
+ pool_get_config(get_config_file_name(), RELOAD_CONFIG);
+ if (pool_config->enable_pool_hba)
+ load_hba(get_hba_file_name());
+ if (pool_config->parallel_mode)
+ pool_memset_system_db_info(system_db_info->info);
+ got_sighup = 0;
+ }
+
first_ready_for_query_received = 0;
/*
@@ -542,11 +553,12 @@ POOL_STATUS pool_parallel_exec(POOL_CONNECTION *frontend,
{
int stime = 5; /* XXX give arbitary time to allow closing idle connections */
- pool_debug("Query: sending HUP signal to parent");
+ pool_debug("Query: sending USR1 signal to parent");
- kill(getppid(), SIGHUP); /* send HUP signal to parent */
+ Req_info->kind = CLOSE_IDLE_REQUEST;
+ kill(getppid(), SIGUSR1); /* send USR1 signal to parent */
- /* we need to loop over here since we will get HUP signal while sleeping */
+ /* we need to loop over here since we will get USR1 signal while sleeping */
while (stime > 0)
{
stime = sleep(stime);
@@ -897,7 +909,7 @@ static POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
check_copy_from_stdin(node);
/*
- * if this is DROP DATABASE command, send HUP signal to parent and
+ * if this is DROP DATABASE command, send USR1 signal to parent and
* ask it to close all idle connections.
* XXX This is overkill. It would be better to close the idle
* connection for the database which DROP DATABASE command tries
@@ -908,11 +920,12 @@ static POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
{
int stime = 5; /* XXX give arbitary time to allow closing idle connections */
- pool_debug("Query: sending HUP signal to parent");
+ pool_debug("Query: sending SIGUSR1 signal to parent");
- kill(getppid(), SIGHUP); /* send HUP signal to parent */
+ Req_info->kind = CLOSE_IDLE_REQUEST;
+ kill(getppid(), SIGUSR1); /* send USR1 signal to parent */
- /* we need to loop over here since we will get HUP signal while sleeping */
+ /* we need to loop over here since we will get USR1 signal while sleeping */
while (stime > 0)
{
stime = sleep(stime);
diff --git a/pool_type.h b/pool_type.h
index 52a6d2d1a..f8f3cd01a 100644
--- a/pool_type.h
+++ b/pool_type.h
@@ -91,6 +91,7 @@ typedef struct {
int backend_port; /* backend port numbers */
BACKEND_STATUS backend_status; /* backend status */
double backend_weight; /* normalized backend load balance ratio */
+ double unnormalized_weight; /* descripted parameter */
char backend_data_directory[MAX_PATH_LENGTH];
} BackendInfo;
[parent: 1e0fc2b5f6b7]