Skip to content

Commit 006b69f

Browse files
committed
Add test module for SLRUs
This commit introduces a basic facility to test SLRUs, in terms of initialization, page reads, writes, flushes, truncation and deletions, using SQL wrappers around the APIs of slru.c. This should be easily extensible at will, and it can be used as a starting point for someone willing to implement an external module that makes use of SLRUs (LWLock tranche registering and SLRU initialization particularly). As this requires a loaded library, the tests use a custom configuration file and are disabled under installcheck. Author: Aleksander Alekseev, Michael Paquier Reviewed-by: Pavel Borisov, Daniel Gustafsson, Noah Misch, Maxim Orlov Discussion: https://postgr.es/m/CAJ7c6TOFoWcHOW4BVe3BG_uikCrO9B91ayx9d6rh5JZr_tPESg@mail.gmail.com
1 parent 1eda3ce commit 006b69f

File tree

11 files changed

+524
-0
lines changed

11 files changed

+524
-0
lines changed

src/test/modules/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SUBDIRS = \
3131
test_regex \
3232
test_rls_hooks \
3333
test_shm_mq \
34+
test_slru \
3435
unsafe_tests \
3536
worker_spi
3637

src/test/modules/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ subdir('test_rbtree')
2525
subdir('test_regex')
2626
subdir('test_rls_hooks')
2727
subdir('test_shm_mq')
28+
subdir('test_slru')
2829
subdir('unsafe_tests')
2930
subdir('worker_spi')

src/test/modules/test_slru/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Generated subdirectories
2+
/log/
3+
/results/
4+
/tmp_check/

