Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d61f253

Browse files
committed
postgres_fdw: Replace WAIT_EVENT_EXTENSION with custom wait events
Three custom wait events are added here: - "PostgresFdwCleanupResult", waiting while cleaning up PQgetResult() on transaction abort. - "PostgresFdwConnect", waiting to establish a connection to a remote server. - "PostgresFdwGetResult", waiting to receive a result from a remote server. Author: Masahiro Ikeda Discussion: https://postgr.es/m/197bce267fa691a0ac62c86c4ab904c4@oss.nttdata.com
1 parent 684d9bf commit d61f253

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

contrib/postgres_fdw/connection.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ static unsigned int prep_stmt_number = 0;
8383
/* tracks whether any work is needed in callback functions */
8484
static bool xact_got_connection = false;
8585

86+
/* custom wait event values, retrieved from shared memory */
87+
static uint32 pgfdw_we_cleanup_result = 0;
88+
static uint32 pgfdw_we_connect = 0;
89+
static uint32 pgfdw_we_get_result = 0;
90+
8691
/*
8792
* Milliseconds to wait to cancel an in-progress query or execute a cleanup
8893
* query; if it takes longer than 30 seconds to do these, we assume the
@@ -527,10 +532,14 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
527532
/* verify the set of connection parameters */
528533
check_conn_params(keywords, values, user);
529534

535+
/* first time, allocate or get the custom wait event */
536+
if (pgfdw_we_connect == 0)
537+
pgfdw_we_connect = WaitEventExtensionNew("PostgresFdwConnect");
538+
530539
/* OK to make connection */
531540
conn = libpqsrv_connect_params(keywords, values,
532541
false, /* expand_dbname */
533-
WAIT_EVENT_EXTENSION);
542+
pgfdw_we_connect);
534543

535544
if (!conn || PQstatus(conn) != CONNECTION_OK)
536545
ereport(ERROR,
@@ -858,12 +867,16 @@ pgfdw_get_result(PGconn *conn, const char *query)
858867
{
859868
int wc;
860869

870+
/* first time, allocate or get the custom wait event */
871+
if (pgfdw_we_get_result == 0)
872+
pgfdw_we_get_result = WaitEventExtensionNew("PostgresFdwGetResult");
873+
861874
/* Sleep until there's something to do */
862875
wc = WaitLatchOrSocket(MyLatch,
863876
WL_LATCH_SET | WL_SOCKET_READABLE |
864877
WL_EXIT_ON_PM_DEATH,
865878
PQsocket(conn),
866-
-1L, WAIT_EVENT_EXTENSION);
879+
-1L, pgfdw_we_get_result);
867880
ResetLatch(MyLatch);
868881

869882
CHECK_FOR_INTERRUPTS();
@@ -1562,12 +1575,16 @@ pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, PGresult **result,
15621575
goto exit;
15631576
}
15641577

1578+
/* first time, allocate or get the custom wait event */
1579+
if (pgfdw_we_cleanup_result == 0)
1580+
pgfdw_we_cleanup_result = WaitEventExtensionNew("PostgresFdwCleanupResult");
1581+
15651582
/* Sleep until there's something to do */
15661583
wc = WaitLatchOrSocket(MyLatch,
15671584
WL_LATCH_SET | WL_SOCKET_READABLE |
15681585
WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
15691586
PQsocket(conn),
1570-
cur_timeout, WAIT_EVENT_EXTENSION);
1587+
cur_timeout, pgfdw_we_cleanup_result);
15711588
ResetLatch(MyLatch);
15721589

15731590
CHECK_FOR_INTERRUPTS();

doc/src/sgml/postgres-fdw.sgml

+38
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,44 @@ postgres=# SELECT postgres_fdw_disconnect_all();
10421042
</para>
10431043
</sect2>
10441044

1045+
<sect2 id="postgres-fdw-wait-events">
1046+
<title>Wait Events</title>
1047+
1048+
<para>
1049+
<filename>postgres_fdw</filename> can report the following wait events
1050+
under the wait event type <literal>Extension</literal>:
1051+
</para>
1052+
1053+
<variablelist>
1054+
<varlistentry>
1055+
<term><literal>PostgresFdwCleanupResult</literal></term>
1056+
<listitem>
1057+
<para>
1058+
Waiting for transaction abort on remote server.
1059+
</para>
1060+
</listitem>
1061+
</varlistentry>
1062+
1063+
<varlistentry>
1064+
<term><literal>PostgresFdwConnect</literal></term>
1065+
<listitem>
1066+
<para>
1067+
Waiting to establish a connection to a remote server.
1068+
</para>
1069+
</listitem>
1070+
</varlistentry>
1071+
1072+
<varlistentry>
1073+
<term><literal>PostgresFdwGetResult</literal></term>
1074+
<listitem>
1075+
<para>
1076+
Waiting to receive the results of a query from a remote server.
1077+
</para>
1078+
</listitem>
1079+
</varlistentry>
1080+
</variablelist>
1081+
</sect2>
1082+
10451083
<sect2 id="postgres-fdw-configuration-parameters">
10461084
<title>Configuration Parameters</title>
10471085

0 commit comments

Comments
 (0)