Summary:
After commit 79888cf12d5eceb58c30a2934222499cc71fa237, follower reads GUCs are allowed to be set in transaction blocks only if no actual SQL query (i.e., other than trivial statements like SET) has executed in the block. This is because after that commit, these GUCs take affect on the transaction block they are set in. Before the commit, the GUCs could be set anywhere in the transaction block because they would take affect only on transaction blocks that follow later.
As a side effect of this commit, follower reads GUCs set in the connection string face the following error: SET yb_read_from_followers must be called before any query.
Because follower reads only applies to read-only transactions, there is no need to perform the check for previous SQL statements and throw the "must be called before any query" error in case of read-write transaction blocks. We can allowing setting the GUCs anywhere in read-write transaction blocks and they would take affect in later read-only transactions. Doing this also side-steps the side-effect mentioned above. This revision does this by performing the checks only if `XactReadOnly` is true.
NOTE: Users can also workaround the side-effect by turning on the `ysql_yb_follower_reads_behavior_before_fixing_20482`
Tserver gflag.
Jira: DB-14886
Test Plan:
libpq/c++ does not support setting guc variables through URI, however go does.
Tested manually using James' repro from the GH issue.
yb_build.sh --cxx-test 'TEST_F(PgMiniTest, FollowerReads) {' --test_args --vmodule=libpq_utils=2
yb_build.sh --java-test 'org.yb.pgsql.TestPgFollowerReads#testSetIsolationLevelsWithReadFromFollowersSessionVariable'
Reviewers: pjain
Reviewed By: pjain
Subscribers: yql
Differential Revision: https://phorge.dev.yugabyte.com/D42277