Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb438e7e

Browse files
committed
Restructure libpq code to remove some duplicity
There was some duplicate code to run SHOW transaction_read_only todetermine whether the server is read-write or read-only. Reduce it byadding another state to the state machine.Author: Hari Babu KommiReviewed-by: Takayuki Tsunakawa, Álvaro HerreraDiscussion:https://postgr.es/m/CAJrrPGe_qgdbbN+yBgEVpd+YLHXXjTruzk6RmTMhqrFig+32ag@mail.gmail.com
1 parent55d015b commitb438e7e

File tree

2 files changed

+33
-55
lines changed

2 files changed

+33
-55
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ typedef struct _internalPQconninfoOption
170170
char*keyword;/* The keyword of the option*/
171171
char*envvar;/* Fallback environment variable name*/
172172
char*compiled;/* Fallback compiled in default value*/
173-
char*val;/* Option's current value, or NULL*/
173+
char*val;/* Option's current value, or NULL*/
174174
char*label;/* Label for field in connect dialog*/
175175
char*dispchar;/* Indicates how to display this field in a
176176
* connect dialog. Values are: "" Display
@@ -3434,6 +3434,13 @@ PQconnectPoll(PGconn *conn)
34343434
returnPGRES_POLLING_WRITING;
34353435
}
34363436

3437+
/* Almost there now ... */
3438+
conn->status=CONNECTION_CHECK_TARGET;
3439+
gotokeep_going;
3440+
}
3441+
3442+
caseCONNECTION_CHECK_TARGET:
3443+
{
34373444
/*
34383445
* If a read-write connection is required, see if we have one.
34393446
*
@@ -3476,66 +3483,36 @@ PQconnectPoll(PGconn *conn)
34763483
}
34773484

34783485
caseCONNECTION_SETENV:
3479-
3480-
/*
3481-
* Do post-connection housekeeping (only needed in protocol 2.0).
3482-
*
3483-
* We pretend that the connection is OK for the duration of these
3484-
* queries.
3485-
*/
3486-
conn->status=CONNECTION_OK;
3487-
3488-
switch (pqSetenvPoll(conn))
34893486
{
3490-
casePGRES_POLLING_OK:/* Success */
3491-
break;
3492-
3493-
casePGRES_POLLING_READING:/* Still going */
3494-
conn->status=CONNECTION_SETENV;
3495-
returnPGRES_POLLING_READING;
3487+
/*
3488+
* Do post-connection housekeeping (only needed in protocol 2.0).
3489+
*
3490+
* We pretend that the connection is OK for the duration of these
3491+
* queries.
3492+
*/
3493+
conn->status=CONNECTION_OK;
34963494

3497-
casePGRES_POLLING_WRITING:/* Still going */
3498-
conn->status=CONNECTION_SETENV;
3499-
returnPGRES_POLLING_WRITING;
3495+
switch (pqSetenvPoll(conn))
3496+
{
3497+
casePGRES_POLLING_OK:/* Success */
3498+
break;
35003499

3501-
default:
3502-
gotoerror_return;
3503-
}
3500+
casePGRES_POLLING_READING:/* Still going */
3501+
conn->status=CONNECTION_SETENV;
3502+
returnPGRES_POLLING_READING;
35043503

3505-
/*
3506-
* If a read-write connection is required, see if we have one.
3507-
* (This should match the stanza in the CONNECTION_AUTH_OK case
3508-
* above.)
3509-
*
3510-
* Servers before 7.4 lack the transaction_read_only GUC, but by
3511-
* the same token they don't have any read-only mode, so we may
3512-
* just skip the test in that case.
3513-
*/
3514-
if (conn->sversion >=70400&&
3515-
conn->target_session_attrs!=NULL&&
3516-
strcmp(conn->target_session_attrs,"read-write")==0)
3517-
{
3518-
if (!saveErrorMessage(conn,&savedMessage))
3519-
gotoerror_return;
3504+
casePGRES_POLLING_WRITING:/* Still going */
3505+
conn->status=CONNECTION_SETENV;
3506+
returnPGRES_POLLING_WRITING;
35203507

3521-
conn->status=CONNECTION_OK;
3522-
if (!PQsendQuery(conn,
3523-
"SHOW transaction_read_only"))
3524-
{
3525-
restoreErrorMessage(conn,&savedMessage);
3526-
gotoerror_return;
3508+
default:
3509+
gotoerror_return;
35273510
}
3528-
conn->status=CONNECTION_CHECK_WRITABLE;
3529-
restoreErrorMessage(conn,&savedMessage);
3530-
returnPGRES_POLLING_READING;
3531-
}
3532-
3533-
/* We can release the address list now. */
3534-
release_conn_addrinfo(conn);
35353511

3536-
/* We are open for business! */
3537-
conn->status=CONNECTION_OK;
3538-
returnPGRES_POLLING_OK;
3512+
/* Almost there now ... */
3513+
conn->status=CONNECTION_CHECK_TARGET;
3514+
gotokeep_going;
3515+
}
35393516

35403517
caseCONNECTION_CONSUME:
35413518
{

‎src/interfaces/libpq/libpq-fe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ typedef enum
6767
* connection. */
6868
CONNECTION_CONSUME,/* Wait for any pending message and consume
6969
* them. */
70-
CONNECTION_GSS_STARTUP/* Negotiating GSSAPI. */
70+
CONNECTION_GSS_STARTUP,/* Negotiating GSSAPI. */
71+
CONNECTION_CHECK_TARGET/* Check if we have a proper target connection */
7172
}ConnStatusType;
7273

7374
typedefenum

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp