aio: Fix assertion, clarify README
authorAndres Freund <andres@anarazel.de>
Tue, 22 Jul 2025 12:30:52 +0000 (08:30 -0400)
committerAndres Freund <andres@anarazel.de>
Tue, 22 Jul 2025 12:30:52 +0000 (08:30 -0400)
The assertion wouldn't have triggered for a long while yet, but this won't
accidentally fail to detect the issue if/when it occurs.

Author: Matthias van de Meent <boekewurm+postgres@gmail.com>
Discussion: https://postgr.es/m/CAEze2Wj-43JV4YufW23gm=Uwr7Lkj+p0yKctKHxNm1rwFC+_DQ@mail.gmail.com
Backpatch-through: 18

src/backend/storage/aio/README.md
src/include/storage/aio.h

index f10b5c7e31ec73d9785a41ca2ba2edc1b0590d46..72ae3b3737d51fae464ab202b3372c59e68484b0 100644 (file)
@@ -94,7 +94,7 @@ pgaio_io_register_callbacks(ioh, PGAIO_HCB_SHARED_BUFFER_READV, 0);
  *
  * In this example we're reading only a single buffer, hence the 1.
  */
-pgaio_io_set_handle_data_32(ioh, (uint32 *) buffer, 1);
+pgaio_io_set_handle_data_32(ioh, (uint32 *) &buffer, 1);
 
 /*
  * Pass the AIO handle to lower-level function. When operating on the level of
@@ -119,8 +119,9 @@ pgaio_io_set_handle_data_32(ioh, (uint32 *) buffer, 1);
  * e.g. due to reaching a limit on the number of unsubmitted IOs, and even
  * complete before smgrstartreadv() returns.
  */
+void *page = BufferGetBlock(buffer);
 smgrstartreadv(ioh, operation->smgr, forknum, blkno,
-               BufferGetBlock(buffer), 1);
+               &page, 1);
 
 /*
  * To benefit from AIO, it is beneficial to perform other work, including
index e7a0a234b6cf2b698cb22c8e99784a89af0438a7..2933eea064910d1e85a15ce2c172046a34ab47e1 100644 (file)
@@ -201,7 +201,7 @@ typedef enum PgAioHandleCallbackID
 } PgAioHandleCallbackID;
 
 #define PGAIO_HCB_MAX  PGAIO_HCB_LOCAL_BUFFER_READV
-StaticAssertDecl(PGAIO_HCB_MAX <= (1 << PGAIO_RESULT_ID_BITS),
+StaticAssertDecl(PGAIO_HCB_MAX < (1 << PGAIO_RESULT_ID_BITS),
                 "PGAIO_HCB_MAX is too big for PGAIO_RESULT_ID_BITS");