Skip to content

Commit 93bc3d7

Browse files
anarazelnbyavuz
andcommitted
aio: Add test_aio module
To make the tests possible, a few functions from bufmgr.c/localbuf.c had to be exported, via buf_internals.h. Reviewed-by: Noah Misch <noah@leadboat.com> Co-authored-by: Andres Freund <andres@anarazel.de> Co-authored-by: Nazir Bilal Yavuz <byavuz81@gmail.com> Discussion: https://postgr.es/m/uvrtrknj4kdytuboidbhwclo4gxhswwcpgadptsjvjqcluzmah%40brqs62irg4dt
1 parent 60f566b commit 93bc3d7

File tree

13 files changed

+2622
-8
lines changed

13 files changed

+2622
-8
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,6 @@ static uint32 WaitBufHdrUnlocked(BufferDesc *buf);
518518
static int SyncOneBuffer(int buf_id, bool skip_recently_used,
519519
WritebackContext *wb_context);
520520
static void WaitIO(BufferDesc *buf);
521-
static bool StartBufferIO(BufferDesc *buf, bool forInput, bool nowait);
522-
static void TerminateBufferIO(BufferDesc *buf, bool clear_dirty,
523-
uint32 set_flag_bits, bool forget_owner,
524-
bool release_aio);
525521
static void AbortBufferIO(Buffer buffer);
526522
static void shared_buffer_write_error_callback(void *arg);
527523
static void local_buffer_write_error_callback(void *arg);
@@ -5962,7 +5958,7 @@ WaitIO(BufferDesc *buf)
59625958
* find out if they can perform the I/O as part of a larger operation, without
59635959
* waiting for the answer or distinguishing the reasons why not.
59645960
*/
5965-
static bool
5961+
bool
59665962
StartBufferIO(BufferDesc *buf, bool forInput, bool nowait)
59675963
{
59685964
uint32 buf_state;
@@ -6019,7 +6015,7 @@ StartBufferIO(BufferDesc *buf, bool forInput, bool nowait)
60196015
* resource owner. (forget_owner=false is used when the resource owner itself
60206016
* is being released)
60216017
*/
6022-
static void
6018+
void
60236019
TerminateBufferIO(BufferDesc *buf, bool clear_dirty, uint32 set_flag_bits,
60246020
bool forget_owner, bool release_aio)
60256021
{

src/backend/storage/buffer/localbuf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ static int NLocalPinnedBuffers = 0;
5757
static void InitLocalBuffers(void);
5858
static Block GetLocalBufferStorage(void);
5959
static Buffer GetLocalVictimBuffer(void);
60-
static void InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced);
6160

6261

6362
/*
@@ -597,7 +596,7 @@ TerminateLocalBufferIO(BufferDesc *bufHdr, bool clear_dirty, uint32 set_flag_bit
597596
*
598597
* See also InvalidateBuffer().
599598
*/
600-
static void
599+
void
601600
InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced)
602601
{
603602
Buffer buffer = BufferDescriptorGetBuffer(bufHdr);

src/include/storage/buf_internals.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ extern void IssuePendingWritebacks(WritebackContext *wb_context, IOContext io_co
434434
extern void ScheduleBufferTagForWriteback(WritebackContext *wb_context,
435435
IOContext io_context, BufferTag *tag);
436436

437+
/* solely to make it easier to write tests */
438+
extern bool StartBufferIO(BufferDesc *buf, bool forInput, bool nowait);
439+
extern void TerminateBufferIO(BufferDesc *buf, bool clear_dirty, uint32 set_flag_bits,
440+
bool forget_owner, bool release_aio);
441+
442+
437443
/* freelist.c */
438444
extern IOContext IOContextForStrategy(BufferAccessStrategy strategy);
439445
extern BufferDesc *StrategyGetBuffer(BufferAccessStrategy strategy,
@@ -478,6 +484,7 @@ extern void TerminateLocalBufferIO(BufferDesc *bufHdr, bool clear_dirty,
478484
uint32 set_flag_bits, bool release_aio);
479485
extern bool StartLocalBufferIO(BufferDesc *bufHdr, bool forInput, bool nowait);
480486
extern void FlushLocalBuffer(BufferDesc *bufHdr, SMgrRelation reln);
487+
extern void InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced);
481488
extern void DropRelationLocalBuffers(RelFileLocator rlocator,
482489
ForkNumber forkNum,
483490
BlockNumber firstDelBlock);

src/test/modules/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SUBDIRS = \
1414
oauth_validator \
1515
plsample \
1616
spgist_name_ops \
17+
test_aio \
1718
test_bloomfilter \
1819
test_copy_callbacks \
1920
test_custom_rmgrs \

src/test/modules/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ subdir('oauth_validator')
1313
subdir('plsample')
1414
subdir('spgist_name_ops')
1515
subdir('ssl_passphrase_callback')
16+
subdir('test_aio')
1617
subdir('test_bloomfilter')
1718
subdir('test_copy_callbacks')
1819
subdir('test_custom_rmgrs')

src/test/modules/test_aio/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated subdirectories
2+
/tmp_check/

src/test/modules/test_aio/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# src/test/modules/test_aio/Makefile
2+
3+
PGFILEDESC = "test_aio - test code for AIO"
4+
5+
MODULE_big = test_aio
6+
OBJS = \
7+
$(WIN32RES) \
8+
test_aio.o
9+
10+
EXTENSION = test_aio
11+
DATA = test_aio--1.0.sql
12+
13+
TAP_TESTS = 1
14+
15+
export enable_injection_points
16+
17+
ifdef USE_PGXS
18+
PG_CONFIG = pg_config
19+
PGXS := $(shell $(PG_CONFIG) --pgxs)
20+
include $(PGXS)
21+
else
22+
subdir = src/test/modules/test_aio
23+
top_builddir = ../../../..
24+
include $(top_builddir)/src/Makefile.global
25+
include $(top_srcdir)/contrib/contrib-global.mk
26+
endif

src/test/modules/test_aio/meson.build

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2024-2025, PostgreSQL Global Development Group
2+
3+
test_aio_sources = files(
4+
'test_aio.c',
5+
)
6+
7+
if host_system == 'windows'
8+
test_aio_sources += rc_lib_gen.process(win32ver_rc, extra_args: [
9+
'--NAME', 'test_aio',
10+
'--FILEDESC', 'test_aio - test code for AIO',])
11+
endif
12+
13+
test_aio = shared_module('test_aio',
14+
test_aio_sources,
15+
kwargs: pg_test_mod_args,
16+
)
17+
test_install_libs += test_aio
18+
19+
test_install_data += files(
20+
'test_aio.control',
21+
'test_aio--1.0.sql',
22+
)
23+
24+
tests += {
25+
'name': 'test_aio',
26+
'sd': meson.current_source_dir(),
27+
'bd': meson.current_build_dir(),
28+
'tap': {
29+
'env': {
30+
'enable_injection_points': get_option('injection_points') ? 'yes' : 'no',
31+
},
32+
'tests': [
33+
't/001_aio.pl',
34+
't/002_io_workers.pl',
35+
],
36+
},
37+
}

0 commit comments

Comments
 (0)