RE: Libpq support to connect to standby server as priority
Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
From: "Tsunakawa, Takayuki" <tsunakawa.takay@jp.fujitsu.com>
To: 'Haribabu Kommi' <kommi.haribabu@gmail.com>
Cc: Laurenz Albe <laurenz.albe@cybertec.at>, Tom Lane <tgl@sss.pgh.pa.us>, Dave Cramer <pg@fastcrypt.com>, Robert Haas <robertmhaas@gmail.com>, "Jing
Wang" <jingwangian@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2019-02-25T00:38:05Z
Lists: pgsql-hackers
Hi Hari-san,
I've reviewed all files. I think I'll proceed to testing when I've reviewed the revised patch and the patch for target_server_type.
(1) patch 0001
CONNECTION_CHECK_WRITABLE, /* Check if we could make a writable
* connection. */
+ CONNECTION_CHECK_TARGET, /* Check if we have a proper target
+ * connection */
CONNECTION_CONSUME /* Wait for any pending message and consume
* them. */
According to the following comment, a new enum value should be added at the end.
/*
* Although it is okay to add to these lists, values which become unused
* should never be removed, nor should constants be redefined - that would
* break compatibility with existing code.
*/
(2) patch 0002
It seems to align better with the existing code to set the default value to pg_conn.requested_session_type explicitly in makeEmptyPGconn(), even if the default value is 0. Although I feel it's redundant, other member variables do so.
(3) patch 0003
<varname>IntervalStyle</varname> was not reported by releases before 8.4;
- <varname>application_name</varname> was not reported by releases before 9.0.)
+ <varname>application_name</varname> was not reported by releases before 9.0
+ <varname>transaction_read_only</varname> was not reported by releases before 12.0.)
";" is missing at the end of the third line.
(4) patch 0004
- /* Type of connection to make. Possible values: any, read-write. */
+ /* Type of connection to make. Possible values: any, read-write, perfer-read. */
char *target_session_attrs;
perfer -> prefer
(5) patch 0004
@@ -3608,6 +3691,9 @@ makeEmptyPGconn(void)
conn = NULL;
}
+ /* Initial value */
+ conn->read_write_host_index = -1;
The new member should be initialized earlier in this function. Otherwise, as you can see in the above fragment, conn can be NULL in an out-of-memory case.
(6) patch 0004
Don't we add read-only as well as prefer-read, which corresponds to Slave or Secondary of PgJDBC's targetServerType? I thought the original proposal was to add both.
(7) patch 0004
@@ -2347,6 +2367,7 @@ keep_going: /* We will come back to here until there is
conn->try_next_addr = true;
goto keep_going;
}
+
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not create socket: %s\n"),
Is this an unintended newline addition?
(8) patch 0004
+ const char *type = (conn->requested_session_type == SESSION_TYPE_PREFER_READ) ?
+ "read-only" : "writable";
I'm afraid these strings are not translatable into other languages.
(9) patch 0004
+ /* Record read-write host index */
+ if (conn->read_write_host_index == -1)
+ conn->read_write_host_index = conn->whichhost;
At this point, the session can be either read-write or read-only, can't it? Add the check "!conn->transaction_read_only" in this if condition?
(10) patch 0004
+ if ((conn->target_session_attrs != NULL) &&
+ (conn->requested_session_type == SESSION_TYPE_PREFER_READ) &&
+ (conn->read_write_host_index != -2))
The first condition is not necessary because the second one exists.
The parenthesis surrounding each of these conditions are redundant. It would be better to remove them for readability. This also applies to the following part:
+ if (((strncmp(val, "on", 2) == 0) &&
+ (conn->requested_session_type == SESSION_TYPE_READ_WRITE)) ||
+ ((strncmp(val, "off", 3) == 0) &&
+ (conn->requested_session_type == SESSION_TYPE_PREFER_READ) &&
+ (conn->read_write_host_index != -2)))
Regards
Takayuki Tsunakawa
Commits
-
Make test_target_session_attrs more robust against connection failure.
- 3769e11a3183 14.0 landed
-
Extend the abilities of libpq's target_session_attrs parameter.
- ee28cacf619f 14.0 landed
-
Mark default_transaction_read_only as GUC_REPORT.
- d16f8c8e416d 14.0 landed
-
Introduce a new GUC_REPORT setting "in_hot_standby".
- bf8a662c9afa 14.0 landed
-
Avoid spamming the client with multiple ParameterStatus messages.
- 2432b1a04087 14.0 landed
-
Avoid harmless Valgrind no-buffer-pin errors.
- a766d6ca22ac 14.0 cited
-
Restructure libpq code to remove some duplicity
- b438e7e7a1c5 13.0 landed
-
libpq: Add target_session_attrs parameter.
- 721f7bd3cbcc 10.0 cited