<para>
<!--
- Specifies the maximum tolerance level of replication delay in
- seconds on the standby server against the primary server. If the
- specified value is greater than
+ Specifies the maximum tolerance level of replication delay
+ on the standby server against the primary server.
+ If this value is specified without units, it is taken as milliseconds.
+ If the specified value is greater than
0, <xref linkend="guc-delay-threshold"> is ignored. If the delay
exceeds this configured level,
<productname>Pgpool-II</productname> stops sending the <acronym>
This delay threshold check is performed every <xref linkend="guc-sr-check-period">.
Default is 0.
-->
- プライマリサーバに対するスタンバイサーバのレプリケーション遅延の許容度を秒単位で指定します。
+ プライマリサーバに対するスタンバイサーバのレプリケーション遅延の許容時間を指定します。
+ この値が単位無しで指定された場合は、マイクロ秒単位であると見なします。
+ 0よりも大きい値が指定されると、<xref linkend="guc-delay-threshold">は無視されます。
<productname>Pgpool-II</productname>は、スタンバイサーバの遅延がこの設定レベルを超えた場合には、 <xref linkend="guc-load-balance-mode">が有効であっても、プライマリに追いつくまでそのスタンバイノードには<acronym>SELECT</acronym>クエリを送信せず、全てプライマリサーバに送るようにします。
このパラメータが0の場合は、遅延のチェックを行ないません。
この遅延閾値のチェックは<xref linkend="guc-sr-check-period">毎に行われます。
<listitem>
<para>
- Specifies the maximum tolerance level of replication delay in
- seconds on the standby server against the primary server. If the
- specified value is greater than
+ Specifies the maximum tolerance level of replication delay
+ on the standby server against the primary server.
+ If this value is specified without units, it is taken as milliseconds.
+ If the specified value is greater than
0, <xref linkend="guc-delay-threshold"> is ignored. If the delay
exceeds this configured level,
<productname>Pgpool-II</productname> stops sending the <acronym>
{
{"delay_threshold_by_time", CFGCXT_RELOAD, STREAMING_REPLICATION_CONFIG,
"standby delay threshold by time.",
- CONFIG_VAR_TYPE_INT, false, GUC_UNIT_S,
+ CONFIG_VAR_TYPE_INT, false, GUC_UNIT_MS,
},
&g_pool_config.delay_threshold_by_time,
0,
!pool_is_failed_transaction() &&
pool_get_transaction_isolation() != POOL_SERIALIZABLE))
{
- BackendInfo *bkinfo = pool_get_node_info(session_context->load_balance_node_id);
-
/*
* Load balance if possible
*/
if (pool_config->statement_level_load_balance)
{
session_context->load_balance_node_id = select_load_balancing_node();
- bkinfo = pool_get_node_info(session_context->load_balance_node_id);
}
/*
* load balance node which is lowest delayed,
* false then send to the primary.
*/
- if (STREAM &&
- (
- (pool_config->delay_threshold &&
- (bkinfo->standby_delay > pool_config->delay_threshold)) ||
- (pool_config->delay_threshold_by_time &&
- (bkinfo->standby_delay > pool_config->delay_threshold_by_time*1000*1000))))
+ if (STREAM && check_replication_delay(session_context->load_balance_node_id))
{
ereport(DEBUG1,
(errmsg("could not load balance because of too much replication delay"),
extern void si_snapshot_acquired(void);
extern void si_commit_request(void);
extern void si_commit_done(void);
+extern int check_replication_delay(int node_id);
#endif /* pool_pg_utils_h */
* and prefer_lower_delay_standby are true, we choose the least delayed
* node if suggested_node is standby and delayed over delay_threshold.
*/
- if (STREAM && pool_config->prefer_lower_delay_standby && suggested_node_id != PRIMARY_NODE_ID &&
- ((BACKEND_INFO(suggested_node_id).standby_delay_by_time && BACKEND_INFO(suggested_node_id).standby_delay > pool_config->delay_threshold_by_time * 1000000) ||
- (BACKEND_INFO(suggested_node_id).standby_delay_by_time == false && BACKEND_INFO(suggested_node_id).standby_delay > pool_config->delay_threshold)))
-
+ if (STREAM && pool_config->prefer_lower_delay_standby &&
+ suggested_node_id != PRIMARY_NODE_ID &&
+ check_replication_delay(suggested_node_id) < 0)
{
ereport(DEBUG1,
(errmsg("selecting load balance node"),
* nodes which have the lowest delay.
*/
if (pool_config->delay_threshold_by_time > 0)
- lowest_delay = pool_config->delay_threshold_by_time * 1000 * 1000;
+ lowest_delay = pool_config->delay_threshold_by_time * 1000; /* convert from milli seconds to micro seconds */
else
lowest_delay = pool_config->delay_threshold;
* node if suggested_node is standby and delayed over delay_threshold.
*/
if (STREAM && pool_config->prefer_lower_delay_standby &&
- ((pool_config->delay_threshold_by_time &&
- BACKEND_INFO(selected_slot).standby_delay > pool_config->delay_threshold_by_time*1000*1000) ||
- (pool_config->delay_threshold &&
- BACKEND_INFO(selected_slot).standby_delay > pool_config->delay_threshold)))
+ check_replication_delay(selected_slot) < 0)
{
ereport(DEBUG1,
(errmsg("selecting load balance node"),
errdetail("backend id %d is streaming delayed over delay_threshold", selected_slot)));
if (pool_config->delay_threshold_by_time > 0)
- lowest_delay = pool_config->delay_threshold_by_time * 1000 * 1000;
+ lowest_delay = pool_config->delay_threshold_by_time * 1000;
else
lowest_delay = pool_config->delay_threshold;
total_weight = 0.0;
session->si_state = SI_NO_SNAPSHOT;
}
}
+
+/*
+ * Check replication delay and returns the status.
+ * Return values:
+ * 0: no delay or not in streaming repplication mode or
+ * delay_threshold(_by_time) is set to 0
+ * -1: delay exceeds delay_threshold_by_time
+ * -2: delay exceeds delay_threshold
+ */
+int check_replication_delay(int node_id)
+{
+ BackendInfo *bkinfo;
+
+ if (!STREAM)
+ return 0;
+
+ bkinfo = pool_get_node_info(node_id);
+
+ /*
+ * Check delay_threshold_by_time. bkinfo->standby_delay is in
+ * microseconds while delay_threshold_by_time is in milliseconds. We need
+ * to multiply delay_threshold_by_time by 1000 to normalize.
+ */
+ if (pool_config->delay_threshold_by_time > 0 &&
+ bkinfo->standby_delay > pool_config->delay_threshold_by_time*1000)
+ return -1;
+
+ /*
+ * Check delay_threshold.
+ */
+ if (pool_config->delay_threshold > 0 &&
+ bkinfo->standby_delay > pool_config->delay_threshold)
+ return -2;
+
+ return 0;
+}
+
# Disabled (0) by default
#delay_threshold_by_time = 0
# Threshold before not dispatching query to standby node
- # Unit is in second(s)
+ # The default unit is in millisecond(s)
# Disabled (0) by default
#prefer_lower_delay_standby = off
#auto_failback = off
# Dettached backend node reattach automatically
- # if replication_state is 'streaming'.
+ # if replicatiotate is 'streaming'.
#auto_failback_interval = 1min
# Min interval of executing auto_failback in
# seconds.
{
bkinfo->standby_delay = atol(s);
ereport(DEBUG1,
- (errmsg("standby delay in seconds * 1000000: " UINT64_FORMAT "", bkinfo->standby_delay)));
+ (errmsg("standby delay in milli seconds * 1000: " UINT64_FORMAT "", bkinfo->standby_delay)));
}
else
bkinfo->standby_delay = 0;
{
lag = bkinfo->standby_delay;
delay_threshold_by_time = pool_config->delay_threshold_by_time;
- delay_threshold_by_time *= 1000000;
+ delay_threshold_by_time *= 1000; /* convert from milli seconds to micro seconds */
/* Log delay if necessary */
if ((pool_config->log_standby_delay == LSD_ALWAYS && lag > 0) ||
echo "sr_check_period = 1" >> etc/pgpool.conf
echo "log_standby_delay = 'always'" >> etc/pgpool.conf
echo "log_min_messages = 'DEBUG1'" >> etc/pgpool.conf
+echo "log_error_verbosity = verbose" >> etc/pgpool.conf
# force load balance node to be 1.
echo "backend_weight0 = 0" >> etc/pgpool.conf
echo "backend_weight2 = 0" >> etc/pgpool.conf
# ----------------------------------------------------------------------------------------
echo Start testing delay_threshold_by_time with prefer_lower_delay_standby disabled
echo "delay_threshold = 0" >> etc/pgpool.conf
-echo "delay_threshold_by_time = 1" >> etc/pgpool.conf
+echo "delay_threshold_by_time = 1000" >> etc/pgpool.conf
+
./startall
wait_for_pgpool_startup
# pause replay on node 1