88#ifdef USE_INJECTION_POINTS
111#ifdef USE_INJECTION_POINTS
114 elog(
LOG,
"injection point loaded");
140 if (strcmp(sym,
"EIO") == 0)
142 else if (strcmp(sym,
"EAGAIN") == 0)
144 else if (strcmp(sym,
"EINTR") == 0)
146 else if (strcmp(sym,
"ENOSPC") == 0)
148 else if (strcmp(sym,
"EROFS") == 0)
152 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
164#define MAX_BUFFERS_TO_EXTEND_BY 64
183 nblocks -= extend_by_pages;
185 for (
uint32 i = 0;
i < extend_by_pages;
i++)
249 if (
PageIsEmpty(page) && (corrupt_header || corrupt_checksum))
257 if (corrupt_checksum)
259 bool successfully_corrupted = 0;
267 for (
int i = 0;
i < 100;
i++)
275 elog(
LOG,
"corrupting checksum of blk %u from %u to %u",
281 successfully_corrupted =
true;
286 if (!successfully_corrupted)
287 elog(
ERROR,
"could not corrupt checksum, what's going on?");
312 bool was_pinned =
false;
345 elog(
ERROR,
"toy buffer %d was already pinned",
383 for (
int i = 0;
i < nblocks;
i++)
401 for (
int i = 0;
i < nblocks;
i++)
407 for (
int i = 0;
i < nblocks;
i++)
428 (
void *) pages, nblocks);
430 if (call_smgrreleaseall)
436 for (
int i = 0;
i < nblocks;
i++)
552 errmsg(
"buffer %d after StartBufferIO: %s",
568 bool clear_dirty =
false;
588 errmsg(
"buffer %d before Terminate[Local]BufferIO: %s",
594 clear_dirty, set_flag_bits, release_aio);
597 clear_dirty, set_flag_bits,
false, release_aio);
600 errmsg(
"buffer %d after Terminate[Local]BufferIO: %s",
676#ifdef USE_INJECTION_POINTS
677extern PGDLLEXPORT void inj_io_short_read(
const char *
name,
const void *private_data);
678extern PGDLLEXPORT void inj_io_reopen(
const char *
name,
const void *private_data);
681inj_io_short_read(
const char *
name,
const void *private_data)
686 errmsg(
"short read injection point called, is enabled: %d",
692 ioh = pgaio_inj_io_get();
708 errmsg(
"short read inject point, changing result from %d to %d",
709 old_result, new_result),
724 if (processed + iov[
i].iov_len <= new_result)
725 processed += iov[
i].iov_len;
726 else if (processed <= new_result)
728 uint32 ok_part = new_result - processed;
730 memset((
char *) iov[
i].iov_base + ok_part, 0, iov[
i].iov_len - ok_part);
731 processed += iov[
i].iov_len;
735 memset((
char *) iov[
i].iov_base, 0, iov[
i].iov_len);
745inj_io_reopen(
const char *
name,
const void *private_data)
748 errmsg(
"reopen injection point called, is enabled: %d",
753 elog(
ERROR,
"injection point triggering failure to reopen ");
761#ifdef USE_INJECTION_POINTS
767 elog(
ERROR,
"injection points not supported");
777#ifdef USE_INJECTION_POINTS
780 elog(
ERROR,
"injection points not supported");
789#ifdef USE_INJECTION_POINTS
792 elog(
ERROR,
"injection points not supported");
802#ifdef USE_INJECTION_POINTS
805 elog(
ERROR,
"injection points not supported");
PgAioHandle * pgaio_io_acquire(struct ResourceOwnerData *resowner, PgAioReturn *ret)
void pgaio_io_get_wref(PgAioHandle *ioh, PgAioWaitRef *iow)
void pgaio_io_set_flag(PgAioHandle *ioh, PgAioHandleFlags flag)
void pgaio_enter_batchmode(void)
void pgaio_wref_wait(PgAioWaitRef *iow)
void pgaio_io_release(PgAioHandle *ioh)
void pgaio_exit_batchmode(void)
@ PGAIO_HCB_LOCAL_BUFFER_READV
@ PGAIO_HCB_SHARED_BUFFER_READV
@ PGAIO_HF_REFERENCES_LOCAL
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)
static void pg_atomic_unlocked_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
#define BufferIsLocal(buffer)
static void UnlockBufHdr(BufferDesc *desc, uint32 buf_state)
static void ResourceOwnerForgetBufferIO(ResourceOwner owner, Buffer buffer)
#define BUF_STATE_GET_REFCOUNT(state)
static BufferDesc * GetLocalBufferDescriptor(uint32 id)
static BufferDesc * GetBufferDescriptor(uint32 id)
PrefetchBufferResult PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
BlockNumber ExtendBufferedRelBy(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, uint32 extend_by, Buffer *buffers, uint32 *extended_by)
char * DebugPrintBufferRefcount(Buffer buffer)
void ReleaseBuffer(Buffer buffer)
void TerminateBufferIO(BufferDesc *buf, bool clear_dirty, uint32 set_flag_bits, bool forget_owner, bool release_aio)
void LockBuffer(Buffer buffer, int mode)
bool EvictUnpinnedBuffer(Buffer buf, bool *buffer_flushed)
bool ReadRecentBuffer(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber blockNum, Buffer recent_buffer)
bool StartBufferIO(BufferDesc *buf, bool forInput, bool nowait)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
uint32 LockBufHdr(BufferDesc *desc)
void FlushOneBuffer(Buffer buffer)
#define BUFFER_LOCK_UNLOCK
#define READ_BUFFERS_ZERO_ON_ERROR
static Page BufferGetPage(Buffer buffer)
static Block BufferGetBlock(Buffer buffer)
#define READ_BUFFERS_IGNORE_CHECKSUM_FAILURES
static Size BufferGetPageSize(Buffer buffer)
#define BUFFER_LOCK_EXCLUSIVE
static bool BufferIsValid(Buffer bufnum)
bool ignore_checksum_failure
void PageSetChecksumInplace(Page page, BlockNumber blkno)
void PageInit(Page page, Size pageSize, Size specialSize)
static bool PageIsEmpty(const PageData *page)
PageHeaderData * PageHeader
uint16 pg_checksum_page(char *page, BlockNumber blkno)
int errmsg_internal(const char *fmt,...)
int errhidestmt(bool hide_stmt)
int errhidecontext(bool hide_ctx)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_GETARG_TEXT_PP(n)
#define PG_GETARG_UINT32(n)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_BOOL(x)
void InjectionPointLoad(const char *name)
void InjectionPointAttach(const char *name, const char *library, const char *function, const void *private_data, int private_data_size)
void(* shmem_startup_hook_type)(void)
shmem_startup_hook_type shmem_startup_hook
void RequestAddinShmemSpace(Size size)
void FlushLocalBuffer(BufferDesc *bufHdr, SMgrRelation reln)
bool StartLocalBufferIO(BufferDesc *bufHdr, bool forInput, bool nowait)
void TerminateLocalBufferIO(BufferDesc *bufHdr, bool clear_dirty, uint32 set_flag_bits, bool release_aio)
void InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced)
#define AccessExclusiveLock
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void * palloc_aligned(Size size, Size alignto, int flags)
void(* shmem_request_hook_type)(void)
shmem_request_hook_type shmem_request_hook
bool process_shared_preload_libraries_in_progress
void pgstat_prepare_report_checksum_failure(Oid dboid)
static SMgrRelation RelationGetSmgr(Relation rel)
#define RelationUsesLocalBuffers(relation)
ResourceOwner CurrentResourceOwner
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
void smgrstartreadv(PgAioHandle *ioh, SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
void smgrreleaseall(void)
static void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
bool short_read_result_set
PgAioTargetData target_data
RelFileLocator rd_locator
RelFileLocatorBackend smgr_rlocator
static void test_aio_shmem_request(void)
Datum batch_end(PG_FUNCTION_ARGS)
static Buffer create_toy_buffer(Relation rel, BlockNumber blkno)
Datum buffer_create_toy(PG_FUNCTION_ARGS)
Datum inj_io_reopen_detach(PG_FUNCTION_ARGS)
Datum buffer_call_terminate_io(PG_FUNCTION_ARGS)
static PgAioHandle * last_handle
Datum read_rel_block_ll(PG_FUNCTION_ARGS)
Datum invalidate_rel_block(PG_FUNCTION_ARGS)
Datum grow_rel(PG_FUNCTION_ARGS)
static void test_aio_shmem_startup(void)
Datum handle_get_release(PG_FUNCTION_ARGS)
Datum buffer_call_start_io(PG_FUNCTION_ARGS)
static shmem_startup_hook_type prev_shmem_startup_hook
static shmem_request_hook_type prev_shmem_request_hook
#define MAX_BUFFERS_TO_EXTEND_BY
Datum inj_io_reopen_attach(PG_FUNCTION_ARGS)
Datum inj_io_short_read_detach(PG_FUNCTION_ARGS)
Datum handle_get(PG_FUNCTION_ARGS)
Datum batch_start(PG_FUNCTION_ARGS)
Datum modify_rel_block(PG_FUNCTION_ARGS)
Datum handle_get_and_error(PG_FUNCTION_ARGS)
struct InjIoErrorState InjIoErrorState
Datum inj_io_short_read_attach(PG_FUNCTION_ARGS)
static InjIoErrorState * inj_io_error_state
PG_FUNCTION_INFO_V1(errno_from_string)
Datum handle_release_last(PG_FUNCTION_ARGS)
Datum handle_get_twice(PG_FUNCTION_ARGS)
Datum errno_from_string(PG_FUNCTION_ARGS)
struct PgAioOpData::@122 read
char * text_to_cstring(const text *t)