RE: Libpq support to connect to standby server as priority

tsunakawa.takay@fujitsu.com <tsunakawa.takay@fujitsu.com>

From: "tsunakawa.takay@fujitsu.com" <tsunakawa.takay@fujitsu.com>
To: 'Greg Nancarrow' <gregn4422@gmail.com>
Cc: 'Alvaro Herrera from 2ndQuadrant' <alvherre@alvh.no-ip.org>, 'Haribabu Kommi' <kommi.haribabu@gmail.com>, 'Robert Haas' <robertmhaas@gmail.com>, 'Laurenz Albe' <laurenz.albe@cybertec.at>, 'Tom Lane' <tgl@sss.pgh.pa.us>, 'Dave Cramer' <pg@fastcrypt.com>, 'Jing Wang' <jingwangian@gmail.com>, 'PostgreSQL-development' <pgsql-hackers@postgresql.org>
Date: 2019-12-20T00:41:21Z
Lists: pgsql-hackers
From: Greg Nancarrow <gregn4422@gmail.com>
> With the permission of the original patch author, Haribabu Kommi, I’ve
> rationalized the existing 8 patches into 3 patches, merging patches
> 1-5 and 6-7, and tidying up some documentation and code comments. I
> also rebased them to the latest PG12 source code (as of October 1,
> 2019). The patch code itself is the same, except for some version
> checks that I have updated to target the features for PG13 instead of
> PG12.
> I’ve attached the updated patches.

Thank you for taking over this patch.  Your arrangement has made the patches much easier to read!

I've finished reviewing, and my comments are below.  Unfortunately, 0003 failed to apply (I guess only slight modification is needed to apply to HEAD.)  I'd like to proceed to testing when the revised patch becomes available.



(1) 0001
+				/*
+				 * Requested type is prefer-read, then record this host index
+				 * and try the other before considering it later. If requested
+				 * type of connection is read-only, ignore this connection.
+				 */
+				if (conn->requested_session_type == SESSION_TYPE_PREFER_READ ||
+					conn->requested_session_type == SESSION_TYPE_READ_ONLY)
 				{

This if statement seems unnecessary, because the following part at the beginning of the CONNECTION_CHECK_TARGET case block precludes entering the if block.  Cases other than "any" are handled first here.


 				if (conn->sversion >= 70400 &&
-					conn->target_session_attrs != NULL &&
-					strcmp(conn->target_session_attrs, "read-write") == 0)
+					conn->requested_session_type != SESSION_TYPE_ANY)
+				{


(2) 0002
-} TargetSessionAttrsType;
+}			TargetSessionAttrsType;

One space after } is replaced with three tabs.  I guess this is an unintentional change.
 

(3) 0002
+reject_checked_read_or_write_connection(PGconn *conn)

To follow the naming style of most internal functions in this file, I find it better to change the name to rejectCheckedReadOrWriteConnection.


(4) 0003
+reject_checked_recovery_connection(PGconn *conn)

The same as the previous one.


(5) 0003
Don't we have to describe in_recovery in both or either of high-availability.sgml and config.sgml?  transaction_read_only is touched in the former.


Regards
Takayuki Tsunakawa

Commits

  1. Make test_target_session_attrs more robust against connection failure.

  2. Extend the abilities of libpq's target_session_attrs parameter.

  3. Mark default_transaction_read_only as GUC_REPORT.

  4. Introduce a new GUC_REPORT setting "in_hot_standby".

  5. Avoid spamming the client with multiple ParameterStatus messages.

  6. Avoid harmless Valgrind no-buffer-pin errors.

  7. Restructure libpq code to remove some duplicity

  8. libpq: Add target_session_attrs parameter.