http://www.pgpool.net/mantisbt/view.php?id=194#c837 reported that if
primary is not node 0, then statement timeout could occur even after
bug194-3.3.diff was applied. After some investigation, it appeared
that MASTER macro could return other than primary or load balance
node, which was not supposed to happen, thus do_query() sends queries
to wrong node (this is not clear from the report but I confirmed it in
my investigation).
pool_virtual_master_db_node_id(), which is called in MASTER macro
returns query_context->virtual_master_node_id if query context
exists. This could return wrong node if the variable has not been set
yet. To fix this, the function is modified: if the variable is not
either load balance node or primary node, the primary node id is
returned.
if (sc->query_context)
{
- return sc->query_context->virtual_master_node_id;
+ int node_id = sc->query_context->virtual_master_node_id;
+
+ if (STREAM)
+ {
+ /*
+ * Make sure that virtual_master_node_id is either primary node
+ * id or load balance node id. If not, it is likely that
+ * virtual_master_node_id is not set up yet. Let's use the
+ * primary node id.
+ */
+ if (node_id != sc->load_balance_node_id && node_id != PRIMARY_NODE_ID)
+ {
+ node_id = PRIMARY_NODE_ID;
+ }
+ }
+
+ return node_id;
}
/*