Skip to content

Commit 039bfc4

Browse files
committed
aio: Improve debug logging around waiting for IOs
Trying to investigate a bug report by Alexander Lakhin made it apparent that the debug logging around waiting for IO completion is insufficient. Fix that. Discussion: https://postgr.es/m/h4in2db37vepagmi2oz5vvqymjasc5gyb4lpqkunj4eusu274i@37jpd3c2spd3
1 parent 500b617 commit 039bfc4

File tree

1 file changed

+25
-4
lines changed
  • src/backend/storage/aio

1 file changed

+25
-4
lines changed

src/backend/storage/aio/aio.c

+25-4
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,10 @@ pgaio_io_wait_for_free(void)
711711
{
712712
int reclaimed = 0;
713713

714-
pgaio_debug(DEBUG2, "waiting for self with %d pending",
715-
pgaio_my_backend->num_staged_ios);
714+
pgaio_debug(DEBUG2, "waiting for free IO with %d pending, %d in-flight, %d idle IOs",
715+
pgaio_my_backend->num_staged_ios,
716+
dclist_count(&pgaio_my_backend->in_flight_ios),
717+
dclist_is_empty(&pgaio_my_backend->idle_ios));
716718

717719
/*
718720
* First check if any of our IOs actually have completed - when using
@@ -743,7 +745,12 @@ pgaio_io_wait_for_free(void)
743745
pgaio_submit_staged();
744746

745747
if (dclist_count(&pgaio_my_backend->in_flight_ios) == 0)
746-
elog(ERROR, "no free IOs despite no in-flight IOs");
748+
ereport(ERROR,
749+
errmsg_internal("no free IOs despite no in-flight IOs"),
750+
errdetail_internal("%d pending, %d in-flight, %d idle IOs",
751+
pgaio_my_backend->num_staged_ios,
752+
dclist_count(&pgaio_my_backend->in_flight_ios),
753+
dclist_is_empty(&pgaio_my_backend->idle_ios)));
747754

748755
/*
749756
* Wait for the oldest in-flight IO to complete.
@@ -1136,7 +1143,13 @@ pgaio_closing_fd(int fd)
11361143
* For now just submit all staged IOs - we could be more selective, but
11371144
* it's probably not worth it.
11381145
*/
1139-
pgaio_submit_staged();
1146+
if (pgaio_my_backend->num_staged_ios > 0)
1147+
{
1148+
pgaio_debug(DEBUG2,
1149+
"submitting %d IOs before FD %d gets closed",
1150+
pgaio_my_backend->num_staged_ios, fd);
1151+
pgaio_submit_staged();
1152+
}
11401153

11411154
/*
11421155
* If requested by the IO method, wait for all IOs that use the
@@ -1168,6 +1181,10 @@ pgaio_closing_fd(int fd)
11681181
if (!ioh)
11691182
break;
11701183

1184+
pgaio_debug_io(DEBUG2, ioh,
1185+
"waiting for IO before FD %d gets closed, %d in-flight IOs",
1186+
fd, dclist_count(&pgaio_my_backend->in_flight_ios));
1187+
11711188
/* see comment in pgaio_io_wait_for_free() about raciness */
11721189
pgaio_io_wait(ioh, ioh->generation);
11731190
}
@@ -1199,6 +1216,10 @@ pgaio_shutdown(int code, Datum arg)
11991216
{
12001217
PgAioHandle *ioh = dclist_head_element(PgAioHandle, node, &pgaio_my_backend->in_flight_ios);
12011218

1219+
pgaio_debug_io(DEBUG2, ioh,
1220+
"waiting for IO to complete during shutdown, %d in-flight IOs",
1221+
dclist_count(&pgaio_my_backend->in_flight_ios));
1222+
12021223
/* see comment in pgaio_io_wait_for_free() about raciness */
12031224
pgaio_io_wait(ioh, ioh->generation);
12041225
}

0 commit comments

Comments
 (0)