mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
Restructure libpq code to remove some duplicity
There was some duplicate code to run SHOW transaction_read_only to determine whether the server is read-write or read-only. Reduce it by adding another state to the state machine. Author: Hari Babu Kommi Reviewed-by: Takayuki Tsunakawa, Álvaro Herrera Discussion: https://postgr.es/m/CAJrrPGe_qgdbbN+yBgEVpd+YLHXXjTruzk6RmTMhqrFig+32ag@mail.gmail.com
This commit is contained in:
parent
55d015bde0
commit
b438e7e7a1
@ -3434,6 +3434,13 @@ keep_going: /* We will come back to here until there is
|
|||||||
return PGRES_POLLING_WRITING;
|
return PGRES_POLLING_WRITING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Almost there now ... */
|
||||||
|
conn->status = CONNECTION_CHECK_TARGET;
|
||||||
|
goto keep_going;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CONNECTION_CHECK_TARGET:
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* If a read-write connection is required, see if we have one.
|
* If a read-write connection is required, see if we have one.
|
||||||
*
|
*
|
||||||
@ -3476,7 +3483,7 @@ keep_going: /* We will come back to here until there is
|
|||||||
}
|
}
|
||||||
|
|
||||||
case CONNECTION_SETENV:
|
case CONNECTION_SETENV:
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Do post-connection housekeeping (only needed in protocol 2.0).
|
* Do post-connection housekeeping (only needed in protocol 2.0).
|
||||||
*
|
*
|
||||||
@ -3502,40 +3509,10 @@ keep_going: /* We will come back to here until there is
|
|||||||
goto error_return;
|
goto error_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Almost there now ... */
|
||||||
* If a read-write connection is required, see if we have one.
|
conn->status = CONNECTION_CHECK_TARGET;
|
||||||
* (This should match the stanza in the CONNECTION_AUTH_OK case
|
goto keep_going;
|
||||||
* above.)
|
|
||||||
*
|
|
||||||
* Servers before 7.4 lack the transaction_read_only GUC, but by
|
|
||||||
* the same token they don't have any read-only mode, so we may
|
|
||||||
* just skip the test in that case.
|
|
||||||
*/
|
|
||||||
if (conn->sversion >= 70400 &&
|
|
||||||
conn->target_session_attrs != NULL &&
|
|
||||||
strcmp(conn->target_session_attrs, "read-write") == 0)
|
|
||||||
{
|
|
||||||
if (!saveErrorMessage(conn, &savedMessage))
|
|
||||||
goto error_return;
|
|
||||||
|
|
||||||
conn->status = CONNECTION_OK;
|
|
||||||
if (!PQsendQuery(conn,
|
|
||||||
"SHOW transaction_read_only"))
|
|
||||||
{
|
|
||||||
restoreErrorMessage(conn, &savedMessage);
|
|
||||||
goto error_return;
|
|
||||||
}
|
}
|
||||||
conn->status = CONNECTION_CHECK_WRITABLE;
|
|
||||||
restoreErrorMessage(conn, &savedMessage);
|
|
||||||
return PGRES_POLLING_READING;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We can release the address list now. */
|
|
||||||
release_conn_addrinfo(conn);
|
|
||||||
|
|
||||||
/* We are open for business! */
|
|
||||||
conn->status = CONNECTION_OK;
|
|
||||||
return PGRES_POLLING_OK;
|
|
||||||
|
|
||||||
case CONNECTION_CONSUME:
|
case CONNECTION_CONSUME:
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,8 @@ typedef enum
|
|||||||
* connection. */
|
* connection. */
|
||||||
CONNECTION_CONSUME, /* Wait for any pending message and consume
|
CONNECTION_CONSUME, /* Wait for any pending message and consume
|
||||||
* them. */
|
* them. */
|
||||||
CONNECTION_GSS_STARTUP /* Negotiating GSSAPI. */
|
CONNECTION_GSS_STARTUP, /* Negotiating GSSAPI. */
|
||||||
|
CONNECTION_CHECK_TARGET /* Check if we have a proper target connection */
|
||||||
} ConnStatusType;
|
} ConnStatusType;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
Loading…
x
Reference in New Issue
Block a user