PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_aio.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * test_aio.c
4 * Helpers to write tests for AIO
5 *
6 * This module provides interface functions for C functionality to SQL, to
7 * make it possible to test AIO related behavior in a targeted way from SQL.
8 * It'd not generally be safe to export these functions to SQL, but for a test
9 * that's fine.
10 *
11 * Copyright (c) 2020-2026, PostgreSQL Global Development Group
12 *
13 * IDENTIFICATION
14 * src/test/modules/test_aio/test_aio.c
15 *
16 *-------------------------------------------------------------------------
17 */
18
19#include "postgres.h"
20
21#include "access/relation.h"
22#include "catalog/pg_type.h"
23#include "fmgr.h"
24#include "funcapi.h"
25#include "storage/aio.h"
28#include "storage/bufmgr.h"
29#include "storage/checksum.h"
31#include "storage/lwlock.h"
32#include "storage/proc.h"
33#include "storage/procnumber.h"
34#include "storage/read_stream.h"
35#include "utils/array.h"
36#include "utils/builtins.h"
38#include "utils/rel.h"
39#include "utils/tuplestore.h"
40#include "utils/wait_event.h"
41
42
44
45
46/* In shared memory */
65
72
73
75
76/* Shared memory init callbacks */
77static void test_aio_shmem_request(void *arg);
78static void test_aio_shmem_init(void *arg);
79static void test_aio_shmem_attach(void *arg);
80
86
87
89
90
91
92static void
94{
95 ShmemRequestStruct(.name = "test_aio injection points",
96 .size = sizeof(InjIoErrorState),
97 .ptr = (void **) &inj_io_error_state,
98 );
99}
100
101static void
103{
104 /* First time through, initialize */
108
111
112#ifdef USE_INJECTION_POINTS
113 InjectionPointAttach("aio-process-completion-before-shared",
114 "test_aio",
115 "inj_io_completion_hook",
116 NULL,
117 0);
118 InjectionPointLoad("aio-process-completion-before-shared");
119
120 InjectionPointAttach("aio-worker-after-reopen",
121 "test_aio",
122 "inj_io_reopen",
123 NULL,
124 0);
125 InjectionPointLoad("aio-worker-after-reopen");
126
127#endif
128}
129
130static void
132{
133 /*
134 * Pre-load the injection points now, so we can call them in a critical
135 * section.
136 */
137#ifdef USE_INJECTION_POINTS
138 InjectionPointLoad("aio-process-completion-before-shared");
139 InjectionPointLoad("aio-worker-after-reopen");
140 elog(LOG, "injection point loaded");
141#endif
142}
143
144void
152
153
155Datum
157{
158 const char *sym = text_to_cstring(PG_GETARG_TEXT_PP(0));
159
160 if (strcmp(sym, "EIO") == 0)
162 else if (strcmp(sym, "EAGAIN") == 0)
164 else if (strcmp(sym, "EINTR") == 0)
166 else if (strcmp(sym, "ENOSPC") == 0)
168 else if (strcmp(sym, "EROFS") == 0)
170
173 errmsg_internal("%s is not a supported errno value", sym));
175}
176
178Datum
180{
181 Oid relid = PG_GETARG_OID(0);
182 uint32 nblocks = PG_GETARG_UINT32(1);
183 Relation rel;
184#define MAX_BUFFERS_TO_EXTEND_BY 64
186
188
189 while (nblocks > 0)
190 {
192
194
197 NULL,
198 0,
202
203 nblocks -= extend_by_pages;
204
205 for (uint32 i = 0; i < extend_by_pages; i++)
206 {
208 }
209 }
210
212
214}
215
217Datum
219{
220 Oid relid = PG_GETARG_OID(0);
221 BlockNumber blkno = PG_GETARG_UINT32(1);
222 bool zero = PG_GETARG_BOOL(2);
226 bool flushed;
227 Relation rel;
228 Buffer buf;
230
232
233 buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno,
235
237
238 /*
239 * copy the page to local memory, seems nicer than to directly modify in
240 * the buffer pool.
241 */
243
245
246 /*
247 * Don't want to have a buffer in-memory that's marked valid where the
248 * on-disk contents are invalid. Particularly not if the in-memory buffer
249 * could be dirty...
250 *
251 * While we hold an AEL on the relation nobody else should be able to read
252 * the buffer in.
253 *
254 * NB: This is probably racy, better don't copy this to non-test code.
255 */
256 if (BufferIsLocal(buf))
258 else
260
261 /*
262 * Now modify the page as asked for by the caller.
263 */
264 if (zero)
265 memset(page, 0, BufferGetPageSize(buf));
266
268 PageInit(page, BufferGetPageSize(buf), 0);
269
270 ph = (PageHeader) page;
271
272 if (corrupt_header)
273 ph->pd_special = BLCKSZ + 1;
274
276 {
277 bool successfully_corrupted = 0;
278
279 /*
280 * Any single modification of the checksum could just end up being
281 * valid again, due to e.g. corrupt_header changing the data in a way
282 * that'd result in the "corrupted" checksum, or the checksum already
283 * being invalid. Retry in that, unlikely, case.
284 */
285 for (int i = 0; i < 100; i++)
286 {
287 uint16 verify_checksum;
289
290 old_checksum = ph->pd_checksum;
291 ph->pd_checksum = old_checksum + 1;
292
293 elog(LOG, "corrupting checksum of blk %u from %u to %u",
294 blkno, old_checksum, ph->pd_checksum);
295
296 verify_checksum = pg_checksum_page(page, blkno);
297 if (verify_checksum != ph->pd_checksum)
298 {
300 break;
301 }
302 }
303
305 elog(ERROR, "could not corrupt checksum, what's going on?");
306 }
307 else
308 {
309 PageSetChecksum(page, blkno);
310 }
311
313 MAIN_FORKNUM, blkno, page, true);
314
316
318}
319
320/*
321 * Ensures a buffer for rel & blkno is in shared buffers, without actually
322 * caring about the buffer contents. Used to set up test scenarios.
323 */
324static Buffer
326{
327 Buffer buf;
330 bool was_pinned = false;
331 uint64 unset_bits = 0;
332
333 /* place buffer in shared buffers without erroring out */
336
338 {
341 }
342 else
343 {
346 }
347
348 /*
349 * We should be the only backend accessing this buffer. This is just a
350 * small bit of belt-and-suspenders defense, none of this code should ever
351 * run in a cluster with real data.
352 */
354 was_pinned = true;
355 else
357
359 {
362 }
363 else
364 {
366 }
367
368 if (was_pinned)
369 elog(ERROR, "toy buffer %d was already pinned",
370 buf);
371
372 return buf;
373}
374
375/*
376 * A "low level" read. This does similar things to what
377 * StartReadBuffers()/WaitReadBuffers() do, but provides more control (and
378 * less sanity).
379 */
381Datum
383{
384 Oid relid = PG_GETARG_OID(0);
385 BlockNumber blkno = PG_GETARG_UINT32(1);
386 int nblocks = PG_GETARG_INT32(2);
392 Relation rel;
395 Page pages[PG_IOV_MAX];
396 uint8 srb_flags = 0;
400 SMgrRelation smgr;
401
403 elog(ERROR, "nblocks is out of range");
404
405 rel = relation_open(relid, AccessShareLock);
406
407 for (int i = 0; i < nblocks; i++)
408 {
409 bufs[i] = create_toy_buffer(rel, blkno + i);
410 pages[i] = BufferGetBlock(bufs[i]);
414 }
415
416 smgr = RelationGetSmgr(rel);
417
419
422
424 {
425 for (int i = 0; i < nblocks; i++)
426 StartLocalBufferIO(buf_hdrs[i], true, true, NULL);
428 }
429 else
430 {
431 for (int i = 0; i < nblocks; i++)
432 StartSharedBufferIO(buf_hdrs[i], true, true, NULL);
433 }
434
436
441
446 srb_flags);
447
448 if (batchmode_enter)
450
451 smgrstartreadv(ioh, smgr, MAIN_FORKNUM, blkno,
452 (void *) pages, nblocks);
453
456
457 if (batchmode_exit)
459
460 for (int i = 0; i < nblocks; i++)
462
463 if (wait_complete)
464 {
466
467 if (ior.result.status != PGAIO_RS_OK)
469 &ior.target_data,
470 ior.result.status == PGAIO_RS_ERROR ?
471 ERROR : WARNING);
472 }
473
475
477}
478
479/* helper for invalidate_rel_block() and evict_rel() */
480static void
482{
484 Buffer buf;
485
486 /*
487 * This is a gross hack, but there's no other API exposed that allows to
488 * get a buffer ID without actually reading the block in.
489 */
490 pr = PrefetchBuffer(rel, forknum, blkno);
491 buf = pr.recent_buffer;
492
493 if (BufferIsValid(buf))
494 {
495 /* if the buffer contents aren't valid, this'll return false */
496 if (ReadRecentBuffer(rel->rd_locator, forknum, blkno, buf))
497 {
501 bool flushed;
502
504
505 if (pg_atomic_read_u64(&buf_hdr->state) & BM_DIRTY)
506 {
507 if (BufferIsLocal(buf))
509 else
511 }
513
514 if (BufferIsLocal(buf))
516 else if (!EvictUnpinnedBuffer(buf, &flushed))
517 elog(ERROR, "couldn't evict");
518 }
519 }
520
521}
522
524Datum
526{
527 Oid relid = PG_GETARG_OID(0);
528 BlockNumber blkno = PG_GETARG_UINT32(1);
529 Relation rel;
530
532
534
536
538}
539
541Datum
543{
544 Oid relid = PG_GETARG_OID(0);
545 Relation rel;
546
548
549 /*
550 * EvictRelUnpinnedBuffers() doesn't support temp tables, so for temp
551 * tables we have to do it the expensive way and evict every possible
552 * buffer.
553 */
555 {
556 SMgrRelation smgr = RelationGetSmgr(rel);
557
558 for (int forknum = MAIN_FORKNUM; forknum <= MAX_FORKNUM; forknum++)
559 {
560 BlockNumber nblocks;
561
562 if (!smgrexists(smgr, forknum))
563 continue;
564
565 nblocks = smgrnblocks(smgr, forknum);
566
567 for (int blkno = 0; blkno < nblocks; blkno++)
568 {
569 invalidate_one_block(rel, forknum, blkno);
570 }
571 }
572 }
573 else
574 {
578
581 }
582
584
585
587}
588
590Datum
592{
593 Oid relid = PG_GETARG_OID(0);
594 BlockNumber blkno = PG_GETARG_UINT32(1);
595 Relation rel;
596 Buffer buf;
597
599
600 buf = create_toy_buffer(rel, blkno);
602
604
606}
607
609Datum
611{
613 bool for_input = PG_GETARG_BOOL(1);
614 bool wait = PG_GETARG_BOOL(2);
616 bool can_start;
617
618 if (BufferIsLocal(buf))
620 for_input, wait, NULL);
621 else
623 for_input, wait, NULL);
624
626
627 /*
628 * For tests we don't want the resowner release preventing us from
629 * orchestrating odd scenarios.
630 */
631 if (can_start && !BufferIsLocal(buf))
633 buf);
634
635 ereport(LOG,
636 errmsg("buffer %d after StartBufferIO: %s",
638 errhidestmt(true), errhidecontext(true));
639
641}
642
644Datum
646{
648 bool for_input = PG_GETARG_BOOL(1);
649 bool succeed = PG_GETARG_BOOL(2);
650 bool io_error = PG_GETARG_BOOL(3);
651 bool release_aio = PG_GETARG_BOOL(4);
652 bool clear_dirty = false;
654
655 if (io_error)
657
658 if (for_input)
659 {
660 clear_dirty = false;
661
662 if (succeed)
664 }
665 else
666 {
667 if (succeed)
668 clear_dirty = true;
669 }
670
671 ereport(LOG,
672 errmsg("buffer %d before Terminate[Local]BufferIO: %s",
674 errhidestmt(true), errhidecontext(true));
675
676 if (BufferIsLocal(buf))
679 else
682
683 ereport(LOG,
684 errmsg("buffer %d after Terminate[Local]BufferIO: %s",
686 errhidestmt(true), errhidecontext(true));
687
689}
690
692/*
693 * Infrastructure to test StartReadBuffers()
694 */
695Datum
697{
698 Oid relid = PG_GETARG_OID(0);
699 BlockNumber startblock = PG_GETARG_UINT32(1);
700 int32 nblocks = PG_GETARG_INT32(2);
701 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
702 Relation rel;
703 SMgrRelation smgr;
704 int nblocks_done = 0;
705 int nblocks_disp = 0;
706 int nios = 0;
708 Buffer *buffers;
710 bool *io_reqds;
711 int *nblocks_per_io;
712
713 Assert(nblocks > 0);
714
715 InitMaterializedSRF(fcinfo, 0);
716
717 /* at worst each block gets its own IO */
718 operations = palloc0(sizeof(ReadBuffersOperation) * nblocks);
719 buffers = palloc0(sizeof(Buffer) * nblocks);
720 buffers_datum = palloc0(sizeof(Datum) * nblocks);
721 io_reqds = palloc0(sizeof(bool) * nblocks);
722 nblocks_per_io = palloc0(sizeof(int) * nblocks);
723
724 rel = relation_open(relid, AccessShareLock);
725 smgr = RelationGetSmgr(rel);
726
727 /*
728 * Do StartReadBuffers() until IO for all the required blocks has been
729 * started (if required).
730 */
731 while (nblocks_done < nblocks)
732 {
734 int nblocks_this_io =
735 Min(nblocks - nblocks_done, io_combine_limit);
736
737 operation->rel = rel;
738 operation->smgr = smgr;
739 operation->persistence = rel->rd_rel->relpersistence;
740 operation->strategy = NULL;
741 operation->forknum = MAIN_FORKNUM;
742
744 &buffers[nblocks_done],
745 startblock + nblocks_done,
747 0);
749 nios++;
750 nblocks_done += nblocks_this_io;
751 }
752
753 /*
754 * Now wait for all operations that required IO. This is done at the end,
755 * as otherwise waiting for IO in progress in other backends could
756 * influence the result for subsequent buffers / blocks.
757 */
758 for (int nio = 0; nio < nios; nio++)
759 {
761
762 if (io_reqds[nio])
764 }
765
766 /*
767 * Convert what has been done into SQL SRF return value.
768 */
769 for (int nio = 0; nio < nios; nio++)
770 {
773 Datum values[6] = {0};
774 bool nulls[6] = {0};
776
777 /* convert buffer array to datum array */
778 for (int i = 0; i < nblocks_this_io; i++)
779 {
780 Buffer buf = buffers[nblocks_disp + i];
781
782 Assert(BufferGetBlockNumber(buf) == startblock + nblocks_disp + i);
783
785 }
786
789 INT4OID);
790
791 /* blockoff */
793 nulls[0] = false;
794
795 /* blocknum */
796 values[1] = UInt32GetDatum(startblock + nblocks_disp);
797 nulls[1] = false;
798
799 /* io_reqd */
801 nulls[2] = false;
802
803 /* foreign IO - only valid when IO was required */
804 values[3] = BoolGetDatum(io_reqds[nio] ? operation->foreign_io : false);
805 nulls[3] = false;
806
807 /* nblocks */
809 nulls[4] = false;
810
811 /* array of buffers */
813 nulls[5] = false;
814
815 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
816
818 }
819
820 /* release pins on all the buffers */
821 for (int i = 0; i < nblocks_done; i++)
822 ReleaseBuffer(buffers[i]);
823
824 /*
825 * Free explicitly, to have a chance to detect potential issues with too
826 * long lived references to the operation.
827 */
829 pfree(buffers);
833
835
836 return (Datum) 0;
837}
838
839
840static BlockNumber
842 void *callback_private_data,
843 void *per_buffer_data)
844{
845 BlocksReadStreamData *stream_data = callback_private_data;
846
847 if (stream_data->curblock >= stream_data->nblocks)
848 return InvalidBlockNumber;
849 return stream_data->blocks[stream_data->curblock++];
850}
851
853Datum
855{
856 Oid relid = PG_GETARG_OID(0);
858 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
859 Relation rel;
861 ReadStream *stream;
862
863 InitMaterializedSRF(fcinfo, 0);
864
865 /*
866 * We expect the input to be an N-element int4 array; verify that. We
867 * don't need to use deconstruct_array() since the array data is just
868 * going to look like a C array of N int4 values.
869 */
870 if (ARR_NDIM(blocksarray) != 1 ||
873 elog(ERROR, "expected 1 dimensional int4 array");
874
875 stream_data.curblock = 0;
876 stream_data.nblocks = ARR_DIMS(blocksarray)[0];
878
879 rel = relation_open(relid, AccessShareLock);
880
882 NULL,
883 rel,
887 0);
888
889 for (int i = 0; i < stream_data.nblocks; i++)
890 {
892 Datum values[3] = {0};
893 bool nulls[3] = {0};
894
895 if (!BufferIsValid(buf))
896 elog(ERROR, "read_stream_next_buffer() call %d is unexpectedly invalid", i);
897
898 values[0] = Int32GetDatum(i);
899 values[1] = UInt32GetDatum(stream_data.blocks[i]);
901
902 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
903
905 }
906
908 elog(ERROR, "read_stream_next_buffer() call %d is unexpectedly valid",
909 stream_data.nblocks);
910
911 read_stream_end(stream);
912
914
915 return (Datum) 0;
916}
917
918
920Datum
927
929Datum
931{
932 if (!last_handle)
933 elog(ERROR, "no handle");
934
936
938}
939
941Datum
949
951Datum
959
961Datum
971
973Datum
979
981Datum
987
988#ifdef USE_INJECTION_POINTS
989extern PGDLLEXPORT void inj_io_completion_hook(const char *name,
990 const void *private_data,
991 void *arg);
992extern PGDLLEXPORT void inj_io_reopen(const char *name,
993 const void *private_data,
994 void *arg);
995
996static bool
998{
1000 int32 io_pid;
1001 int32 inj_pid;
1002 PgAioTargetData *td;
1003
1005 return false;
1006
1008 return false;
1009
1011 io_pid = io_proc->pid;
1013
1014 if (inj_pid != InvalidPid && inj_pid != io_pid)
1015 return false;
1016
1018
1021 return false;
1022
1023 /*
1024 * Only shorten reads that are actually longer than the target size,
1025 * otherwise we can trigger over-reads.
1026 */
1028 return false;
1029
1030 return true;
1031}
1032
1033static bool
1035{
1036 PGPROC *io_proc;
1037 int32 io_pid;
1038 PgAioTargetData *td;
1039 int32 inj_pid;
1043
1045 return false;
1046
1048 io_pid = io_proc->pid;
1050
1051 if (inj_pid != InvalidPid && inj_pid != io_pid)
1052 return false;
1053
1055
1057 if (inj_relfilenode != InvalidOid &&
1059 return false;
1060
1062 io_blockno = td->smgr.blockNum;
1065 return false;
1066
1067 return true;
1068}
1069
1070static void
1071inj_io_completion_wait_hook(const char *name, const void *private_data, void *arg)
1072{
1074
1076 return;
1077
1079
1080 while (true)
1081 {
1083 break;
1084
1087 }
1088
1090}
1091
1092static void
1093inj_io_short_read_hook(const char *name, const void *private_data, void *arg)
1094{
1096
1097 ereport(LOG,
1098 errmsg("short read injection point called, is enabled: %d",
1100 errhidestmt(true), errhidecontext(true));
1101
1103 {
1104 struct iovec *iov = &pgaio_ctl->iovecs[ioh->iovec_off];
1105 int32 old_result = ioh->result;
1107 int32 processed = 0;
1108
1109 ereport(LOG,
1110 errmsg("short read inject point, changing result from %d to %d",
1112 errhidestmt(true), errhidecontext(true));
1113
1114 /*
1115 * The underlying IO actually completed OK, and thus the "invalid"
1116 * portion of the IOV actually contains valid data. That can hide a
1117 * lot of problems, e.g. if we were to wrongly mark a buffer, that
1118 * wasn't read according to the shortened-read, IO as valid, the
1119 * contents would look valid and we might miss a bug.
1120 *
1121 * To avoid that, iterate through the IOV and zero out the "failed"
1122 * portion of the IO.
1123 */
1124 for (int i = 0; i < ioh->op_data.read.iov_length; i++)
1125 {
1126 if (processed + iov[i].iov_len <= new_result)
1127 processed += iov[i].iov_len;
1128 else if (processed <= new_result)
1129 {
1130 uint32 ok_part = new_result - processed;
1131
1132 memset((char *) iov[i].iov_base + ok_part, 0, iov[i].iov_len - ok_part);
1133 processed += iov[i].iov_len;
1134 }
1135 else
1136 {
1137 memset((char *) iov[i].iov_base, 0, iov[i].iov_len);
1138 }
1139 }
1140
1141 ioh->result = new_result;
1142 }
1143}
1144
1145void
1146inj_io_completion_hook(const char *name, const void *private_data, void *arg)
1147{
1148 inj_io_completion_wait_hook(name, private_data, arg);
1149 inj_io_short_read_hook(name, private_data, arg);
1150}
1151
1152void
1153inj_io_reopen(const char *name, const void *private_data, void *arg)
1154{
1155 ereport(LOG,
1156 errmsg("reopen injection point called, is enabled: %d",
1158 errhidestmt(true), errhidecontext(true));
1159
1161 elog(ERROR, "injection point triggering failure to reopen ");
1162}
1163#endif
1164
1166Datum
1183
1185Datum
1200
1202Datum
1220
1222Datum
1224{
1225#ifdef USE_INJECTION_POINTS
1227#else
1228 elog(ERROR, "injection points not supported");
1229#endif
1231}
1232
1234Datum
1236{
1237#ifdef USE_INJECTION_POINTS
1239#else
1240 elog(ERROR, "injection points not supported");
1241#endif
1242
1244}
1245
1247Datum
1249{
1250#ifdef USE_INJECTION_POINTS
1252#else
1253 elog(ERROR, "injection points not supported");
1254#endif
1256}
PgAioHandle * pgaio_io_acquire(struct ResourceOwnerData *resowner, PgAioReturn *ret)
Definition aio.c:162
void pgaio_io_get_wref(PgAioHandle *ioh, PgAioWaitRef *iow)
Definition aio.c:366
void pgaio_io_set_flag(PgAioHandle *ioh, PgAioHandleFlags flag)
Definition aio.c:330
PgAioCtl * pgaio_ctl
Definition aio.c:78
ProcNumber pgaio_io_get_owner(PgAioHandle *ioh)
Definition aio.c:355
void pgaio_enter_batchmode(void)
Definition aio.c:1091
void pgaio_wref_wait(PgAioWaitRef *iow)
Definition aio.c:991
void pgaio_io_release(PgAioHandle *ioh)
Definition aio.c:240
void pgaio_exit_batchmode(void)
Definition aio.c:1102
@ PGAIO_HCB_LOCAL_BUFFER_READV
Definition aio.h:200
@ PGAIO_HCB_SHARED_BUFFER_READV
Definition aio.h:198
@ PGAIO_HF_REFERENCES_LOCAL
Definition aio.h:60
void pgaio_io_set_handle_data_32(PgAioHandle *ioh, uint32 *data, uint8 len)
void pgaio_io_register_callbacks(PgAioHandle *ioh, PgAioHandleCallbackID cb_id, uint8 cb_data)
void pgaio_result_report(PgAioResult result, const PgAioTargetData *target_data, int elevel)
PgAioTargetData * pgaio_io_get_target_data(PgAioHandle *ioh)
Definition aio_target.c:73
@ PGAIO_RS_OK
Definition aio_types.h:81
@ PGAIO_RS_ERROR
Definition aio_types.h:84
#define ARR_NDIM(a)
Definition array.h:290
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
#define ARR_DATA_PTR(a)
Definition array.h:322
#define ARR_ELEMTYPE(a)
Definition array.h:292
#define ARR_DIMS(a)
Definition array.h:294
#define ARR_HASNULL(a)
Definition array.h:291
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
static void pg_atomic_unlocked_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:494
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition atomics.h:467
uint32 BlockNumber
Definition block.h:31
#define InvalidBlockNumber
Definition block.h:33
static Datum values[MAXATTR]
Definition bootstrap.c:190
int Buffer
Definition buf.h:23
#define InvalidBuffer
Definition buf.h:25
#define BufferIsLocal(buffer)
Definition buf.h:37
static uint64 UnlockBufHdrExt(BufferDesc *desc, uint64 old_buf_state, uint64 set_bits, uint64 unset_bits, int refcount_change)
#define BM_DIRTY
StartBufferIOResult
@ BUFFER_IO_READY_FOR_IO
static void ResourceOwnerForgetBufferIO(ResourceOwner owner, Buffer buffer)
#define BUF_STATE_GET_REFCOUNT(state)
#define BM_VALID
#define BM_IO_ERROR
static BufferDesc * GetLocalBufferDescriptor(uint32 id)
static BufferDesc * GetBufferDescriptor(uint32 id)
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition bufmgr.c:4446
PrefetchBufferResult PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
Definition bufmgr.c:787
bool StartReadBuffers(ReadBuffersOperation *operation, Buffer *buffers, BlockNumber blockNum, int *nblocks, int flags)
Definition bufmgr.c:1609
bool zero_damaged_pages
Definition bufmgr.c:189
void EvictRelUnpinnedBuffers(Relation rel, int32 *buffers_evicted, int32 *buffers_flushed, int32 *buffers_skipped)
Definition bufmgr.c:8032
BlockNumber ExtendBufferedRelBy(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, uint32 extend_by, Buffer *buffers, uint32 *extended_by)
Definition bufmgr.c:1011
char * DebugPrintBufferRefcount(Buffer buffer)
Definition bufmgr.c:4389
uint64 LockBufHdr(BufferDesc *desc)
Definition bufmgr.c:7518
StartBufferIOResult StartSharedBufferIO(BufferDesc *buf, bool forInput, bool wait, PgAioWaitRef *io_wref)
Definition bufmgr.c:7241
void ReleaseBuffer(Buffer buffer)
Definition bufmgr.c:5586
void UnlockReleaseBuffer(Buffer buffer)
Definition bufmgr.c:5603
bool WaitReadBuffers(ReadBuffersOperation *operation)
Definition bufmgr.c:1750
bool EvictUnpinnedBuffer(Buffer buf, bool *buffer_flushed)
Definition bufmgr.c:7953
bool ReadRecentBuffer(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber blockNum, Buffer recent_buffer)
Definition bufmgr.c:818
void TerminateBufferIO(BufferDesc *buf, bool clear_dirty, uint64 set_flag_bits, bool forget_owner, bool release_aio)
Definition bufmgr.c:7358
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition bufmgr.c:926
int io_combine_limit
Definition bufmgr.c:215
void FlushOneBuffer(Buffer buffer)
Definition bufmgr.c:5566
#define READ_BUFFERS_ZERO_ON_ERROR
Definition bufmgr.h:122
static Page BufferGetPage(Buffer buffer)
Definition bufmgr.h:468
static Block BufferGetBlock(Buffer buffer)
Definition bufmgr.h:435
@ BUFFER_LOCK_EXCLUSIVE
Definition bufmgr.h:222
@ BUFFER_LOCK_UNLOCK
Definition bufmgr.h:207
#define READ_BUFFERS_IGNORE_CHECKSUM_FAILURES
Definition bufmgr.h:126
static Size BufferGetPageSize(Buffer buffer)
Definition bufmgr.h:457
static void LockBuffer(Buffer buffer, BufferLockMode mode)
Definition bufmgr.h:334
@ RBM_ZERO_ON_ERROR
Definition bufmgr.h:51
@ RBM_ZERO_AND_LOCK
Definition bufmgr.h:47
#define BMR_REL(p_rel)
Definition bufmgr.h:114
static bool BufferIsValid(Buffer bufnum)
Definition bufmgr.h:419
bool ignore_checksum_failure
Definition bufpage.c:27
void PageSetChecksum(Page page, BlockNumber blkno)
Definition bufpage.c:1518
void PageInit(Page page, Size pageSize, Size specialSize)
Definition bufpage.c:42
static bool PageIsEmpty(const PageData *page)
Definition bufpage.h:248
PageHeaderData * PageHeader
Definition bufpage.h:199
PageData * Page
Definition bufpage.h:81
#define Min(x, y)
Definition c.h:1091
uint8_t uint8
Definition c.h:622
#define Assert(condition)
Definition c.h:943
#define PGDLLEXPORT
Definition c.h:1436
int32_t int32
Definition c.h:620
uint64_t uint64
Definition c.h:625
uint16_t uint16
Definition c.h:623
uint32_t uint32
Definition c.h:624
uint16 pg_checksum_page(char *page, BlockNumber blkno)
uint32 result
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
bool ConditionVariableCancelSleep(void)
void ConditionVariableBroadcast(ConditionVariable *cv)
void ConditionVariablePrepareToSleep(ConditionVariable *cv)
void ConditionVariableInit(ConditionVariable *cv)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
static DataChecksumsWorkerOperation operation
Datum arg
Definition elog.c:1322
int errcode(int sqlerrcode)
Definition elog.c:874
int int errhidestmt(bool hide_stmt)
#define LOG
Definition elog.h:31
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define WARNING
Definition elog.h:36
#define ERROR
Definition elog.h:39
int errhidecontext(bool hide_ctx)
#define elog(elevel,...)
Definition elog.h:227
#define ereport(elevel,...)
Definition elog.h:151
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define PG_GETARG_UINT32(n)
Definition fmgr.h:270
#define PG_ARGISNULL(n)
Definition fmgr.h:209
#define PG_FUNCTION_INFO_V1(funcname)
Definition fmgr.h:417
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
void InitMaterializedSRF(FunctionCallInfo fcinfo, uint32 flags)
Definition funcapi.c:76
void InjectionPointLoad(const char *name)
void InjectionPointAttach(const char *name, const char *library, const char *function, const void *private_data, int private_data_size)
int i
Definition isn.c:77
void FlushLocalBuffer(BufferDesc *bufHdr, SMgrRelation reln)
Definition localbuf.c:183
StartBufferIOResult StartLocalBufferIO(BufferDesc *bufHdr, bool forInput, bool wait, PgAioWaitRef *io_wref)
Definition localbuf.c:524
void InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced)
Definition localbuf.c:621
void TerminateLocalBufferIO(BufferDesc *bufHdr, bool clear_dirty, uint64 set_flag_bits, bool release_aio)
Definition localbuf.c:578
#define NoLock
Definition lockdefs.h:34
#define AccessExclusiveLock
Definition lockdefs.h:43
#define AccessShareLock
Definition lockdefs.h:36
void pfree(void *pointer)
Definition mcxt.c:1616
void * palloc0(Size size)
Definition mcxt.c:1417
void * palloc_aligned(Size size, Size alignto, int flags)
Definition mcxt.c:1606
#define InvalidPid
Definition miscadmin.h:32
bool process_shared_preload_libraries_in_progress
Definition miscinit.c:1788
static char * errmsg
#define PG_IO_ALIGN_SIZE
#define PG_IOV_MAX
Definition pg_iovec.h:47
static char buf[DEFAULT_XLOG_SEG_SIZE]
void pgstat_prepare_report_checksum_failure(Oid dboid)
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
uint64_t Datum
Definition postgres.h:70
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
static Datum UInt32GetDatum(uint32 X)
Definition postgres.h:232
#define InvalidOid
unsigned int Oid
static int fb(int x)
#define GetPGProcByNumber(n)
Definition proc.h:504
Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
ReadStream * read_stream_begin_relation(int flags, BufferAccessStrategy strategy, Relation rel, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
void read_stream_end(ReadStream *stream)
#define READ_STREAM_FULL
Definition read_stream.h:43
static SMgrRelation RelationGetSmgr(Relation rel)
Definition rel.h:578
#define RelationUsesLocalBuffers(relation)
Definition rel.h:648
ForkNumber
Definition relpath.h:56
@ MAIN_FORKNUM
Definition relpath.h:58
#define MAX_FORKNUM
Definition relpath.h:70
ResourceOwner CurrentResourceOwner
Definition resowner.c:173
void RegisterShmemCallbacks(const ShmemCallbacks *callbacks)
Definition shmem.c:874
#define ShmemRequestStruct(...)
Definition shmem.h:176
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition smgr.c:819
void smgrstartreadv(PgAioHandle *ioh, SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
Definition smgr.c:753
void smgrreleaseall(void)
Definition smgr.c:412
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Definition smgr.c:462
static void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
Definition smgr.h:131
void relation_close(Relation relation, LOCKMODE lockmode)
Definition relation.c:206
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition relation.c:48
bool enabled_reopen
Definition test_aio.c:52
pid_t short_read_pid
Definition test_aio.c:62
int short_read_result
Definition test_aio.c:63
ConditionVariable cv
Definition test_aio.c:49
BlockNumber completion_wait_blockno
Definition test_aio.c:56
bool enabled_short_read
Definition test_aio.c:51
pid_t completion_wait_pid
Definition test_aio.c:57
bool enabled_completion_wait
Definition test_aio.c:54
uint32 completion_wait_event
Definition test_aio.c:58
Oid short_read_relfilenode
Definition test_aio.c:61
Oid completion_wait_relfilenode
Definition test_aio.c:55
bool short_read_result_set
Definition test_aio.c:60
Definition proc.h:179
struct iovec * iovecs
RelFileLocator locator
RelFileNumber relNumber
RelFileLocator rd_locator
Definition rel.h:57
Form_pg_class rd_rel
Definition rel.h:111
RelFileLocatorBackend smgr_rlocator
Definition smgr.h:38
ShmemRequestCallback request_fn
Definition shmem.h:133
static void invalidate_one_block(Relation rel, ForkNumber forknum, BlockNumber blkno)
Definition test_aio.c:481
Datum batch_end(PG_FUNCTION_ARGS)
Definition test_aio.c:982
static Buffer create_toy_buffer(Relation rel, BlockNumber blkno)
Definition test_aio.c:325
Datum inj_io_completion_wait(PG_FUNCTION_ARGS)
Definition test_aio.c:1167
void _PG_init(void)
Definition test_aio.c:145
Datum evict_rel(PG_FUNCTION_ARGS)
Definition test_aio.c:542
Datum buffer_create_toy(PG_FUNCTION_ARGS)
Definition test_aio.c:591
Datum inj_io_reopen_detach(PG_FUNCTION_ARGS)
Definition test_aio.c:1248
Datum buffer_call_terminate_io(PG_FUNCTION_ARGS)
Definition test_aio.c:645
static PgAioHandle * last_handle
Definition test_aio.c:88
Datum inj_io_completion_continue(PG_FUNCTION_ARGS)
Definition test_aio.c:1186
Datum read_rel_block_ll(PG_FUNCTION_ARGS)
Definition test_aio.c:382
PG_MODULE_MAGIC
Definition test_aio.c:43
Datum invalidate_rel_block(PG_FUNCTION_ARGS)
Definition test_aio.c:525
static const ShmemCallbacks inj_io_shmem_callbacks
Definition test_aio.c:81
static void test_aio_shmem_attach(void *arg)
Definition test_aio.c:131
Datum grow_rel(PG_FUNCTION_ARGS)
Definition test_aio.c:179
static BlockNumber read_stream_for_blocks_cb(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
Definition test_aio.c:841
static void test_aio_shmem_request(void *arg)
Definition test_aio.c:93
Datum handle_get_release(PG_FUNCTION_ARGS)
Definition test_aio.c:962
Datum read_stream_for_blocks(PG_FUNCTION_ARGS)
Definition test_aio.c:854
Datum buffer_call_start_io(PG_FUNCTION_ARGS)
Definition test_aio.c:610
#define MAX_BUFFERS_TO_EXTEND_BY
Datum inj_io_reopen_attach(PG_FUNCTION_ARGS)
Definition test_aio.c:1235
Datum inj_io_short_read_detach(PG_FUNCTION_ARGS)
Definition test_aio.c:1223
Datum handle_get(PG_FUNCTION_ARGS)
Definition test_aio.c:921
Datum batch_start(PG_FUNCTION_ARGS)
Definition test_aio.c:974
Datum modify_rel_block(PG_FUNCTION_ARGS)
Definition test_aio.c:218
Datum handle_get_and_error(PG_FUNCTION_ARGS)
Definition test_aio.c:942
Datum inj_io_short_read_attach(PG_FUNCTION_ARGS)
Definition test_aio.c:1203
static InjIoErrorState * inj_io_error_state
Definition test_aio.c:74
Datum read_buffers(PG_FUNCTION_ARGS)
Definition test_aio.c:696
Datum handle_release_last(PG_FUNCTION_ARGS)
Definition test_aio.c:930
static void test_aio_shmem_init(void *arg)
Definition test_aio.c:102
Datum handle_get_twice(PG_FUNCTION_ARGS)
Definition test_aio.c:952
Datum errno_from_string(PG_FUNCTION_ARGS)
Definition test_aio.c:156
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition tuplestore.c:785
BlockNumber blockNum
Definition aio_types.h:66
RelFileLocator rlocator
Definition aio_types.h:65
struct PgAioTargetData::@131 smgr
BlockNumber nblocks
Definition aio_types.h:67
char * text_to_cstring(const text *t)
Definition varlena.c:217
uint32 WaitEventInjectionPointNew(const char *wait_event_name)
Definition wait_event.c:155
const char * name
#define EINTR
Definition win32_port.h:361
#define EAGAIN
Definition win32_port.h:359