src/test/modules/test_slru/Makefile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# src/test/modules/test_slru/Makefile
2+
3+
MODULE_big = test_slru
4+
OBJS = \
5+
$(WIN32RES) \
6+
test_slru.o
7+
PGFILEDESC = "test_slru - test module for SLRUs"
8+
9+
EXTENSION = test_slru
10+
DATA = test_slru--1.0.sql
11+
12+
REGRESS_OPTS = --temp-config $(top_srcdir)/src/test/modules/test_slru/test_slru.conf
13+
REGRESS = test_slru
14+
# Disabled because these tests require "shared_preload_libraries=test_slru",
15+
# which typical installcheck users do not have (e.g. buildfarm clients).
16+
NO_INSTALLCHECK = 1
17+
18+
ifdef USE_PGXS
19+
PG_CONFIG = pg_config
20+
PGXS := $(shell $(PG_CONFIG) --pgxs)
21+
include $(PGXS)
22+
else
23+
subdir = src/test/modules/test_slru
24+
top_builddir = ../../../..
25+
include $(top_builddir)/src/Makefile.global
26+
include $(top_srcdir)/contrib/contrib-global.mk
27+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
CREATE EXTENSION test_slru;
2+
SELECT test_slru_page_exists(12345);
3+
test_slru_page_exists
4+
-----------------------
5+
f
6+
(1 row)
7+
8+
SELECT test_slru_page_write(12345, 'Test SLRU');
9+
test_slru_page_write
10+
----------------------
11+
12+
(1 row)
13+
14+
SELECT test_slru_page_read(12345);
15+
test_slru_page_read
16+
---------------------
17+
Test SLRU
18+
(1 row)
19+
20+
SELECT test_slru_page_exists(12345);
21+
test_slru_page_exists
22+
-----------------------
23+
t
24+
(1 row)
25+
26+
-- 48 extra pages
27+
SELECT count(test_slru_page_write(a, 'Test SLRU'))
28+
FROM generate_series(12346, 12393, 1) as a;
29+
count
30+
-------
31+
48
32+
(1 row)
33+
34+
-- Reading page in buffer for read and write
35+
SELECT test_slru_page_read(12377, true);
36+
test_slru_page_read
37+
---------------------
38+
Test SLRU
39+
(1 row)
40+
41+
-- Reading page in buffer for read-only
42+
SELECT test_slru_page_readonly(12377);
43+
test_slru_page_readonly
44+
-------------------------
45+
Test SLRU
46+
(1 row)
47+
48+
-- Reading page not in buffer with read-only
49+
SELECT test_slru_page_readonly(12346);
50+
test_slru_page_readonly
51+
-------------------------
52+
Test SLRU
53+
(1 row)
54+
55+
-- Write all the pages in buffers
56+
SELECT test_slru_page_writeall();
57+
test_slru_page_writeall
58+
-------------------------
59+
60+
(1 row)
61+
62+
-- Flush the last page written out.
63+
SELECT test_slru_page_sync(12393);
64+
NOTICE: Called SlruSyncFileTag() for segment 387 on path pg_test_slru/0183
65+
test_slru_page_sync
66+
---------------------
67+
68+
(1 row)
69+
70+
SELECT test_slru_page_exists(12393);
71+
test_slru_page_exists
72+
-----------------------
73+
t
74+
(1 row)
75+
76+
-- Segment deletion
77+
SELECT test_slru_page_delete(12393);
78+
NOTICE: Called SlruDeleteSegment() for segment 387
79+
test_slru_page_delete
80+
-----------------------
81+
82+
(1 row)
83+
84+
SELECT test_slru_page_exists(12393);
85+
test_slru_page_exists
86+
-----------------------
87+
f
88+
(1 row)
89+
90+
-- Page truncation
91+
SELECT test_slru_page_exists(12377);
92+
test_slru_page_exists
93+
-----------------------
94+
t
95+
(1 row)
96+
97+
SELECT test_slru_page_truncate(12377);
98+
test_slru_page_truncate
99+
-------------------------
100+
101+
(1 row)
102+
103+
SELECT test_slru_page_exists(12377);
104+
test_slru_page_exists
105+
-----------------------
106+
t
107+
(1 row)
108+
109+
-- Full deletion
110+
SELECT test_slru_delete_all();
111+
NOTICE: Calling test_slru_scan_cb()
112+
test_slru_delete_all
113+
----------------------
114+
115+
(1 row)
116+
117+
SELECT test_slru_page_exists(12345);
118+
test_slru_page_exists
119+
-----------------------
120+
f
121+
(1 row)
122+
123+
SELECT test_slru_page_exists(12377);
124+
test_slru_page_exists
125+
-----------------------
126+
f
127+
(1 row)
128+
129+
SELECT test_slru_page_exists(12393);
130+
test_slru_page_exists
131+
-----------------------
132+
f
133+
(1 row)
134+
135+
DROP EXTENSION test_slru;
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# FIXME: prevent install during main install, but not during test :/
2+
3+
test_slru_sources = files(
4+
'test_slru.c',
5+
)
6+
7+
if host_system == 'windows'
8+
test_slru_sources += rc_lib_gen.process(win32ver_rc, extra_args: [
9+
'--NAME', 'test_slru',
10+
'--FILEDESC', 'test_slru - test module for SLRUs',])
11+
endif
12+
13+
test_slru = shared_module('test_slru',
14+
test_slru_sources,
15+
kwargs: pg_mod_args,
16+
)
17+
testprep_targets += test_slru
18+
19+
install_data(
20+
'test_slru.control',
21+
'test_slru--1.0.sql',
22+
kwargs: contrib_data_args,
23+
)
24+
25+
tests += {
26+
'name': 'test_slru',
27+
'sd': meson.current_source_dir(),
28+
'bd': meson.current_build_dir(),
29+
'regress': {
30+
'sql': [
31+
'test_slru',
32+
],
33+
'regress_args': ['--temp-config', files('test_slru.conf')],
34+
},
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CREATE EXTENSION test_slru;
2+
3+
SELECT test_slru_page_exists(12345);
4+
SELECT test_slru_page_write(12345, 'Test SLRU');
5+
SELECT test_slru_page_read(12345);
6+
SELECT test_slru_page_exists(12345);
7+
8+
-- 48 extra pages
9+
SELECT count(test_slru_page_write(a, 'Test SLRU'))
10+
FROM generate_series(12346, 12393, 1) as a;
11+
12+
-- Reading page in buffer for read and write
13+
SELECT test_slru_page_read(12377, true);
14+
-- Reading page in buffer for read-only
15+
SELECT test_slru_page_readonly(12377);
16+
-- Reading page not in buffer with read-only
17+
SELECT test_slru_page_readonly(12346);
18+
19+
-- Write all the pages in buffers
20+
SELECT test_slru_page_writeall();
21+
-- Flush the last page written out.
22+
SELECT test_slru_page_sync(12393);
23+
SELECT test_slru_page_exists(12393);
24+
-- Segment deletion
25+
SELECT test_slru_page_delete(12393);
26+
SELECT test_slru_page_exists(12393);
27+
-- Page truncation
28+
SELECT test_slru_page_exists(12377);
29+
SELECT test_slru_page_truncate(12377);
30+
SELECT test_slru_page_exists(12377);
31+
32+
-- Full deletion
33+
SELECT test_slru_delete_all();
34+
SELECT test_slru_page_exists(12345);
35+
SELECT test_slru_page_exists(12377);
36+
SELECT test_slru_page_exists(12393);
37+
38+
DROP EXTENSION test_slru;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
2+
\echo Use "CREATE EXTENSION test_slru" to load this file. \quit
3+
4+
CREATE OR REPLACE FUNCTION test_slru_page_write(int, text) RETURNS VOID
5+
AS 'MODULE_PATHNAME', 'test_slru_page_write' LANGUAGE C;
6+
CREATE OR REPLACE FUNCTION test_slru_page_writeall() RETURNS VOID
7+
AS 'MODULE_PATHNAME', 'test_slru_page_writeall' LANGUAGE C;
8+
CREATE OR REPLACE FUNCTION test_slru_page_sync(int) RETURNS VOID
9+
AS 'MODULE_PATHNAME', 'test_slru_page_sync' LANGUAGE C;
10+
CREATE OR REPLACE FUNCTION test_slru_page_read(int, bool DEFAULT true) RETURNS text
11+
AS 'MODULE_PATHNAME', 'test_slru_page_read' LANGUAGE C;
12+
CREATE OR REPLACE FUNCTION test_slru_page_readonly(int) RETURNS text
13+
AS 'MODULE_PATHNAME', 'test_slru_page_readonly' LANGUAGE C;
14+
CREATE OR REPLACE FUNCTION test_slru_page_exists(int) RETURNS bool
15+
AS 'MODULE_PATHNAME', 'test_slru_page_exists' LANGUAGE C;
16+
CREATE OR REPLACE FUNCTION test_slru_page_delete(int) RETURNS VOID
17+
AS 'MODULE_PATHNAME', 'test_slru_page_delete' LANGUAGE C;
18+
CREATE OR REPLACE FUNCTION test_slru_page_truncate(int) RETURNS VOID
19+
AS 'MODULE_PATHNAME', 'test_slru_page_truncate' LANGUAGE C;
20+
CREATE OR REPLACE FUNCTION test_slru_delete_all() RETURNS VOID
21+
AS 'MODULE_PATHNAME', 'test_slru_delete_all' LANGUAGE C;

0 commit comments

Comments
 (0)