mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-11-27 07:21:09 +08:00
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
This commit is contained in:
parent
684d9bfdd5
commit
d61f2538a3
@ -83,6 +83,11 @@ static unsigned int prep_stmt_number = 0;
|
|||||||
/* tracks whether any work is needed in callback functions */
|
/* tracks whether any work is needed in callback functions */
|
||||||
static bool xact_got_connection = false;
|
static bool xact_got_connection = false;
|
||||||
|
|
||||||
|
/* custom wait event values, retrieved from shared memory */
|
||||||
|
static uint32 pgfdw_we_cleanup_result = 0;
|
||||||
|
static uint32 pgfdw_we_connect = 0;
|
||||||
|
static uint32 pgfdw_we_get_result = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Milliseconds to wait to cancel an in-progress query or execute a cleanup
|
* Milliseconds to wait to cancel an in-progress query or execute a cleanup
|
||||||
* query; if it takes longer than 30 seconds to do these, we assume the
|
* 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)
|
|||||||
/* verify the set of connection parameters */
|
/* verify the set of connection parameters */
|
||||||
check_conn_params(keywords, values, user);
|
check_conn_params(keywords, values, user);
|
||||||
|
|
||||||
|
/* first time, allocate or get the custom wait event */
|
||||||
|
if (pgfdw_we_connect == 0)
|
||||||
|
pgfdw_we_connect = WaitEventExtensionNew("PostgresFdwConnect");
|
||||||
|
|
||||||
/* OK to make connection */
|
/* OK to make connection */
|
||||||
conn = libpqsrv_connect_params(keywords, values,
|
conn = libpqsrv_connect_params(keywords, values,
|
||||||
false, /* expand_dbname */
|
false, /* expand_dbname */
|
||||||
WAIT_EVENT_EXTENSION);
|
pgfdw_we_connect);
|
||||||
|
|
||||||
if (!conn || PQstatus(conn) != CONNECTION_OK)
|
if (!conn || PQstatus(conn) != CONNECTION_OK)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -858,12 +867,16 @@ pgfdw_get_result(PGconn *conn, const char *query)
|
|||||||
{
|
{
|
||||||
int wc;
|
int wc;
|
||||||
|
|
||||||
|
/* first time, allocate or get the custom wait event */
|
||||||
|
if (pgfdw_we_get_result == 0)
|
||||||
|
pgfdw_we_get_result = WaitEventExtensionNew("PostgresFdwGetResult");
|
||||||
|
|
||||||
/* Sleep until there's something to do */
|
/* Sleep until there's something to do */
|
||||||
wc = WaitLatchOrSocket(MyLatch,
|
wc = WaitLatchOrSocket(MyLatch,
|
||||||
WL_LATCH_SET | WL_SOCKET_READABLE |
|
WL_LATCH_SET | WL_SOCKET_READABLE |
|
||||||
WL_EXIT_ON_PM_DEATH,
|
WL_EXIT_ON_PM_DEATH,
|
||||||
PQsocket(conn),
|
PQsocket(conn),
|
||||||
-1L, WAIT_EVENT_EXTENSION);
|
-1L, pgfdw_we_get_result);
|
||||||
ResetLatch(MyLatch);
|
ResetLatch(MyLatch);
|
||||||
|
|
||||||
CHECK_FOR_INTERRUPTS();
|
CHECK_FOR_INTERRUPTS();
|
||||||
@ -1562,12 +1575,16 @@ pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, PGresult **result,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* first time, allocate or get the custom wait event */
|
||||||
|
if (pgfdw_we_cleanup_result == 0)
|
||||||
|
pgfdw_we_cleanup_result = WaitEventExtensionNew("PostgresFdwCleanupResult");
|
||||||
|
|
||||||
/* Sleep until there's something to do */
|
/* Sleep until there's something to do */
|
||||||
wc = WaitLatchOrSocket(MyLatch,
|
wc = WaitLatchOrSocket(MyLatch,
|
||||||
WL_LATCH_SET | WL_SOCKET_READABLE |
|
WL_LATCH_SET | WL_SOCKET_READABLE |
|
||||||
WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
|
WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
|
||||||
PQsocket(conn),
|
PQsocket(conn),
|
||||||
cur_timeout, WAIT_EVENT_EXTENSION);
|
cur_timeout, pgfdw_we_cleanup_result);
|
||||||
ResetLatch(MyLatch);
|
ResetLatch(MyLatch);
|
||||||
|
|
||||||
CHECK_FOR_INTERRUPTS();
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
@ -1042,6 +1042,44 @@ postgres=# SELECT postgres_fdw_disconnect_all();
|
|||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
|
<sect2 id="postgres-fdw-wait-events">
|
||||||
|
<title>Wait Events</title>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
<filename>postgres_fdw</filename> can report the following wait events
|
||||||
|
under the wait event type <literal>Extension</literal>:
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>PostgresFdwCleanupResult</literal></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Waiting for transaction abort on remote server.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>PostgresFdwConnect</literal></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Waiting to establish a connection to a remote server.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>PostgresFdwGetResult</literal></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Waiting to receive the results of a query from a remote server.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
</variablelist>
|
||||||
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="postgres-fdw-configuration-parameters">
|
<sect2 id="postgres-fdw-configuration-parameters">
|
||||||
<title>Configuration Parameters</title>
|
<title>Configuration Parameters</title>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user