pgpool2.git / summary / log / commit / refs
commit 2f9454eef49cf43d47cf341ad763309d56527cc4
Author: Yugo Nagata <nagata@sraoss.co.jp>
Date: Wed May 15 07:12:58 2013 +0000
Rename watchdog options
pgpool.conf.sample | 108 +++++---
pgpool.conf.sample-master-slave | 107 +++++---
pgpool.conf.sample-replication | 107 +++++---
pgpool.conf.sample-stream | 107 +++++---
pool_config.c | 62 ++---
pool_config.h | 27 +-
pool_config.l | 62 ++---
pool_process_reporting.c | 38 +--
watchdog/Makefile.am | 2 +-
watchdog/Makefile.in | 6 +-
watchdog/watchdog.c | 78 +++---
watchdog/watchdog.h | 12 +-
watchdog/wd_ext.h | 14 +-
watchdog/wd_heartbeat.c | 533 ++++++++++++++++++++++++++++++++++++++++
watchdog/wd_init.c | 4 +-
watchdog/wd_lifecheck.c | 48 ++--
watchdog/wd_list.c | 4 +-
watchdog/wd_udp.c | 533 ----------------------------------------
18 files changed, 1000 insertions(+), 852 deletions(-)
diff --git a/pgpool.conf.sample b/pgpool.conf.sample
index 7d59cdf61..7647f583b 100644
--- a/pgpool.conf.sample
+++ b/pgpool.conf.sample
@@ -74,7 +74,7 @@ enable_pool_hba = off
# Use pool_hba.conf for client authentication
pool_passwd = 'pool_passwd'
# File name of pool_passwd for md5 authentication.
- # "" disables pool_passwd.
+ # "" disables pool_passwd.
# (change requires restart)
authentication_timeout = 60
# Delay in seconds to complete client authentication
@@ -319,14 +319,14 @@ parallel_mode = off
# Activates parallel query mode
# (change requires restart)
pgpool2_hostname = ''
- # Set pgpool2 hostname
+ # Set pgpool2 hostname
# (change requires restart)
# - System DB info -
system_db_hostname = 'localhost'
# (change requires restart)
-system_db_port = 5432
+system_db_port = 5432
# (change requires restart)
system_db_dbname = 'pgpool'
# (change requires restart)
@@ -425,44 +425,40 @@ client_idle_limit_in_recovery = 0
#------------------------------------------------------------------------------
# WATCHDOG
#------------------------------------------------------------------------------
-use_watchdog = off
- # Activates watchdog
-watchdog_mode='udp'
- # Mode of watchdog lifecheck ('udp' or 'query')
+# - Enabling -
+
+use_watchdog = off
+ # Activates watchdog
# (change requires restart)
-clear_memqcache_on_escalation = on
- # Clear all the query cache on shared memory
- # when standby pgpool escalate to active pgpool
- # (= virtual IP holder).
- # This should be off if client connects to pgpool
- # not using virtual IP.
- # (change requires restart)
-wd_escalation_command = ''
- # Executes this command at escalation on new active pgpool.
+# -Connection to up stream servers -
trusted_servers = ''
# trusted server list which are used
# to confirm network connection
# (hostA,hostB,hostC,...)
# (change requires restart)
-delegate_IP = ''
- # delegate IP address
+ping_path = '/bin'
+ # ping command path
# (change requires restart)
+
+# - Watchdog communication Settings -
+
wd_hostname = ''
# Host name or IP address of this watchdog
# (change requires restart)
wd_port = 9000
# port number for watchdog service
# (change requires restart)
-wd_interval = 10
- # lifecheck interval (sec) > 0
- # (change requires restart)
wd_authkey = ''
- # Authentication key for watchdog communication
-ping_path = '/bin'
- # ping command path
+ # Authentication key for watchdog communication
+ # (change requires restart)
+
+# - Virtual IP control Setting -
+
+delegate_IP = ''
+ # delegate IP address
# (change requires restart)
ifconfig_path = '/sbin'
# ifconfig command path
@@ -480,21 +476,54 @@ arping_path = '/usr/sbin' # arping command path
arping_cmd = 'arping -U $_IP_$ -w 1'
# arping command
# (change requires restart)
-wd_udp_port = 9694
- # Port number for UDP heartbeat lifecheck
-wd_udp_keepalive = 2
- # Interval time of sending UDP heartbeat signal (sec)
-wd_udp_deadtime = 30
- # Deadtime interval for UDP heartbeat signal (sec)
-udp_device0 = 'eth0'
+
+# - Behaivor on escalation Setting -
+
+clear_memqcache_on_escalation = on
+ # Clear all the query cache on shared memory
+ # when standby pgpool escalate to active pgpool
+ # (= virtual IP holder).
+ # This should be off if client connects to pgpool
+ # not using virtual IP.
+ # (change requires restart)
+wd_escalation_command = ''
+ # Executes this command at escalation on new active pgpool.
+ # (change requires restart)
+
+# - Lifecheck Setting -
+
+# -- common --
+
+wd_lifecheck_method='heartbeat'
+ # Method of watchdog lifecheck ('heartbeat' or 'query')
+ # (change requires restart)
+wd_interval = 10
+ # lifecheck interval (sec) > 0
+ # (change requires restart)
+
+# -- heartbeat mode --
+
+wd_heartbeat_port = 9694
+ # Port number for heartbeat lifecheck
+ # (change requires restart)
+wd_heartbeat_keepalive = 2
+ # Interval time of sending heartbeat signal (sec)
+ # (change requires restart)
+wd_heartbeat_deadtime = 30
+ # Deadtime interval for heartbeat signal (sec)
+ # (change requires restart)
+heartbeat_device0 = 'eth0'
# Name of NIC device 0 using for
# sending/receiving heartbeat signal
-udp_destination0 = 'host0_ip1'
+ # (change requires restart)
+heartbeat_destination0 = 'host0_ip1'
# Destination host name or IP address
# for sending heartbeat signal using NIC device 0.
+ # (change requires restart)
+#heartbeat_device1 = 'eth1'
+#heartbeat_destination1 = 'host0_ip2'
-#udp_device1 = 'eth1'
-#udp_destination1 = 'host0_ip2'
+# -- query mode --
wd_life_point = 3
# lifecheck retry times
@@ -503,21 +532,26 @@ wd_lifecheck_query = 'SELECT 1'
# lifecheck query to pgpool from watchdog
# (change requires restart)
wd_lifecheck_dbname = 'template1'
- # Database name connected for lifecheck
+ # Database name connected for lifecheck
+ # (change requires restart)
wd_lifecheck_user = 'nobody'
# watchdog user monitoring pgpools in lifecheck
+ # (change requires restart)
wd_lifecheck_password = ''
# Password for watchdog user in lifecheck
+ # (change requires restart)
-
-# Other pgpool Connection Settings
+# - Other pgpool Connection Settings -
#other_pgpool_hostname0 = 'host0'
# Host name or IP address to connect to for other pgpool 0
+ # (change requires restart)
#other_pgpool_port0 = 5432
# Port number for othet pgpool 0
+ # (change requires restart)
#other_wd_port0 = 9000
# Port number for othet watchdog 0
+ # (change requires restart)
#other_pgpool_hostname1 = 'host1'
#other_pgpool_port1 = 5432
#other_wd_port1 = 9000
diff --git a/pgpool.conf.sample-master-slave b/pgpool.conf.sample-master-slave
index f2598b56a..6911ba89c 100644
--- a/pgpool.conf.sample-master-slave
+++ b/pgpool.conf.sample-master-slave
@@ -74,7 +74,7 @@ enable_pool_hba = off
# Use pool_hba.conf for client authentication
pool_passwd = 'pool_passwd'
# File name of pool_passwd for md5 authentication.
- # "" disables pool_passwd.
+ # "" disables pool_passwd.
# (change requires restart)
authentication_timeout = 60
# Delay in seconds to complete client authentication
@@ -318,7 +318,7 @@ parallel_mode = off
# Activates parallel query mode
# (change requires restart)
pgpool2_hostname = ''
- # Set pgpool2 hostname
+ # Set pgpool2 hostname
# (change requires restart)
# - System DB info -
@@ -425,42 +425,40 @@ client_idle_limit_in_recovery = 0
#------------------------------------------------------------------------------
# WATCHDOG
#------------------------------------------------------------------------------
-use_watchdog = off
+
+# - Enabling -
+
+use_watchdog = off
# Activates watchdog
# (change requires restart)
-watchdog_mode='udp'
- # Mode of watchdog lifecheck ('udp' or 'query')
- # (change requires restart)
-clear_memqcache_on_escalation = on
- # Clear all the query cache on shared memory
- # when standby pgpool escalate to active pgpool
- # (= virtual IP holder).
- # This should be off if client connects to pgpool
- # not using virtual IP.
- # (change requires restart)
-wd_escalation_command = ''
- # Executes this command at escalation on new active pgpool.
+
+# -Connection to up stream servers -
+
trusted_servers = ''
# trusted server list which are used
# to confirm network connection
# (hostA,hostB,hostC,...)
# (change requires restart)
-delegate_IP = ''
- # delegate IP address
+ping_path = '/bin'
+ # ping command path
# (change requires restart)
+
+# - Watchdog communication Settings -
+
wd_hostname = ''
# Host name or IP address of this watchdog
# (change requires restart)
wd_port = 9000
# port number for watchdog service
# (change requires restart)
-wd_interval = 10
- # lifecheck interval (sec) > 0
- # (change requires restart)
wd_authkey = ''
- # Authentication key for watchdog communication
-ping_path = '/bin'
- # ping command path
+ # Authentication key for watchdog communication
+ # (change requires restart)
+
+# - Virtual IP control Setting -
+
+delegate_IP = ''
+ # delegate IP address
# (change requires restart)
ifconfig_path = '/sbin'
# ifconfig command path
@@ -478,21 +476,54 @@ arping_path = '/usr/sbin' # arping command path
arping_cmd = 'arping -U $_IP_$ -w 1'
# arping command
# (change requires restart)
-wd_udp_port = 9694
- # Port number for UDP heartbeat lifecheck
-wd_udp_keepalive = 2
- # Interval time of sending UDP heartbeat signal (sec)
-wd_udp_deadtime = 30
- # Deadtime interval for UDP heartbeat signal (sec)
-udp_device0 = 'eth0'
+
+# - Behaivor on escalation Setting -
+
+clear_memqcache_on_escalation = on
+ # Clear all the query cache on shared memory
+ # when standby pgpool escalate to active pgpool
+ # (= virtual IP holder).
+ # This should be off if client connects to pgpool
+ # not using virtual IP.
+ # (change requires restart)
+wd_escalation_command = ''
+ # Executes this command at escalation on new active pgpool.
+ # (change requires restart)
+
+# - Lifecheck Setting -
+
+# -- common --
+
+wd_lifecheck_method='heartbeat'
+ # Method of watchdog lifecheck ('heartbeat' or 'query')
+ # (change requires restart)
+wd_interval = 10
+ # lifecheck interval (sec) > 0
+ # (change requires restart)
+
+# -- heartbeat mode --
+
+wd_heartbeat_port = 9694
+ # Port number for heartbeat lifecheck
+ # (change requires restart)
+wd_heartbeat_keepalive = 2
+ # Interval time of sending heartbeat signal (sec)
+ # (change requires restart)
+wd_heartbeat_deadtime = 30
+ # Deadtime interval for heartbeat signal (sec)
+ # (change requires restart)
+heartbeat_device0 = 'eth0'
# Name of NIC device 0 using for
# sending/receiving heartbeat signal
-udp_destination0 = 'host0_ip1'
+ # (change requires restart)
+heartbeat_destination0 = 'host0_ip1'
# Destination host name or IP address
# for sending heartbeat signal using NIC device 0.
+ # (change requires restart)
+#heartbeat_device1 = 'eth1'
+#heartbeat_destination1 = 'host0_ip2'
-#udp_device1 = 'eth1'
-#udp_destination1 = 'host0_ip2'
+# -- query mode --
wd_life_point = 3
# lifecheck retry times
@@ -501,20 +532,26 @@ wd_lifecheck_query = 'SELECT 1'
# lifecheck query to pgpool from watchdog
# (change requires restart)
wd_lifecheck_dbname = 'template1'
- # Database name connected for lifecheck
+ # Database name connected for lifecheck
+ # (change requires restart)
wd_lifecheck_user = 'nobody'
# watchdog user monitoring pgpools in lifecheck
+ # (change requires restart)
wd_lifecheck_password = ''
# Password for watchdog user in lifecheck
+ # (change requires restart)
-# Other pgpool Connection Settings
+# - Other pgpool Connection Settings -
#other_pgpool_hostname0 = 'host0'
# Host name or IP address to connect to for other pgpool 0
+ # (change requires restart)
#other_pgpool_port0 = 5432
# Port number for othet pgpool 0
+ # (change requires restart)
#other_wd_port0 = 9000
# Port number for othet watchdog 0
+ # (change requires restart)
#other_pgpool_hostname1 = 'host1'
#other_pgpool_port1 = 5432
#other_wd_port1 = 9000
diff --git a/pgpool.conf.sample-replication b/pgpool.conf.sample-replication
index 93b80536f..80b1d6da7 100644
--- a/pgpool.conf.sample-replication
+++ b/pgpool.conf.sample-replication
@@ -74,7 +74,7 @@ enable_pool_hba = off
# Use pool_hba.conf for client authentication
pool_passwd = 'pool_passwd'
# File name of pool_passwd for md5 authentication.
- # "" disables pool_passwd.
+ # "" disables pool_passwd.
# (change requires restart)
authentication_timeout = 60
# Delay in seconds to complete client authentication
@@ -318,7 +318,7 @@ parallel_mode = off
# Activates parallel query mode
# (change requires restart)
pgpool2_hostname = ''
- # Set pgpool2 hostname
+ # Set pgpool2 hostname
# (change requires restart)
# - System DB info -
@@ -424,42 +424,40 @@ client_idle_limit_in_recovery = 0
#------------------------------------------------------------------------------
# WATCHDOG
#------------------------------------------------------------------------------
-use_watchdog = off
+
+# - Enabling -
+
+use_watchdog = off
# Activates watchdog
# (change requires restart)
-watchdog_mode='udp'
- # Mode of watchdog lifecheck ('udp' or 'query')
- # (change requires restart)
-clear_memqcache_on_escalation = on
- # Clear all the query cache on shared memory
- # when standby pgpool escalate to active pgpool
- # (= virtual IP holder).
- # This should be off if client connects to pgpool
- # not using virtual IP.
- # (change requires restart)
-wd_escalation_command = ''
- # Executes this command at escalation on new active pgpool.
+
+# -Connection to up stream servers -
+
trusted_servers = ''
# trusted server list which are used
# to confirm network connection
# (hostA,hostB,hostC,...)
# (change requires restart)
-delegate_IP = ''
- # delegate IP address
+ping_path = '/bin'
+ # ping command path
# (change requires restart)
+
+# - Watchdog communication Settings -
+
wd_hostname = ''
# Host name or IP address of this watchdog
# (change requires restart)
wd_port = 9000
# port number for watchdog service
# (change requires restart)
-wd_interval = 10
- # lifecheck interval (sec) > 0
- # (change requires restart)
wd_authkey = ''
- # Authentication key for watchdog communication
-ping_path = '/bin'
- # ping command path
+ # Authentication key for watchdog communication
+ # (change requires restart)
+
+# - Virtual IP control Setting -
+
+delegate_IP = ''
+ # delegate IP address
# (change requires restart)
ifconfig_path = '/sbin'
# ifconfig command path
@@ -477,21 +475,54 @@ arping_path = '/usr/sbin' # arping command path
arping_cmd = 'arping -U $_IP_$ -w 1'
# arping command
# (change requires restart)
-wd_udp_port = 9694
- # Port number for UDP heartbeat lifecheck
-wd_udp_keepalive = 2
- # Interval time of sending UDP heartbeat signal (sec)
-wd_udp_deadtime = 30
- # Deadtime interval for UDP heartbeat signal (sec)
-udp_device0 = 'eth0'
+
+# - Behaivor on escalation Setting -
+
+clear_memqcache_on_escalation = on
+ # Clear all the query cache on shared memory
+ # when standby pgpool escalate to active pgpool
+ # (= virtual IP holder).
+ # This should be off if client connects to pgpool
+ # not using virtual IP.
+ # (change requires restart)
+wd_escalation_command = ''
+ # Executes this command at escalation on new active pgpool.
+ # (change requires restart)
+
+# - Lifecheck Setting -
+
+# -- common --
+
+wd_lifecheck_method='heartbeat'
+ # Method of watchdog lifecheck ('heartbeat' or 'query')
+ # (change requires restart)
+wd_interval = 10
+ # lifecheck interval (sec) > 0
+ # (change requires restart)
+
+# -- heartbeat mode --
+
+wd_heartbeat_port = 9694
+ # Port number for heartbeat lifecheck
+ # (change requires restart)
+wd_heartbeat_keepalive = 2
+ # Interval time of sending heartbeat signal (sec)
+ # (change requires restart)
+wd_heartbeat_deadtime = 30
+ # Deadtime interval for heartbeat signal (sec)
+ # (change requires restart)
+heartbeat_device0 = 'eth0'
# Name of NIC device 0 using for
# sending/receiving heartbeat signal
-udp_destination0 = 'host0_ip1'
+ # (change requires restart)
+heartbeat_destination0 = 'host0_ip1'
# Destination host name or IP address
# for sending heartbeat signal using NIC device 0.
+ # (change requires restart)
+#heartbeat_device1 = 'eth1'
+#heartbeat_destination1 = 'host0_ip2'
-#udp_device1 = 'eth1'
-#udp_destination1 = 'host0_ip2'
+# -- query mode --
wd_life_point = 3
# lifecheck retry times
@@ -500,20 +531,26 @@ wd_lifecheck_query = 'SELECT 1'
# lifecheck query to pgpool from watchdog
# (change requires restart)
wd_lifecheck_dbname = 'template1'
- # Database name connected for lifecheck
+ # Database name connected for lifecheck
+ # (change requires restart)
wd_lifecheck_user = 'nobody'
# watchdog user monitoring pgpools in lifecheck
+ # (change requires restart)
wd_lifecheck_password = ''
# Password for watchdog user in lifecheck
+ # (change requires restart)
-# Other pgpool Connection Settings
+# - Other pgpool Connection Settings -
#other_pgpool_hostname0 = 'host0'
# Host name or IP address to connect to for other pgpool 0
+ # (change requires restart)
#other_pgpool_port0 = 5432
# Port number for othet pgpool 0
+ # (change requires restart)
#other_wd_port0 = 9000
# Port number for othet watchdog 0
+ # (change requires restart)
#other_pgpool_hostname1 = 'host1'
#other_pgpool_port1 = 5432
#other_wd_port1 = 9000
diff --git a/pgpool.conf.sample-stream b/pgpool.conf.sample-stream
index fad2fbfc9..85153454a 100644
--- a/pgpool.conf.sample-stream
+++ b/pgpool.conf.sample-stream
@@ -74,7 +74,7 @@ enable_pool_hba = off
# Use pool_hba.conf for client authentication
pool_passwd = 'pool_passwd'
# File name of pool_passwd for md5 authentication.
- # "" disables pool_passwd.
+ # "" disables pool_passwd.
# (change requires restart)
authentication_timeout = 60
# Delay in seconds to complete client authentication
@@ -318,7 +318,7 @@ parallel_mode = off
# Activates parallel query mode
# (change requires restart)
pgpool2_hostname = ''
- # Set pgpool2 hostname
+ # Set pgpool2 hostname
# (change requires restart)
# - System DB info -
@@ -424,42 +424,40 @@ client_idle_limit_in_recovery = 0
#------------------------------------------------------------------------------
# WATCHDOG
#------------------------------------------------------------------------------
-use_watchdog = off
+
+# - Enabling -
+
+use_watchdog = off
# Activates watchdog
# (change requires restart)
-watchdog_mode='udp'
- # Mode of watchdog lifecheck ('udp' or 'query')
- # (change requires restart)
-clear_memqcache_on_escalation = on
- # Clear all the query cache on shared memory
- # when standby pgpool escalate to active pgpool
- # (= virtual IP holder).
- # This should be off if client connects to pgpool
- # not using virtual IP.
- # (change requires restart)
-wd_escalation_command = ''
- # Executes this command at escalation on new active pgpool.
+
+# -Connection to up stream servers -
+
trusted_servers = ''
# trusted server list which are used
# to confirm network connection
# (hostA,hostB,hostC,...)
# (change requires restart)
-delegate_IP = ''
- # delegate IP address
+ping_path = '/bin'
+ # ping command path
# (change requires restart)
+
+# - Watchdog communication Settings -
+
wd_hostname = ''
# Host name or IP address of this watchdog
# (change requires restart)
wd_port = 9000
# port number for watchdog service
# (change requires restart)
-wd_interval = 10
- # lifecheck interval (sec) > 0
- # (change requires restart)
wd_authkey = ''
- # Authentication key for watchdog communication
-ping_path = '/bin'
- # ping command path
+ # Authentication key for watchdog communication
+ # (change requires restart)
+
+# - Virtual IP control Setting -
+
+delegate_IP = ''
+ # delegate IP address
# (change requires restart)
ifconfig_path = '/sbin'
# ifconfig command path
@@ -477,21 +475,54 @@ arping_path = '/usr/sbin' # arping command path
arping_cmd = 'arping -U $_IP_$ -w 1'
# arping command
# (change requires restart)
-wd_udp_port = 9694
- # Port number for UDP heartbeat lifecheck
-wd_udp_keepalive = 2
- # Interval time of sending UDP heartbeat signal (sec)
-wd_udp_deadtime = 30
- # Deadtime interval for UDP heartbeat signal (sec)
-udp_device0 = 'eth0'
+
+# - Behaivor on escalation Setting -
+
+clear_memqcache_on_escalation = on
+ # Clear all the query cache on shared memory
+ # when standby pgpool escalate to active pgpool
+ # (= virtual IP holder).
+ # This should be off if client connects to pgpool
+ # not using virtual IP.
+ # (change requires restart)
+wd_escalation_command = ''
+ # Executes this command at escalation on new active pgpool.
+ # (change requires restart)
+
+# - Lifecheck Setting -
+
+# -- common --
+
+wd_lifecheck_method='heartbeat'
+ # Method of watchdog lifecheck ('heartbeat' or 'query')
+ # (change requires restart)
+wd_interval = 10
+ # lifecheck interval (sec) > 0
+ # (change requires restart)
+
+# -- heartbeat mode --
+
+wd_heartbeat_port = 9694
+ # Port number for heartbeat lifecheck
+ # (change requires restart)
+wd_heartbeat_keepalive = 2
+ # Interval time of sending heartbeat signal (sec)
+ # (change requires restart)
+wd_heartbeat_deadtime = 30
+ # Deadtime interval for heartbeat signal (sec)
+ # (change requires restart)
+heartbeat_device0 = 'eth0'
# Name of NIC device 0 using for
# sending/receiving heartbeat signal
-udp_destination0 = 'host0_ip1'
+ # (change requires restart)
+heartbeat_destination0 = 'host0_ip1'
# Destination host name or IP address
# for sending heartbeat signal using NIC device 0.
+ # (change requires restart)
+#heartbeat_device1 = 'eth1'
+#heartbeat_destination1 = 'host0_ip2'
-#udp_device1 = 'eth1'
-#udp_destination1 = 'host0_ip2'
+# -- query mode --
wd_life_point = 3
# lifecheck retry times
@@ -500,20 +531,26 @@ wd_lifecheck_query = 'SELECT 1'
# lifecheck query to pgpool from watchdog
# (change requires restart)
wd_lifecheck_dbname = 'template1'
- # Database name connected for lifecheck
+ # Database name connected for lifecheck
+ # (change requires restart)
wd_lifecheck_user = 'nobody'
# watchdog user monitoring pgpools in lifecheck
+ # (change requires restart)
wd_lifecheck_password = ''
# Password for watchdog user in lifecheck
+ # (change requires restart)
-# Other pgpool Connection Settings
+# - Other pgpool Connection Settings -
#other_pgpool_hostname0 = 'host0'
# Host name or IP address to connect to for other pgpool 0
+ # (change requires restart)
#other_pgpool_port0 = 5432
# Port number for othet pgpool 0
+ # (change requires restart)
#other_wd_port0 = 9000
# Port number for othet watchdog 0
+ # (change requires restart)
#other_pgpool_hostname1 = 'host1'
#other_pgpool_port1 = 5432
#other_wd_port1 = 9000
diff --git a/pool_config.c b/pool_config.c
index 40bd2159b..1589d7ca7 100644
--- a/pool_config.c
+++ b/pool_config.c
@@ -410,7 +410,7 @@ char *yytext;
*
* $Header$
*
- * pgpool: a language independent connection pool server for PostgreSQL
+ * pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2013 PgPool Global Development Group
@@ -1780,7 +1780,7 @@ int pool_init_config(void)
* add for watchdog
*/
pool_config->use_watchdog = 0;
- pool_config->watchdog_mode = MODE_UDP;
+ pool_config->wd_lifecheck_method = MODE_HEARTBEAT;
pool_config->clear_memqcache_on_escalation = 1;
pool_config->wd_escalation_command = "";
pool_config->trusted_servers = "";
@@ -1806,10 +1806,10 @@ int pool_init_config(void)
pool_config->wd_lifecheck_dbname = "template1";
pool_config->wd_lifecheck_user = "nobody";
pool_config->wd_lifecheck_password = "";
- pool_config->wd_udp_port = 9694;
- pool_config->wd_udp_keepalive = 2;
- pool_config->wd_udp_deadtime = 30;
- pool_config->num_udp_if = 0;
+ pool_config->wd_heartbeat_port = 9694;
+ pool_config->wd_heartbeat_keepalive = 2;
+ pool_config->wd_heartbeat_deadtime = 30;
+ pool_config->num_hb_if = 0;
pool_config->memory_cache_enabled = 0;
pool_config->memqcache_method = "shmem";
@@ -1844,7 +1844,7 @@ int pool_init_config(void)
return 0;
}
-/*
+/*
* Add regex expression to patterns array
* The supported type are: black_function_list and white_function_list
* Return 0 on error, 1 on success
@@ -1920,7 +1920,7 @@ int add_regex_pattern(char *type, char *s)
return 1;
}
-/*
+/*
* Dynamically grow the regex pattern array
* The array start with PATTERN_ARR_SIZE storage place, if required
* it will grow of PATTERN_ARR_SIZE more each time.
@@ -2001,7 +2001,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
token = yylex();
if (token == 0)
{
- break;
+ break;
}
if (token == POOL_PARSE_ERROR)
{
@@ -3826,7 +3826,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
pool_config->wd_lifecheck_password = str;
}
- else if (!strcmp(key, "watchdog_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
+ else if (!strcmp(key, "wd_lifecheck_method") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -3843,15 +3843,15 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
return(-1);
}
- if (strcmp(str, MODE_UDP) && strcmp(str, MODE_QUERY))
+ if (strcmp(str, MODE_HEARTBEAT) && strcmp(str, MODE_QUERY))
{
- pool_error("pool_config: %s must be either \"udp\" or \"query\"", key);
+ pool_error("pool_config: %s must be either \"heartbeat\" or \"query\"", key);
fclose(fd);
return(-1);
}
- pool_config->watchdog_mode = str;
+ pool_config->wd_lifecheck_method = str;
}
- else if (!strcmp(key, "wd_udp_port") && CHECK_CONTEXT(INIT_CONFIG, context))
+ else if (!strcmp(key, "wd_heartbeat_port") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -3861,9 +3861,9 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
fclose(fd);
return(-1);
}
- pool_config->wd_udp_port = v;
+ pool_config->wd_heartbeat_port = v;
}
- else if (!strcmp(key, "wd_udp_keepalive") && CHECK_CONTEXT(INIT_CONFIG, context))
+ else if (!strcmp(key, "wd_heartbeat_keepalive") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -3873,9 +3873,9 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
fclose(fd);
return(-1);
}
- pool_config->wd_udp_keepalive = v;
+ pool_config->wd_heartbeat_keepalive = v;
}
- else if (!strcmp(key, "wd_udp_deadtime") && CHECK_CONTEXT(INIT_CONFIG, context))
+ else if (!strcmp(key, "wd_heartbeat_deadtime") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -3885,7 +3885,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
fclose(fd);
return(-1);
}
- pool_config->wd_udp_deadtime = v;
+ pool_config->wd_heartbeat_deadtime = v;
}
else if (!strcmp(key, "wd_authkey") &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
@@ -3907,7 +3907,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
pool_config->wd_authkey = str;
}
- else if (!strncmp(key, "udp_device", 10) &&
+ else if (!strncmp(key, "heartbeat_device", 16) &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
mypid == getpid()) /* this parameter must be modified by parent pid */
{
@@ -3917,7 +3917,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
slot = atoi(key + 10) ;
if (slot < 0 || slot >= WD_MAX_IF_NUM)
{
- pool_error("pool_config: pgpool number %s for udp_device out of range", key);
+ pool_error("pool_config: pgpool number %s for heartbeat_device out of range", key);
fclose(fd);
return(-1);
}
@@ -3930,12 +3930,12 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
if (context == INIT_CONFIG || (context == RELOAD_CONFIG ))
{
- strlcpy(WD_UDP_IF(slot).if_name, str, WD_MAX_IF_NAME_LEN);
- pool_config->num_udp_if = slot + 1;
+ strlcpy(WD_HB_IF(slot).if_name, str, WD_MAX_IF_NAME_LEN);
+ pool_config->num_hb_if = slot + 1;
}
}
- else if (!strncmp(key, "udp_destination", 15) &&
+ else if (!strncmp(key, "heartbeat_destination", 21) &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
mypid == getpid()) /* this parameter must be modified by parent pid */
{
@@ -3945,7 +3945,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
slot = atoi(key + 15) ;
if (slot < 0 || slot >= WD_MAX_IF_NUM)
{
- pool_error("pool_config: pgpool number %s for udp_destination out of range", key);
+ pool_error("pool_config: pgpool number %s for heartbeat_destination out of range", key);
fclose(fd);
return(-1);
}
@@ -3957,7 +3957,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
return(-1);
}
if (context == INIT_CONFIG || (context == RELOAD_CONFIG ))
- strlcpy(WD_UDP_IF(slot).addr, str, WD_MAX_IF_NAME_LEN);
+ strlcpy(WD_HB_IF(slot).addr, str, WD_MAX_HOST_NAMELEN);
}
else if (!strcmp(key, "ssl") && CHECK_CONTEXT(INIT_CONFIG, context))
@@ -4007,7 +4007,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->ssl_key = str;
}
- else if (!strcmp(key, "ssl_ca_cert") &&
+ else if (!strcmp(key, "ssl_ca_cert") &&
CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -4026,7 +4026,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->ssl_ca_cert = str;
}
- else if (!strcmp(key, "ssl_ca_cert_dir") &&
+ else if (!strcmp(key, "ssl_ca_cert_dir") &&
CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -4360,14 +4360,14 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
pool_config->backend_desc->num_backends = i+1;
/* intialize backend_hostname with a default socket path if empty */
- if (*(BACKEND_INFO(i).backend_hostname) == '\0')
+ if (*(BACKEND_INFO(i).backend_hostname) == '\0')
{
if (pool_config->backend_socket_dir == NULL)
{
pool_debug("pool_config: empty backend_hostname%d, use PostgreSQL's default unix socket path (%s)", i, DEFAULT_SOCKET_DIR);
strlcpy(BACKEND_INFO(i).backend_hostname, DEFAULT_SOCKET_DIR, MAX_DB_HOST_NAMELEN);
}
- else /* DEPRECATED. backward compatibility with older version. Use backend_socket_dir*/
+ else /* DEPRECATED. backward compatibility with older version. Use backend_socket_dir*/
{
pool_debug("pool_config: empty backend_hostname%d, use backend_socket_dir as unix socket path (%s)", i, pool_config->backend_socket_dir);
strlcpy(BACKEND_INFO(i).backend_hostname, pool_config->backend_socket_dir, MAX_DB_HOST_NAMELEN);
@@ -4473,7 +4473,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
#endif
}
- if (strcmp(pool_config->recovery_1st_stage_command, "") ||
+ if (strcmp(pool_config->recovery_1st_stage_command, "") ||
strcmp(pool_config->recovery_2nd_stage_command, ""))
{
for (i=0;i<MAX_CONNECTION_SLOTS;i++)
diff --git a/pool_config.h b/pool_config.h
index 4829b8b2a..425fd7f6b 100644
--- a/pool_config.h
+++ b/pool_config.h
@@ -3,7 +3,7 @@
*
* $Header$
*
- * pgpool: a language independent connection pool server for PostgreSQL
+ * pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2013 PgPool Global Development Group
@@ -34,11 +34,14 @@
/*
* Master/slave sub mode
*/
-#define MODE_STREAMREP "stream" /* Streaming Replication */
-#define MODE_SLONY "slony" /* Slony-I */
+#define MODE_STREAMREP "stream" /* Streaming Replication */
+#define MODE_SLONY "slony" /* Slony-I */
-#define MODE_UDP "udp"
-#define MODE_QUERY "query"
+/*
+ * watchdog lifecheck method
+ */
+#define MODE_HEARTBEAT "heartbeat"
+#define MODE_QUERY "query"
/*
* Regex support in white and black list function
@@ -223,12 +226,12 @@ typedef struct {
* add for watchdog
*/
int use_watchdog; /* if non 0, use watchdog */
- char *watchdog_mode; /* mode of lifecheck mode. 'udp' or 'query' */
+ char *wd_lifecheck_method; /* method of lifecheck. 'heartbeat' or 'query' */
int clear_memqcache_on_escalation; /* if no 0, clear query cache on shmem when escalating */
char *wd_escalation_command; /* Executes this command at escalation on new active pgpool.*/
char *wd_hostname; /* watchdog hostname */
int wd_port; /* watchdog port */
- WdDesc * other_wd; /* watchdog lists */
+ WdDesc * other_wd; /* watchdog lists */
char * trusted_servers; /* icmp reachable server list (A,B,C) */
char * delegate_IP; /* delegate IP address */
int wd_interval; /* lifecheck interval (sec) */
@@ -244,11 +247,11 @@ typedef struct {
char *wd_lifecheck_dbname; /* Database name connected for lifecheck */
char *wd_lifecheck_user; /* PostgreSQL user name for watchdog */
char *wd_lifecheck_password; /* password for watchdog user */
- int wd_udp_port; /* Port number for UDP heartbeat lifecheck */
- int wd_udp_keepalive; /* Interval time of sending UDP heartbeat signal (sec) */
- int wd_udp_deadtime; /* Deadtime interval for UDP heartbeat signal (sec) */
- WdUdpIf udp_if[WD_MAX_IF_NUM]; /* interface devices */
- int num_udp_if; /* number of interface devices */
+ int wd_heartbeat_port; /* Port number for heartbeat lifecheck */
+ int wd_heartbeat_keepalive; /* Interval time of sending heartbeat signal (sec) */
+ int wd_heartbeat_deadtime; /* Deadtime interval for heartbeat signal (sec) */
+ WdHbIf hb_if[WD_MAX_IF_NUM]; /* interface devices */
+ int num_hb_if; /* number of interface devices */
} POOL_CONFIG;
typedef enum {
diff --git a/pool_config.l b/pool_config.l
index 84ed59370..a43d400d7 100644
--- a/pool_config.l
+++ b/pool_config.l
@@ -3,7 +3,7 @@
*
* $Header$
*
- * pgpool: a language independent connection pool server for PostgreSQL
+ * pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2013 PgPool Global Development Group
@@ -233,7 +233,7 @@ int pool_init_config(void)
* add for watchdog
*/
pool_config->use_watchdog = 0;
- pool_config->watchdog_mode = MODE_UDP;
+ pool_config->wd_lifecheck_method = MODE_HEARTBEAT;
pool_config->clear_memqcache_on_escalation = 1;
pool_config->wd_escalation_command = "";
pool_config->trusted_servers = "";
@@ -259,10 +259,10 @@ int pool_init_config(void)
pool_config->wd_lifecheck_dbname = "template1";
pool_config->wd_lifecheck_user = "nobody";
pool_config->wd_lifecheck_password = "";
- pool_config->wd_udp_port = 9694;
- pool_config->wd_udp_keepalive = 2;
- pool_config->wd_udp_deadtime = 30;
- pool_config->num_udp_if = 0;
+ pool_config->wd_heartbeat_port = 9694;
+ pool_config->wd_heartbeat_keepalive = 2;
+ pool_config->wd_heartbeat_deadtime = 30;
+ pool_config->num_hb_if = 0;
pool_config->memory_cache_enabled = 0;
pool_config->memqcache_method = "shmem";
@@ -297,7 +297,7 @@ int pool_init_config(void)
return 0;
}
-/*
+/*
* Add regex expression to patterns array
* The supported type are: black_function_list and white_function_list
* Return 0 on error, 1 on success
@@ -373,7 +373,7 @@ int add_regex_pattern(char *type, char *s)
return 1;
}
-/*
+/*
* Dynamically grow the regex pattern array
* The array start with PATTERN_ARR_SIZE storage place, if required
* it will grow of PATTERN_ARR_SIZE more each time.
@@ -454,7 +454,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
token = yylex();
if (token == 0)
{
- break;
+ break;
}
if (token == POOL_PARSE_ERROR)
{
@@ -2279,7 +2279,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
pool_config->wd_lifecheck_password = str;
}
- else if (!strcmp(key, "watchdog_mode") && CHECK_CONTEXT(INIT_CONFIG, context))
+ else if (!strcmp(key, "wd_lifecheck_method") && CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2296,15 +2296,15 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
return(-1);
}
- if (strcmp(str, MODE_UDP) && strcmp(str, MODE_QUERY))
+ if (strcmp(str, MODE_HEARTBEAT) && strcmp(str, MODE_QUERY))
{
- pool_error("pool_config: %s must be either \"udp\" or \"query\"", key);
+ pool_error("pool_config: %s must be either \"heartbeat\" or \"query\"", key);
fclose(fd);
return(-1);
}
- pool_config->watchdog_mode = str;
+ pool_config->wd_lifecheck_method = str;
}
- else if (!strcmp(key, "wd_udp_port") && CHECK_CONTEXT(INIT_CONFIG, context))
+ else if (!strcmp(key, "wd_heartbeat_port") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -2314,9 +2314,9 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
fclose(fd);
return(-1);
}
- pool_config->wd_udp_port = v;
+ pool_config->wd_heartbeat_port = v;
}
- else if (!strcmp(key, "wd_udp_keepalive") && CHECK_CONTEXT(INIT_CONFIG, context))
+ else if (!strcmp(key, "wd_heartbeat_keepalive") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -2326,9 +2326,9 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
fclose(fd);
return(-1);
}
- pool_config->wd_udp_keepalive = v;
+ pool_config->wd_heartbeat_keepalive = v;
}
- else if (!strcmp(key, "wd_udp_deadtime") && CHECK_CONTEXT(INIT_CONFIG, context))
+ else if (!strcmp(key, "wd_heartbeat_deadtime") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -2338,7 +2338,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
fclose(fd);
return(-1);
}
- pool_config->wd_udp_deadtime = v;
+ pool_config->wd_heartbeat_deadtime = v;
}
else if (!strcmp(key, "wd_authkey") &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
@@ -2360,7 +2360,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
pool_config->wd_authkey = str;
}
- else if (!strncmp(key, "udp_device", 10) &&
+ else if (!strncmp(key, "heartbeat_device", 16) &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
mypid == getpid()) /* this parameter must be modified by parent pid */
{
@@ -2370,7 +2370,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
slot = atoi(key + 10) ;
if (slot < 0 || slot >= WD_MAX_IF_NUM)
{
- pool_error("pool_config: pgpool number %s for udp_device out of range", key);
+ pool_error("pool_config: pgpool number %s for heartbeat_device out of range", key);
fclose(fd);
return(-1);
}
@@ -2383,12 +2383,12 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
if (context == INIT_CONFIG || (context == RELOAD_CONFIG ))
{
- strlcpy(WD_UDP_IF(slot).if_name, str, WD_MAX_IF_NAME_LEN);
- pool_config->num_udp_if = slot + 1;
+ strlcpy(WD_HB_IF(slot).if_name, str, WD_MAX_IF_NAME_LEN);
+ pool_config->num_hb_if = slot + 1;
}
}
- else if (!strncmp(key, "udp_destination", 15) &&
+ else if (!strncmp(key, "heartbeat_destination", 21) &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
mypid == getpid()) /* this parameter must be modified by parent pid */
{
@@ -2398,7 +2398,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
slot = atoi(key + 15) ;
if (slot < 0 || slot >= WD_MAX_IF_NUM)
{
- pool_error("pool_config: pgpool number %s for udp_destination out of range", key);
+ pool_error("pool_config: pgpool number %s for heartbeat_destination out of range", key);
fclose(fd);
return(-1);
}
@@ -2410,7 +2410,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
return(-1);
}
if (context == INIT_CONFIG || (context == RELOAD_CONFIG ))
- strlcpy(WD_UDP_IF(slot).addr, str, WD_MAX_IF_NAME_LEN);
+ strlcpy(WD_HB_IF(slot).addr, str, WD_MAX_HOST_NAMELEN);
}
else if (!strcmp(key, "ssl") && CHECK_CONTEXT(INIT_CONFIG, context))
@@ -2460,7 +2460,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->ssl_key = str;
}
- else if (!strcmp(key, "ssl_ca_cert") &&
+ else if (!strcmp(key, "ssl_ca_cert") &&
CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2479,7 +2479,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->ssl_ca_cert = str;
}
- else if (!strcmp(key, "ssl_ca_cert_dir") &&
+ else if (!strcmp(key, "ssl_ca_cert_dir") &&
CHECK_CONTEXT(INIT_CONFIG, context))
{
char *str;
@@ -2813,14 +2813,14 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
pool_config->backend_desc->num_backends = i+1;
/* intialize backend_hostname with a default socket path if empty */
- if (*(BACKEND_INFO(i).backend_hostname) == '\0')
+ if (*(BACKEND_INFO(i).backend_hostname) == '\0')
{
if (pool_config->backend_socket_dir == NULL)
{
pool_debug("pool_config: empty backend_hostname%d, use PostgreSQL's default unix socket path (%s)", i, DEFAULT_SOCKET_DIR);
strlcpy(BACKEND_INFO(i).backend_hostname, DEFAULT_SOCKET_DIR, MAX_DB_HOST_NAMELEN);
}
- else /* DEPRECATED. backward compatibility with older version. Use backend_socket_dir*/
+ else /* DEPRECATED. backward compatibility with older version. Use backend_socket_dir*/
{
pool_debug("pool_config: empty backend_hostname%d, use backend_socket_dir as unix socket path (%s)", i, pool_config->backend_socket_dir);
strlcpy(BACKEND_INFO(i).backend_hostname, pool_config->backend_socket_dir, MAX_DB_HOST_NAMELEN);
@@ -2926,7 +2926,7 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
#endif
}
- if (strcmp(pool_config->recovery_1st_stage_command, "") ||
+ if (strcmp(pool_config->recovery_1st_stage_command, "") ||
strcmp(pool_config->recovery_2nd_stage_command, ""))
{
for (i=0;i<MAX_CONNECTION_SLOTS;i++)
diff --git a/pool_process_reporting.c b/pool_process_reporting.c
index 358759e7e..7c7005c7d 100644
--- a/pool_process_reporting.c
+++ b/pool_process_reporting.c
@@ -630,9 +630,9 @@ POOL_REPORT_CONFIG* get_config(int *nrows)
strncpy(status[i].desc, "non 0 if operating in use_watchdog", POOLCONFIG_MAXDESCLEN);
i++;
- strncpy(status[i].name, "watchdog_mode", POOLCONFIG_MAXNAMELEN);
- snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", pool_config->watchdog_mode);
- strncpy(status[i].desc, "mode of watchdog lifecheck", POOLCONFIG_MAXDESCLEN);
+ strncpy(status[i].name, "wd_lifecheck_method", POOLCONFIG_MAXNAMELEN);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", pool_config->wd_lifecheck_method);
+ strncpy(status[i].desc, "method of watchdog lifecheck", POOLCONFIG_MAXDESCLEN);
i++;
strncpy(status[i].name, "clear_memqcache_on_escalation", POOLCONFIG_MAXNAMELEN);
@@ -700,19 +700,19 @@ POOL_REPORT_CONFIG* get_config(int *nrows)
strncpy(status[i].desc, "send ARP REQUESTi to neighbour host", POOLCONFIG_MAXDESCLEN);
i++;
- strncpy(status[i].name, "wd_udp_port", POOLCONFIG_MAXNAMELEN);
- snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->wd_udp_port);
- strncpy(status[i].desc, "port number for UDP heartbeat lifecheck", POOLCONFIG_MAXDESCLEN);
+ strncpy(status[i].name, "wd_heartbeat_port", POOLCONFIG_MAXNAMELEN);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->wd_heartbeat_port);
+ strncpy(status[i].desc, "port number for heartbeat lifecheck", POOLCONFIG_MAXDESCLEN);
i++;
- strncpy(status[i].name, "wd_udp_keepalive", POOLCONFIG_MAXNAMELEN);
- snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->wd_udp_keepalive);
- strncpy(status[i].desc, "interval time of sending UDP heartbeat siganl (sec)", POOLCONFIG_MAXDESCLEN);
+ strncpy(status[i].name, "wd_heartbeat_keepalive", POOLCONFIG_MAXNAMELEN);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->wd_heartbeat_keepalive);
+ strncpy(status[i].desc, "interval time of sending heartbeat siganl (sec)", POOLCONFIG_MAXDESCLEN);
i++;
- strncpy(status[i].name, "wd_udp_deadtime", POOLCONFIG_MAXNAMELEN);
- snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->wd_udp_deadtime);
- strncpy(status[i].desc, "deadtime interval for UDP heartbeat siganl (sec)", POOLCONFIG_MAXDESCLEN);
+ strncpy(status[i].name, "wd_heartbeat_deadtime", POOLCONFIG_MAXNAMELEN);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->wd_heartbeat_deadtime);
+ strncpy(status[i].desc, "deadtime interval for heartbeat siganl (sec)", POOLCONFIG_MAXDESCLEN);
i++;
strncpy(status[i].name, "wd_life_point", POOLCONFIG_MAXNAMELEN);
@@ -905,15 +905,15 @@ POOL_REPORT_CONFIG* get_config(int *nrows)
}
- for (j =0; j < pool_config->num_udp_if; j++)
+ for (j =0; j < pool_config->num_hb_if; j++)
{
- snprintf(status[i].name, POOLCONFIG_MAXNAMELEN, "udp_device%d", j);
- snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", WD_UDP_IF(j).if_name);
+ snprintf(status[i].name, POOLCONFIG_MAXNAMELEN, "heartbeat_device%d", j);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", WD_HB_IF(j).if_name);
snprintf(status[i].desc, POOLCONFIG_MAXDESCLEN, "name of NIC device #%d for sending hearbeat", j);
i++;
- snprintf(status[i].name, POOLCONFIG_MAXNAMELEN, "udp_destination%d", j);
- snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", WD_UDP_IF(j).addr);
+ snprintf(status[i].name, POOLCONFIG_MAXNAMELEN, "heartbeat_destination%d", j);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", WD_HB_IF(j).addr);
snprintf(status[i].desc, POOLCONFIG_MAXDESCLEN, "destination for sending heartbeat using NIC device %d", j);
i++;
}
@@ -1155,7 +1155,7 @@ POOL_REPORT_POOLS* get_pools(int *nrows)
{
proc_id = process_info[child].pid;
pi = pool_get_process_info(proc_id);
-
+
for (pool = 0; pool < pool_config->max_pool; pool++)
{
for (backend_id = 0; backend_id < NUM_BACKENDS; backend_id++)
@@ -1352,7 +1352,7 @@ POOL_REPORT_PROCESSES* get_processes(int *nrows)
{
proc_id = process_info[child].pid;
pi = pool_get_process_info(proc_id);
-
+
snprintf(processes[child].pool_pid, POOLCONFIG_MAXCOUNTLEN, "%d", proc_id);
strftime(processes[child].start_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pi->start_time));
strncpy(processes[child].database, "", POOLCONFIG_MAXIDENTLEN);
diff --git a/watchdog/Makefile.am b/watchdog/Makefile.am
index 861c2db38..48ff9508e 100644
--- a/watchdog/Makefile.am
+++ b/watchdog/Makefile.am
@@ -11,7 +11,7 @@ lib_watchdog_a_SOURCES = \
wd_list.c \
wd_packet.c \
wd_ping.c \
- wd_udp.c \
+ wd_heartbeat.c \
wd_interlock.c
AM_CPPFLAGS = -D_GNU_SOURCE -I .. -I @PGSQL_INCLUDE_DIR@
diff --git a/watchdog/Makefile.in b/watchdog/Makefile.in
index 45f78601a..e8f3d4a92 100644
--- a/watchdog/Makefile.in
+++ b/watchdog/Makefile.in
@@ -57,7 +57,7 @@ lib_watchdog_a_LIBADD =
am_lib_watchdog_a_OBJECTS = watchdog.$(OBJEXT) wd_child.$(OBJEXT) \
wd_if.$(OBJEXT) wd_init.$(OBJEXT) wd_lifecheck.$(OBJEXT) \
wd_list.$(OBJEXT) wd_packet.$(OBJEXT) wd_ping.$(OBJEXT) \
- wd_udp.$(OBJEXT) wd_interlock.$(OBJEXT)
+ wd_heartbeat.$(OBJEXT) wd_interlock.$(OBJEXT)
lib_watchdog_a_OBJECTS = $(am_lib_watchdog_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -212,7 +212,7 @@ lib_watchdog_a_SOURCES = \
wd_list.c \
wd_packet.c \
wd_ping.c \
- wd_udp.c \
+ wd_heartbeat.c \
wd_interlock.c
AM_CPPFLAGS = -D_GNU_SOURCE -I .. -I @PGSQL_INCLUDE_DIR@
@@ -266,6 +266,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/watchdog.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_child.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_heartbeat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_if.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_init.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_interlock.Po@am__quote@
@@ -273,7 +274,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_list.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_packet.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_ping.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_udp.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/watchdog/watchdog.c b/watchdog/watchdog.c
index 9f31362c0..50de1aa35 100644
--- a/watchdog/watchdog.c
+++ b/watchdog/watchdog.c
@@ -3,7 +3,7 @@
*
* Handles watchdog connection, and protocol communication with pgpool-II
*
- * pgpool: a language independent connection pool server for PostgreSQL
+ * pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2012 PgPool Global Development Group
@@ -44,8 +44,8 @@ unsigned char * WD_Node_List = NULL; /* node list */
pid_t wd_ppid = 0;
static pid_t lifecheck_pid;
static pid_t child_pid;
-static pid_t reader_pid[WD_MAX_IF_NUM];
-static pid_t writer_pid[WD_MAX_IF_NUM];
+static pid_t hb_receiver_pid[WD_MAX_IF_NUM];
+static pid_t hb_sender_pid[WD_MAX_IF_NUM];
pid_t wd_main(int fork_wait_time);
void wd_kill_watchdog(int sig);
@@ -82,12 +82,12 @@ wd_kill_watchdog(int sig)
kill (lifecheck_pid, sig);
kill (child_pid, sig);
- if (!strcmp(pool_config->watchdog_mode, MODE_UDP))
+ if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT))
{
- for (i = 0; i < pool_config->num_udp_if; i++)
+ for (i = 0; i < pool_config->num_hb_if; i++)
{
- kill (reader_pid[i], sig);
- kill (writer_pid[i], sig);
+ kill (hb_receiver_pid[i], sig);
+ kill (hb_sender_pid[i], sig);
}
}
}
@@ -154,24 +154,24 @@ wd_main(int fork_wait_time)
return 0;
}
- if (!strcmp(pool_config->watchdog_mode, MODE_UDP))
+ if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT))
{
- for (i = 0; i < pool_config->num_udp_if; i++)
+ for (i = 0; i < pool_config->num_hb_if; i++)
{
- /* reader process */
- reader_pid[i] = wd_reader(1, pool_config->udp_if[i]);
- if (reader_pid[i] < 0 )
+ /* heartbeat receiver process */
+ hb_receiver_pid[i] = wd_hb_receiver(1, pool_config->hb_if[i]);
+ if (hb_receiver_pid[i] < 0 )
{
- pool_error("launch wd_reader failed");
- return reader_pid[i];
+ pool_error("launch wd_hb_receiver failed");
+ return hb_receiver_pid[i];
}
- /* writer process */
- writer_pid[i] = wd_writer(1, pool_config->udp_if[i]);
- if (writer_pid[i] < 0 )
+ /* heartbeat sender process */
+ hb_sender_pid[i] = wd_hb_sender(1, pool_config->hb_if[i]);
+ if (hb_sender_pid[i] < 0 )
{
- pool_error("launch wd_writer failed");
- return writer_pid[i];
+ pool_error("launch wd_hb_sender failed");
+ return hb_sender_pid[i];
}
}
}
@@ -251,9 +251,9 @@ wd_is_watchdog_pid(pid_t pid)
return 1;
}
- for (i = 0; i < pool_config->num_udp_if; i++)
+ for (i = 0; i < pool_config->num_hb_if; i++)
{
- if (pid == reader_pid[i] || pid == writer_pid[i])
+ if (pid == hb_receiver_pid[i] || pid == hb_sender_pid[i])
{
return 1;
}
@@ -267,7 +267,7 @@ wd_reaper_watchdog(pid_t pid, int status)
{
int i;
- /* exiting process was watchdog lifecheck process */
+ /* watchdog lifecheck process exits */
if (pid == lifecheck_pid)
{
if (WIFSIGNALED(status))
@@ -287,7 +287,7 @@ wd_reaper_watchdog(pid_t pid, int status)
pool_log("fork a new watchdog lifecheck pid %d", lifecheck_pid);
}
- /* exiting process was watchdog child process */
+ /* watchdog child process exits */
else if (pid == child_pid)
{
if (WIFSIGNALED(status))
@@ -307,48 +307,48 @@ wd_reaper_watchdog(pid_t pid, int status)
pool_log("fork a new watchdog child pid %d", child_pid);
}
- /* exiting process was reader/writer process */
+ /* receiver/sender process exits */
else
{
- for (i = 0; i < pool_config->num_udp_if; i++)
+ for (i = 0; i < pool_config->num_hb_if; i++)
{
- if (pid == reader_pid[i])
+ if (pid == hb_receiver_pid[i])
{
if (WIFSIGNALED(status))
- pool_debug("watchdog reader process %d exits with status %d by signal %d",
+ pool_debug("watchdog heartbeat receiver process %d exits with status %d by signal %d",
pid, status, WTERMSIG(status));
else
- pool_debug("watchdog reader process %d exits with status %d", pid, status);
+ pool_debug("watchdog heartbeat receiver process %d exits with status %d", pid, status);
- reader_pid[i] = wd_reader(1, pool_config->udp_if[i]);
+ hb_receiver_pid[i] = wd_hb_receiver(1, pool_config->hb_if[i]);
- if (reader_pid[i] < 0)
+ if (hb_receiver_pid[i] < 0)
{
- pool_error("wd_reaper: fork a watchdog reader process failed");
+ pool_error("wd_reaper: fork a watchdog heartbeat receiver process failed");
return 0;
}
- pool_log("fork a new watchdog reader pid %d", reader_pid[i]);
+ pool_log("fork a new watchdog heartbeat receiver: pid %d", hb_receiver_pid[i]);
break;
}
- else if (pid == writer_pid[i])
+ else if (pid == hb_sender_pid[i])
{
if (WIFSIGNALED(status))
- pool_debug("watchdog writer process %d exits with status %d by signal %d",
+ pool_debug("watchdog heartbeat sender process %d exits with status %d by signal %d",
pid, status, WTERMSIG(status));
else
- pool_debug("watchdog writer process %d exits with status %d", pid, status);
+ pool_debug("watchdog heartbeat sender process %d exits with status %d", pid, status);
- writer_pid[i] = wd_writer(1, pool_config->udp_if[i]);
+ hb_sender_pid[i] = wd_hb_sender(1, pool_config->hb_if[i]);
- if (writer_pid[i] < 0)
+ if (hb_sender_pid[i] < 0)
{
- pool_error("wd_reaper: fork a watchdog writer process failed");
+ pool_error("wd_reaper: fork a watchdog heartbeat sender process failed");
return 0;
}
- pool_log("fork a new watchdog writer pid %d", writer_pid[i]);
+ pool_log("fork a new watchdog heartbeat sender: pid %d", hb_sender_pid[i]);
break;
}
}
diff --git a/watchdog/watchdog.h b/watchdog/watchdog.h
index 982fe8332..332a96020 100644
--- a/watchdog/watchdog.h
+++ b/watchdog/watchdog.h
@@ -39,7 +39,7 @@
#define WD_MAX_IF_NAME_LEN (16)
#define WD_INFO(wd_id) (pool_config->other_wd->wd_info[(wd_id)])
-#define WD_UDP_IF(if_id) (pool_config->udp_if[(if_id)])
+#define WD_HB_IF(if_id) (pool_config->hb_if[(if_id)])
#define WD_MYSELF (WD_List)
@@ -131,8 +131,8 @@ typedef struct {
int life; /* life point */
char delegate_ip[WD_MAX_HOST_NAMELEN]; /* delegate IP */
int delegate_ip_flag; /* delegate IP flag */
- struct timeval udp_send_time; /* send time */
- struct timeval udp_last_recv_time; /* recv time */
+ struct timeval hb_send_time; /* send time */
+ struct timeval hb_last_recv_time; /* recv time */
bool is_lock_holder; /* lock holder flag */
bool in_interlocking; /* failover or failback is in progress */
} WdInfo;
@@ -155,7 +155,7 @@ typedef union {
typedef struct {
char addr[WD_MAX_HOST_NAMELEN];
char if_name[WD_MAX_IF_NAME_LEN];
-} WdUdpIf;
+} WdHbIf;
typedef struct {
int num_wd; /* number of watchdogs */
@@ -182,14 +182,14 @@ typedef struct {
} WdPacketThreadArg;
/*
- * UDP packet
+ * heartbeat packet
*/
typedef struct {
char from[WD_MAX_HOST_NAMELEN];
struct timeval send_time;
WD_STATUS status;
char hash[(MD5_PASSWD_LEN+1)*2];
-} WdUdpPacket;
+} WdHbPacket;
/*
* thread argument for lifecheck of pgpool
diff --git a/watchdog/wd_ext.h b/watchdog/wd_ext.h
index 786b0b903..2c0d5c4ba 100644
--- a/watchdog/wd_ext.h
+++ b/watchdog/wd_ext.h
@@ -92,13 +92,13 @@ extern int is_wd_lifecheck_ready(void);
extern int wd_lifecheck(void);
extern int wd_ping_pgpool(WdInfo * pgpool);
-/* wd_udp.c */
-extern int wd_create_udp_send_socket(WdUdpIf udp_if);
-extern int wd_create_udp_recv_socket(WdUdpIf udp_if);
-extern int wd_udp_write(int sock, WdUdpPacket * pkt, int len, const char * destination);
-extern int wd_udp_read(int sock, WdUdpPacket * pkt);
-extern pid_t wd_reader(int fork_wait_time, WdUdpIf udp_if);
-extern pid_t wd_writer(int fork_wait_time, WdUdpIf udp_if);
+/* wd_hearbeat.c */
+extern int wd_create_hb_send_socket(WdHbIf hb_if);
+extern int wd_create_hb_recv_socket(WdHbIf hb_if);
+extern int wd_hb_send(int sock, WdHbPacket * pkt, int len, const char * destination);
+extern int wd_hb_recv(int sock, WdHbPacket * pkt);
+extern pid_t wd_hb_receiver(int fork_wait_time, WdHbIf hb_if);
+extern pid_t wd_hb_sender(int fork_wait_time, WdHbIf hb_if);
/* wd_interlock.c */
extern int wd_init_interlock(void);
diff --git a/watchdog/wd_heartbeat.c b/watchdog/wd_heartbeat.c
new file mode 100644
index 000000000..32c9a0bae
--- /dev/null
+++ b/watchdog/wd_heartbeat.c
@@ -0,0 +1,533 @@
+/*
+ * $Header$
+ *
+ * Handles watchdog connection, and protocol communication with pgpool-II
+ *
+ * pgpool: a language independent connection pool server for PostgreSQL
+ * written by Tatsuo Ishii
+ *
+ * Copyright (c) 2003-2013 PgPool Global Development Group
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby
+ * granted, provided that the above copyright notice appear in all
+ * copies and that both that copyright notice and this permission
+ * notice appear in supporting documentation, and that the name of the
+ * author not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. The author makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <ctype.h>
+#include <time.h>
+#include <string.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/stat.h>
+#include <sys/un.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <netinet/ip.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#if defined(SO_BINDTODEVICE)
+#include <net/if.h>
+#endif
+
+#include "pool.h"
+#include "pool_config.h"
+#include "md5.h"
+#include "watchdog.h"
+#include "wd_ext.h"
+
+#define MAX_BIND_TRIES 5
+
+static RETSIGTYPE hb_sender_exit(int sig);
+static RETSIGTYPE hb_receiver_exit(int sig);
+static int hton_wd_hb_packet(WdHbPacket * to, WdHbPacket * from);
+static int ntoh_wd_hb_packet(WdHbPacket * to, WdHbPacket * from);
+static int packet_to_string_hb(WdHbPacket pkt, char *str, int maxlen);
+
+int
+wd_create_hb_send_socket(WdHbIf hb_if)
+{
+ int sock;
+ int tos;
+
+ /* create socket */
+ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ {
+ /* socket create failed */
+ pool_error("wd_create_hb_send_socket: Failed to create socket. reason: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ /* set socket option */
+ tos = IPTOS_LOWDELAY;
+ if (setsockopt(sock, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(tos)) == -1 )
+ {
+ pool_error("wd_create_hb_send_socket: setsockopt(IP_TOS) failed. reason: %s",
+ strerror(errno));
+ close(sock);
+ return -1;
+ }
+
+#if defined(SO_BINDTODEVICE)
+ {
+ struct ifreq i;
+ strlcpy(i.ifr_name, hb_if.if_name, sizeof(i.ifr_name));
+
+ if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &i, sizeof(i)) == -1)
+ {
+ pool_error("wd_create_hb_send_socket: setsockopt(SO_BINDTODEVICE) failed. reason: %s, device: %s",
+ strerror(errno), i.ifr_name);
+ close(sock);
+ return -1;
+ }
+ pool_log("wd_create_hb_send_socket: bind send socket to device: %s", i.ifr_name);
+ }
+#endif
+#if defined(SO_REUSEPORT)
+ {
+ int one = 1;
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) == -1)
+ {
+ pool_error("wd_create_hb_send_socket: setsockopt(SO_REUSEPORT) failed. reason: %s",
+ strerror(errno));
+ close(sock);
+ return -1;
+ }
+ pool_log("wd_create_hb_send_socket: set SO_REUSEPORT");
+ }
+#endif
+
+ if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
+ pool_error("wd_create_hb_send_socket: setting close-on-exec flag failed. reason: %s",
+ strerror(errno));
+ close(sock);
+ return -1;
+ }
+
+ return sock;
+}
+
+int
+wd_create_hb_recv_socket(WdHbIf hb_if)
+{
+ struct sockaddr_in addr;
+ int sock;
+ const int one = 1;
+ int bind_tries;
+ int bind_is_done;
+
+ memset(&(addr), 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(pool_config->wd_heartbeat_port);
+ addr.sin_addr.s_addr = INADDR_ANY;
+
+ /* create socket */
+ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ {
+ /* socket create failed */
+ pool_error("wd_create_hb_recv_socket: Failed to create socket. reason: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(one)) == -1 )
+ {
+ pool_error("wd_create_hb_recv_socket: setsockopt(SO_REUSEADDR) failed. reason: %s",
+ strerror(errno));
+ close(sock);
+ return -1;
+ }
+
+#if defined(SO_BINDTODEVICE)
+ {
+ struct ifreq i;
+ strlcpy(i.ifr_name, hb_if.if_name, sizeof(i.ifr_name));
+
+ if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &i, sizeof(i)) == -1)
+ {
+ pool_error("wd_create_hb_recv_socket: setsockopt(SO_BINDTODEVICE) failed. reason: %s, devise: %s",
+ strerror(errno), i.ifr_name);
+ close(sock);
+ return -1;
+ }
+ pool_log("wd_create_hb_recv_socket: bind receive socket to device: %s", i.ifr_name);
+ }
+#endif
+
+#if defined(SO_REUSEPORT)
+ {
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) == -1)
+ {
+ pool_error("wd_create_hb_recv_socket: setsockopt(SO_REUSEPORT) failed. reason: %s",
+ strerror(errno));
+ close(sock);
+ return -1;
+ }
+ pool_log("wd_create_hb_recv_socket: set SO_REUSEPORT");
+ }
+#endif
+
+ bind_is_done = 0;
+ for (bind_tries = 0; !bind_is_done && bind_tries < MAX_BIND_TRIES; bind_tries++)
+ {
+ if (bind(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr)) < 0)
+ {
+ pool_log("wd_crate_hb_recv_socket: bind failed. reason: %s ... retrying",
+ strerror(errno));
+ sleep(1);
+ }
+ else
+ {
+ bind_is_done = 1;
+ }
+ }
+
+ /* bind failed finally */
+ if (!bind_is_done)
+ {
+ pool_error("wd_crate_hb_recv_socket: unable to bind socket. reason: %s",
+ strerror(errno));
+ close(sock);
+ return -1;
+ }
+
+ if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
+ pool_error("wd_create_hb_recv_socket: setting close-on-exec flag failed. reason: %s",
+ strerror(errno));
+ close(sock);
+ return -1;
+ }
+
+ return sock;
+}
+
+int
+wd_hb_send(int sock, WdHbPacket * pkt, int len, const char * host)
+{
+ int rtn;
+ struct sockaddr_in addr;
+ struct hostent *hp;
+ WdHbPacket buf;
+
+ if (!host || !strlen(host))
+ {
+ pool_error("wd_hb_send: host name is empty");
+ return -1;
+ }
+
+ hp = gethostbyname(host);
+ if ((hp == NULL) || (hp->h_addrtype != AF_INET))
+ {
+ pool_error("wd_hb_send: gethostbyname() failed: %s host: %s",
+ hstrerror(h_errno), host);
+ return -1;
+ }
+ memmove((char *) &(addr.sin_addr), (char *) hp->h_addr, hp->h_length);
+
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(pool_config->wd_heartbeat_port);
+
+ hton_wd_hb_packet(&buf, pkt);
+
+ if ((rtn = sendto(sock, &buf, sizeof(WdHbPacket), 0,
+ (struct sockaddr *)&addr, sizeof(addr))) != len)
+ {
+ pool_error("wd_hb_send: failed to sent packet to %s", host);
+ return WD_NG;
+ }
+ pool_debug("wd_hb_send: send %d byte packet", rtn);
+
+ return WD_OK;
+}
+
+int
+wd_hb_recv(int sock, WdHbPacket * pkt)
+{
+ int rtn;
+ struct sockaddr_in senderinfo;
+ socklen_t addrlen;
+ WdHbPacket buf;
+
+ addrlen = sizeof(senderinfo);
+
+ rtn = recvfrom(sock, &buf, sizeof(WdHbPacket), 0,
+ (struct sockaddr *)&senderinfo, &addrlen);
+ if (rtn < 0)
+ {
+ pool_error("wd_hb_recv: failed to receive packet");
+ return WD_NG;
+ }
+ else if (rtn == 0)
+ {
+ pool_error("wd_hb_recv: received zero bytes");
+ return WD_NG;
+ }
+ else
+ {
+ pool_debug("wd_hb_recv: received %d byte packet", rtn);
+ }
+
+ ntoh_wd_hb_packet(pkt, &buf);
+
+ return WD_OK;
+}
+
+pid_t wd_hb_receiver(int fork_wait_time, WdHbIf hb_if)
+{
+ int sock;
+ pid_t pid = 0;
+ WdHbPacket pkt;
+ struct timeval tv;
+ char from[WD_MAX_HOST_NAMELEN];
+ char buf[(MD5_PASSWD_LEN+1)*2];
+ char pack_str[WD_MAX_PACKET_STRING];
+ int pack_str_len;
+
+ WdInfo * p;
+
+ pid = fork();
+ if (pid != 0)
+ {
+ if (pid == -1)
+ pool_error("wd_hb_receiver: fork() failed.");
+
+ return pid;
+ }
+
+ if (fork_wait_time > 0)
+ {
+ sleep(fork_wait_time);
+ }
+
+ myargv = save_ps_display_args(myargc, myargv);
+
+ POOL_SETMASK(&UnBlockSig);
+
+ signal(SIGTERM, hb_receiver_exit);
+ signal(SIGINT, hb_receiver_exit);
+ signal(SIGQUIT, hb_receiver_exit);
+ signal(SIGCHLD, SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
+ signal(SIGUSR1, SIG_IGN);
+ signal(SIGUSR2, SIG_IGN);
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGALRM, SIG_IGN);
+
+ init_ps_display("", "", "", "");
+
+ if ( (sock = wd_create_hb_recv_socket(hb_if)) < 0)
+ {
+ pool_error("wd_hb_receiver: socket create failed");
+ hb_receiver_exit(SIGTERM);
+ }
+
+ set_ps_display("heartbeat receiver", false);
+
+ for(;;)
+ {
+ if (wd_hb_recv(sock, &pkt) == WD_OK)
+ {
+ /* auhtentication */
+ if (strlen(pool_config->wd_authkey))
+ {
+ /* calculate hash from packet */
+ pack_str_len = packet_to_string_hb(pkt, pack_str, sizeof(pack_str));
+ wd_calc_hash(pack_str, pack_str_len, buf);
+
+ if (strcmp(pkt.hash, buf))
+ {
+ pool_log("wd_hb_receiver: authentication failed");
+ continue;
+ }
+ }
+
+ /* get current time */
+ gettimeofday(&tv, NULL);
+
+ /* who send this packet? */
+ strlcpy(from, pkt.from, sizeof(from));
+
+ p = WD_List;
+ while (p->status != WD_END)
+ {
+ if (!strcmp(p->hostname, from))
+ {
+ /* this is the first packet or the latest packet */
+ if (!WD_TIME_ISSET(p->hb_send_time) ||
+ WD_TIME_BEFORE(p->hb_send_time, pkt.send_time))
+ {
+ pool_debug("wd_hb_receiver: received heartbeat signal from %s", from);
+ p->hb_send_time = pkt.send_time;
+ p->hb_last_recv_time = tv;
+ }
+ break;
+ }
+ p++;
+ }
+ }
+ }
+
+ return pid;
+}
+
+pid_t wd_hb_sender(int fork_wait_time, WdHbIf hb_if)
+{
+ int sock;
+ pid_t pid = 0;
+ WdHbPacket pkt;
+ WdInfo * p = WD_List;
+ char pack_str[WD_MAX_PACKET_STRING];
+ int pack_str_len;
+
+ pid = fork();
+ if (pid != 0)
+ {
+ if (pid == -1)
+ pool_error("wd_hb_sender: fork() failed.");
+
+ return pid;
+ }
+
+ if (fork_wait_time > 0)
+ {
+ sleep(fork_wait_time);
+ }
+
+ myargv = save_ps_display_args(myargc, myargv);
+
+ POOL_SETMASK(&UnBlockSig);
+
+ signal(SIGTERM, hb_sender_exit);
+ signal(SIGINT, hb_sender_exit);
+ signal(SIGQUIT, hb_sender_exit);
+ signal(SIGCHLD, SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
+ signal(SIGUSR1, SIG_IGN);
+ signal(SIGUSR2, SIG_IGN);
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGALRM, SIG_IGN);
+
+ init_ps_display("", "", "", "");
+
+ if ( (sock = wd_create_hb_send_socket(hb_if)) < 0)
+ {
+ pool_error("wd_hb_sender: socket create failed");
+ hb_sender_exit(SIGTERM);
+ }
+
+ set_ps_display("heartbeat sender", false);
+
+ for(;;)
+ {
+ gettimeofday(&pkt.send_time, NULL);
+ strlcpy(pkt.from, pool_config->wd_hostname, sizeof(pkt.from));
+
+ pkt.status = p->status;
+
+ if (strlen(pool_config->wd_authkey))
+ {
+ /* calculate hash from packet */
+ pack_str_len = packet_to_string_hb(pkt, pack_str, sizeof(pack_str));
+ wd_calc_hash(pack_str, pack_str_len, pkt.hash);
+ }
+
+ wd_hb_send(sock, &pkt, sizeof(pkt), hb_if.addr);
+ pool_debug("wd_hb_sender: send heartbeat signal to %s", hb_if.addr);
+ sleep(pool_config->wd_heartbeat_keepalive);
+ }
+
+ return pid;
+}
+
+static RETSIGTYPE
+hb_sender_exit(int sig)
+{
+ switch (sig)
+ {
+ case SIGTERM: /* smart shutdown */
+ case SIGINT: /* fast shutdown */
+ case SIGQUIT: /* immediate shutdown */
+ pool_debug("hb_sender child receives shutdown request signal %d", sig);
+ break;
+ default:
+ pool_error("hb_sender child receives unknown signal %d", sig);
+ }
+
+ exit(0);
+}
+
+static RETSIGTYPE
+hb_receiver_exit(int sig)
+{
+ switch (sig)
+ {
+ case SIGTERM: /* smart shutdown */
+ case SIGINT: /* fast shutdown */
+ case SIGQUIT: /* immediate shutdown */
+ pool_debug("hb_receiver child receives shutdown request signal %d", sig);
+ break;
+ default:
+ pool_error("hb_receiver child receives unknown signal %d", sig);
+ }
+
+ exit(0);
+}
+
+static int
+hton_wd_hb_packet(WdHbPacket * to, WdHbPacket * from)
+{
+ if ((to == NULL) || (from == NULL))
+ {
+ return WD_NG;
+ }
+
+ to->status = htonl(from->status);
+ to->send_time.tv_sec = htonl(from->send_time.tv_sec);
+ to->send_time.tv_usec = htonl(from->send_time.tv_usec);
+ memcpy(to->from, from->from, sizeof(to->from));
+ memcpy(to->hash, from->hash, sizeof(to->hash));
+
+ return WD_OK;
+}
+
+static int
+ntoh_wd_hb_packet(WdHbPacket * to, WdHbPacket * from)
+{
+ if ((to == NULL) || (from == NULL))
+ {
+ return WD_NG;
+ }
+
+ to->status = ntohl(from->status);
+ to->send_time.tv_sec = ntohl(from->send_time.tv_sec);
+ to->send_time.tv_usec = ntohl(from->send_time.tv_usec);
+ memcpy(to->from, from->from, sizeof(to->from));
+ memcpy(to->hash, from->hash, sizeof(to->hash));
+
+ return WD_OK;
+}
+
+/* convert pakcet to string and return length of the string */
+static int packet_to_string_hb(WdHbPacket pkt, char *str, int maxlen)
+{
+ int len;
+ len = snprintf(str, maxlen, "status=%d tv_sec=%ld tv_usec=%ld from=%s",
+ pkt.status, pkt.send_time.tv_sec, pkt.send_time.tv_usec, pkt.from);
+
+ return len;
+}
diff --git a/watchdog/wd_init.c b/watchdog/wd_init.c
index dfc5eb6e9..4c6bcd53d 100644
--- a/watchdog/wd_init.c
+++ b/watchdog/wd_init.c
@@ -86,8 +86,8 @@ wd_init(void)
p = WD_List;
while (p->status != WD_END)
{
- WD_TIME_INIT(p->udp_send_time);
- WD_TIME_INIT(p->udp_last_recv_time);
+ WD_TIME_INIT(p->hb_send_time);
+ WD_TIME_INIT(p->hb_last_recv_time);
p++;
}
diff --git a/watchdog/wd_lifecheck.c b/watchdog/wd_lifecheck.c
index a4575356d..14c31d85d 100644
--- a/watchdog/wd_lifecheck.c
+++ b/watchdog/wd_lifecheck.c
@@ -46,7 +46,7 @@ static int pgpool_down(WdInfo * pool);
static void check_pgpool_status(void);
static void check_pgpool_status_by_query(void);
-static void check_pgpool_status_by_udp(void);
+static void check_pgpool_status_by_hb(void);
static int ping_pgpool(PGconn * conn);
static int is_parent_alive(void);
@@ -60,7 +60,7 @@ is_wd_lifecheck_ready(void)
while (p->status != WD_END)
{
/* query mode */
- if (!strcmp(pool_config->watchdog_mode, MODE_QUERY))
+ if (!strcmp(pool_config->wd_lifecheck_method, MODE_QUERY))
{
if (wd_ping_pgpool(p) == WD_NG)
{
@@ -69,8 +69,8 @@ is_wd_lifecheck_ready(void)
rtn = WD_NG;
}
}
- /* udp mode */
- else if (!strcmp(pool_config->watchdog_mode, MODE_UDP))
+ /* heartbeat mode */
+ else if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT))
{
if (p == WD_List)
{
@@ -79,8 +79,8 @@ is_wd_lifecheck_ready(void)
continue;
}
- if (!WD_TIME_ISSET(p->udp_last_recv_time) ||
- !WD_TIME_ISSET(p->udp_send_time))
+ if (!WD_TIME_ISSET(p->hb_last_recv_time) ||
+ !WD_TIME_ISSET(p->hb_send_time))
{
pool_debug("is_wd_lifecheck_ready: pgpool %d (%s:%d) has not send the heartbeat signal yet",
i, p->hostname, p->pgpool_port);
@@ -91,7 +91,7 @@ is_wd_lifecheck_ready(void)
else
{
pool_error("is_wd_lifecheck_ready: unkown watchdog mode %s",
- pool_config->watchdog_mode);
+ pool_config->wd_lifecheck_method);
return WD_NG;
}
@@ -154,19 +154,19 @@ static void
check_pgpool_status()
{
/* query mode */
- if (!strcmp(pool_config->watchdog_mode, MODE_QUERY))
+ if (!strcmp(pool_config->wd_lifecheck_method, MODE_QUERY))
{
check_pgpool_status_by_query();
}
- /* udp heartbeat mode */
- else if (!strcmp(pool_config->watchdog_mode, MODE_UDP))
+ /* heartbeat mode */
+ else if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT))
{
- check_pgpool_status_by_udp();
+ check_pgpool_status_by_hb();
}
}
static void
-check_pgpool_status_by_udp(void)
+check_pgpool_status_by_hb(void)
{
int cnt;
WdInfo * p = WD_List;
@@ -178,41 +178,41 @@ check_pgpool_status_by_udp(void)
cnt = 0;
while (p->status != WD_END)
{
- pool_debug("check_pgpool_status_by_udp: checking pgpool %d (%s:%d)",
+ pool_debug("check_pgpool_status_by_hb: checking pgpool %d (%s:%d)",
cnt, p->hostname, p->pgpool_port);
if (p == WD_MYSELF)
{
if (is_parent_alive() == WD_NG && WD_MYSELF->status != WD_DOWN)
{
- pool_debug("check_pgpool_status_by_udp: NG; the main pgpool process does't exist.");
- pool_log("check_pgpool_status_by_udp: lifecheck failed. pgpool %d (%s:%d) seems not to be working",
+ pool_debug("check_pgpool_status_by_hb: NG; the main pgpool process does't exist.");
+ pool_log("check_pgpool_status_by_hb: lifecheck failed. pgpool %d (%s:%d) seems not to be working",
cnt, p->hostname, p->pgpool_port);
wd_set_myself(&tv, WD_DOWN);
wd_notice_server_down();
}
else
{
- pool_debug("check_pgpool_status_by_udp: OK; status %d", p->status);
+ pool_debug("check_pgpool_status_by_hb: OK; status %d", p->status);
}
}
else
{
- interval = WD_TIME_DIFF_SEC(tv, p->udp_last_recv_time);
+ interval = WD_TIME_DIFF_SEC(tv, p->hb_last_recv_time);
- if (interval > pool_config->wd_udp_deadtime)
+ if (interval > pool_config->wd_heartbeat_deadtime)
{
- pool_debug("check_pgpool_status_by_udp: the latest heartbeat received %d seconds ago", interval);
- pool_debug("check_pgpool_status_by_udp: NG; status %d", p->status);
+ pool_debug("check_pgpool_status_by_hb: the latest heartbeat received %d seconds ago", interval);
+ pool_debug("check_pgpool_status_by_hb: NG; status %d", p->status);
- pool_log("check_pgpool_status_by_udp: lifecheck failed. pgpool %d (%s:%d) seems not to be working",
+ pool_log("check_pgpool_status_by_hb: lifecheck failed. pgpool %d (%s:%d) seems not to be working",
cnt, p->hostname, p->pgpool_port);
pgpool_down(p);
}
else
{
- pool_debug("check_pgpool_status_by_udp: the latest heartbeat received %d secconds ago", interval);
- pool_debug("check_pgpool_status_by_udp: OK; status %d", p->status);
+ pool_debug("check_pgpool_status_by_hb: the latest heartbeat received %d secconds ago", interval);
+ pool_debug("check_pgpool_status_by_hb: OK; status %d", p->status);
}
}
@@ -220,7 +220,7 @@ check_pgpool_status_by_udp(void)
cnt++;
if (cnt >= MAX_WATCHDOG_NUM)
{
- pool_error("check_pgpool_status_by_udp: pgpool num is out of range(%d)",cnt);
+ pool_error("check_pgpool_status_by_hb: pgpool num is out of range(%d)",cnt);
break;
}
}
diff --git a/watchdog/wd_list.c b/watchdog/wd_list.c
index 5f93254a3..ae385bc53 100644
--- a/watchdog/wd_list.c
+++ b/watchdog/wd_list.c
@@ -308,8 +308,8 @@ wd_is_alive_master(void)
master = wd_is_exist_master();
if (master != NULL)
{
- if (!strcmp(pool_config->watchdog_mode, MODE_UDP) ||
- (!strcmp(pool_config->watchdog_mode, MODE_QUERY) &&
+ if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT) ||
+ (!strcmp(pool_config->wd_lifecheck_method, MODE_QUERY) &&
wd_ping_pgpool(master) == WD_OK))
{
return master;
diff --git a/watchdog/wd_udp.c b/watchdog/wd_udp.c
index f82fa6930..e69de29bb 100644
--- a/watchdog/wd_udp.c
+++ b/watchdog/wd_udp.c
@@ -1,533 +0,0 @@
-/*
- * $Header$
- *
- * Handles watchdog connection, and protocol communication with pgpool-II
- *
- * pgpool: a language independent connection pool server for PostgreSQL
- * written by Tatsuo Ishii
- *
- * Copyright (c) 2003-2013 PgPool Global Development Group
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation, and that the name of the
- * author not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. The author makes no representations about the
- * suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <ctype.h>
-#include <time.h>
-#include <string.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <sys/un.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <netinet/ip.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#if defined(SO_BINDTODEVICE)
-#include <net/if.h>
-#endif
-
-#include "pool.h"
-#include "pool_config.h"
-#include "md5.h"
-#include "watchdog.h"
-#include "wd_ext.h"
-
-#define MAX_BIND_TRIES 5
-
-static RETSIGTYPE writer_exit(int sig);
-static RETSIGTYPE reader_exit(int sig);
-static int hton_wd_udp_packet(WdUdpPacket * to, WdUdpPacket * from);
-static int ntoh_wd_udp_packet(WdUdpPacket * to, WdUdpPacket * from);
-static int packet_to_string_udp(WdUdpPacket pkt, char *str, int maxlen);
-
-int
-wd_create_udp_send_socket(WdUdpIf udp_if)
-{
- int sock;
- int tos;
-
- /* create socket */
- if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- {
- /* socket create failed */
- pool_error("wd_create_udp_send_socket: Failed to create socket. reason: %s",
- strerror(errno));
- return -1;
- }
-
- /* set socket option */
- tos = IPTOS_LOWDELAY;
- if (setsockopt(sock, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(tos)) == -1 )
- {
- pool_error("wd_create_udp_send_socket: setsockopt(IP_TOS) failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
-
-#if defined(SO_BINDTODEVICE)
- {
- struct ifreq i;
- strlcpy(i.ifr_name, udp_if.if_name, sizeof(i.ifr_name));
-
- if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &i, sizeof(i)) == -1)
- {
- pool_error("wd_create_udp_send_socket: setsockopt(SO_BINDTODEVICE) failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
- pool_log("wd_create_udp_send_socket: bind send socket to device: %s", i.ifr_name);
- }
-#endif
-#if defined(SO_REUSEPORT)
- {
- int one = 1;
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) == -1)
- {
- pool_error("wd_create_udp_send_socket: setsockopt(SO_REUSEPORT) failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
- pool_log("wd_create_udp_send_socket: set SO_REUSEPORT");
- }
-#endif
-
- if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
- pool_error("wd_create_udp_send_socket: setting close-on-exec flag failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
-
- return sock;
-}
-
-int
-wd_create_udp_recv_socket(WdUdpIf udp_if)
-{
- struct sockaddr_in addr;
- int sock;
- const int one = 1;
- int bind_tries;
- int bind_is_done;
-
- memset(&(addr), 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(pool_config->wd_udp_port);
- addr.sin_addr.s_addr = INADDR_ANY;
-
- /* create socket */
- if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- {
- /* socket create failed */
- pool_error("wd_create_udp_recv_socket: Failed to create socket. reason: %s",
- strerror(errno));
- return -1;
- }
-
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(one)) == -1 )
- {
- pool_error("wd_create_udp_recv_socket: setsockopt(SO_REUSEADDR) failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
-
-#if defined(SO_BINDTODEVICE)
- {
- struct ifreq i;
- strlcpy(i.ifr_name, udp_if.if_name, sizeof(i.ifr_name));
-
- if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &i, sizeof(i)) == -1)
- {
- pool_error("wd_create_udp_recv_socket: setsockopt(SO_BINDTODEVICE) failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
- pool_log("wd_create_udp_recv_socket: bind receive socket to device: %s", i.ifr_name);
- }
-#endif
-
-#if defined(SO_REUSEPORT)
- {
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) == -1)
- {
- pool_error("wd_create_udp_recv_socket: setsockopt(SO_REUSEPORT) failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
- pool_log("wd_create_udp_recv_socket: set SO_REUSEPORT");
- }
-#endif
-
- bind_is_done = 0;
- for (bind_tries = 0; !bind_is_done && bind_tries < MAX_BIND_TRIES; bind_tries++)
- {
- if (bind(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr)) < 0)
- {
- pool_log("wd_crate_udp_recv_socket: bind failed. reason: %s ... retrying",
- strerror(errno));
- sleep(1);
- }
- else
- {
- bind_is_done = 1;
- }
- }
-
- /* bind failed finally */
- if (!bind_is_done)
- {
- pool_error("wd_crate_udp_recv_socket: unable to bind socket. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
-
- if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
- pool_error("wd_create_udp_recv_socket: setting close-on-exec flag failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
-
- return sock;
-}
-
-int
-wd_udp_write(int sock, WdUdpPacket * pkt, int len, const char * host)
-{
- int rtn;
- struct sockaddr_in addr;
- struct hostent *hp;
- WdUdpPacket buf;
-
- if (!host || !strlen(host))
- {
- pool_error("wd_udp_write: host name is empty");
- return -1;
- }
-
- hp = gethostbyname(host);
- if ((hp == NULL) || (hp->h_addrtype != AF_INET))
- {
- pool_error("wd_udp_write: gethostbyname() failed: %s host: %s",
- hstrerror(h_errno), host);
- return -1;
- }
- memmove((char *) &(addr.sin_addr), (char *) hp->h_addr, hp->h_length);
-
- addr.sin_family = AF_INET;
- addr.sin_port = htons(pool_config->wd_udp_port);
-
- hton_wd_udp_packet(&buf, pkt);
-
- if ((rtn = sendto(sock, &buf, sizeof(WdUdpPacket), 0,
- (struct sockaddr *)&addr, sizeof(addr))) != len)
- {
- pool_error("wd_udp_write: failed to sent packet to %s", host);
- return WD_NG;
- }
- pool_debug("wd_udp_write: send %d byte packet", rtn);
-
- return WD_OK;
-}
-
-int
-wd_udp_read(int sock, WdUdpPacket * pkt)
-{
- int rtn;
- struct sockaddr_in senderinfo;
- socklen_t addrlen;
- WdUdpPacket buf;
-
- addrlen = sizeof(senderinfo);
-
- rtn = recvfrom(sock, &buf, sizeof(WdUdpPacket), 0,
- (struct sockaddr *)&senderinfo, &addrlen);
- if (rtn < 0)
- {
- pool_error("wd_udp_read: failed to receive packet");
- return WD_NG;
- }
- else if (rtn == 0)
- {
- pool_error("wd_udp_read: received zero bytes");
- return WD_NG;
- }
- else
- {
- pool_debug("wd_udp_read: received %d byte packet", rtn);
- }
-
- ntoh_wd_udp_packet(pkt, &buf);
-
- return WD_OK;
-}
-
-pid_t wd_reader(int fork_wait_time, WdUdpIf udp_if)
-{
- int sock;
- pid_t pid = 0;
- WdUdpPacket pkt;
- struct timeval tv;
- char from[WD_MAX_HOST_NAMELEN];
- char buf[(MD5_PASSWD_LEN+1)*2];
- char pack_str[WD_MAX_PACKET_STRING];
- int pack_str_len;
-
- WdInfo * p;
-
- pid = fork();
- if (pid != 0)
- {
- if (pid == -1)
- pool_error("wd_reader: fork() failed.");
-
- return pid;
- }
-
- if (fork_wait_time > 0)
- {
- sleep(fork_wait_time);
- }
-
- myargv = save_ps_display_args(myargc, myargv);
-
- POOL_SETMASK(&UnBlockSig);
-
- signal(SIGTERM, reader_exit);
- signal(SIGINT, reader_exit);
- signal(SIGQUIT, reader_exit);
- signal(SIGCHLD, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
- signal(SIGUSR1, SIG_IGN);
- signal(SIGUSR2, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
- signal(SIGALRM, SIG_IGN);
-
- init_ps_display("", "", "", "");
-
- if ( (sock = wd_create_udp_recv_socket(udp_if)) < 0)
- {
- pool_error("wd_reader: socket create failed");
- reader_exit(SIGTERM);
- }
-
- set_ps_display("udp reader", false);
-
- for(;;)
- {
- if (wd_udp_read(sock, &pkt) == WD_OK)
- {
- /* auhtentication */
- if (strlen(pool_config->wd_authkey))
- {
- /* calculate hash from packet */
- pack_str_len = packet_to_string_udp(pkt, pack_str, sizeof(pack_str));
- wd_calc_hash(pack_str, pack_str_len, buf);
-
- if (strcmp(pkt.hash, buf))
- {
- pool_log("wd_reader: authentication failed");
- continue;
- }
- }
-
- /* get current time */
- gettimeofday(&tv, NULL);
-
- /* who send this packet? */
- strlcpy(from, pkt.from, sizeof(from));
-
- p = WD_List;
- while (p->status != WD_END)
- {
- if (!strcmp(p->hostname, from))
- {
- /* this is the first packet or the latest packet */
- if (!WD_TIME_ISSET(p->udp_send_time) ||
- WD_TIME_BEFORE(p->udp_send_time, pkt.send_time))
- {
- pool_debug("wd_reader: received heartbeat signal from %s", from);
- p->udp_send_time = pkt.send_time;
- p->udp_last_recv_time = tv;
- }
- break;
- }
- p++;
- }
- }
- }
-
- return pid;
-}
-
-pid_t wd_writer(int fork_wait_time, WdUdpIf udp_if)
-{
- int sock;
- pid_t pid = 0;
- WdUdpPacket pkt;
- WdInfo * p = WD_List;
- char pack_str[WD_MAX_PACKET_STRING];
- int pack_str_len;
-
- pid = fork();
- if (pid != 0)
- {
- if (pid == -1)
- pool_error("wd_writer: fork() failed.");
-
- return pid;
- }
-
- if (fork_wait_time > 0)
- {
- sleep(fork_wait_time);
- }
-
- myargv = save_ps_display_args(myargc, myargv);
-
- POOL_SETMASK(&UnBlockSig);
-
- signal(SIGTERM, writer_exit);
- signal(SIGINT, writer_exit);
- signal(SIGQUIT, writer_exit);
- signal(SIGCHLD, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
- signal(SIGUSR1, SIG_IGN);
- signal(SIGUSR2, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
- signal(SIGALRM, SIG_IGN);
-
- init_ps_display("", "", "", "");
-
- if ( (sock = wd_create_udp_send_socket(udp_if)) < 0)
- {
- pool_error("wd_writer: socket create failed");
- writer_exit(SIGTERM);
- }
-
- set_ps_display("udp writer", false);
-
- for(;;)
- {
- gettimeofday(&pkt.send_time, NULL);
- strlcpy(pkt.from, pool_config->wd_hostname, sizeof(pkt.from));
-
- pkt.status = p->status;
-
- if (strlen(pool_config->wd_authkey))
- {
- /* calculate hash from packet */
- pack_str_len = packet_to_string_udp(pkt, pack_str, sizeof(pack_str));
- wd_calc_hash(pack_str, pack_str_len, pkt.hash);
- }
-
- wd_udp_write(sock, &pkt, sizeof(pkt), udp_if.addr);
- pool_debug("wd_writer: send heartbeat signal to %s", udp_if.addr);
- sleep(pool_config->wd_udp_keepalive);
- }
-
- return pid;
-}
-
-static RETSIGTYPE
-writer_exit(int sig)
-{
- switch (sig)
- {
- case SIGTERM: /* smart shutdown */
- case SIGINT: /* fast shutdown */
- case SIGQUIT: /* immediate shutdown */
- pool_debug("writer child receives shutdown request signal %d", sig);
- break;
- default:
- pool_error("writer child receives unknown signal %d", sig);
- }
-
- exit(0);
-}
-
-static RETSIGTYPE
-reader_exit(int sig)
-{
- switch (sig)
- {
- case SIGTERM: /* smart shutdown */
- case SIGINT: /* fast shutdown */
- case SIGQUIT: /* immediate shutdown */
- pool_debug("reader child receives shutdown request signal %d", sig);
- break;
- default:
- pool_error("reader child receives unknown signal %d", sig);
- }
-
- exit(0);
-}
-
-static int
-hton_wd_udp_packet(WdUdpPacket * to, WdUdpPacket * from)
-{
- if ((to == NULL) || (from == NULL))
- {
- return WD_NG;
- }
-
- to->status = htonl(from->status);
- to->send_time.tv_sec = htonl(from->send_time.tv_sec);
- to->send_time.tv_usec = htonl(from->send_time.tv_usec);
- memcpy(to->from, from->from, sizeof(to->from));
- memcpy(to->hash, from->hash, sizeof(to->hash));
-
- return WD_OK;
-}
-
-static int
-ntoh_wd_udp_packet(WdUdpPacket * to, WdUdpPacket * from)
-{
- if ((to == NULL) || (from == NULL))
- {
- return WD_NG;
- }
-
- to->status = ntohl(from->status);
- to->send_time.tv_sec = ntohl(from->send_time.tv_sec);
- to->send_time.tv_usec = ntohl(from->send_time.tv_usec);
- memcpy(to->from, from->from, sizeof(to->from));
- memcpy(to->hash, from->hash, sizeof(to->hash));
-
- return WD_OK;
-}
-
-/* convert pakcet to string and return length of the string */
-static int packet_to_string_udp(WdUdpPacket pkt, char *str, int maxlen)
-{
- int len;
- len = snprintf(str, maxlen, "status=%d tv_sec=%ld tv_usec=%ld from=%s",
- pkt.status, pkt.send_time.tv_sec, pkt.send_time.tv_usec, pkt.from);
-
- return len;
-}
[parent: eb05233035e4]