Skip to content

Commit c194805

Browse files
Antonin Houskahackorum
authored andcommitted
Teach isolation tester about injection points in background workers.
When session gets blocked, the isolation tester checks if the corresponding backend is waiting on a lock or on an injection point. If the backend launched a background worker, the isolation tester is able to detect when the worker is waiting on a lock - this is due to the concept of "lock groups". However, it does not recoginze that the background worker is waiting on an injection point. This patch tries to fix the problem by calling pg_isolation_test_session_is_blocked() not only for the backend, but also for its background worker(s). The assumption is that if the backend is blocked, and at the same time its background worker is waiting on an injection point, then that waiting is probably the reason for the backend to be blocked.
1 parent 19733fa commit c194805

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/test/isolation/isolationtester.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,22 @@ main(int argc, char **argv)
216216
* exactly expect concurrent use of test tables. However, autovacuum will
217217
* occasionally take AccessExclusiveLock to truncate a table, and we must
218218
* ignore that transient wait.
219+
*
220+
* If the session's backend is blocked, and if its background worker is
221+
* waiting on an injection point, we assume that the injection point is
222+
* the reason for the backend to be blocked. That's what we check in the
223+
* second query of the UNION. XXX Should we use a separate query for that?
219224
*/
220225
initPQExpBuffer(&wait_query);
221226
appendPQExpBufferStr(&wait_query,
227+
"WITH blocking(res) AS ("
222228
"SELECT pg_catalog.pg_isolation_test_session_is_blocked($1, '{");
223229
/* The spec syntax requires at least one session; assume that here. */
224230
appendPQExpBufferStr(&wait_query, conns[1].backend_pid_str);
225231
for (i = 2; i < nconns; i++)
226232
appendPQExpBuffer(&wait_query, ",%s", conns[i].backend_pid_str);
227-
appendPQExpBufferStr(&wait_query, "}')");
233+
appendPQExpBufferStr(&wait_query, "}') UNION "
234+
"SELECT pg_catalog.pg_isolation_test_session_is_blocked(pid, '{}') FROM pg_stat_activity WHERE leader_pid=$1) SELECT bool_or(res) FROM blocking");
228235

229236
res = PQprepare(conns[0].conn, PREP_WAITING, wait_query.data, 0, NULL);
230237
if (PQresultStatus(res) != PGRES_COMMAND_OK)

0 commit comments

Comments
 (0)