@@ -5,7 +5,11 @@ sidebar_label: Code Structure
55
66# OrioleDB Source Code Structure
77
8- The OrioleDB source code structure comprises various components including workflows for CI/CD, documentation, tests, and C-source files, structured to facilitate development, testing (including under Valgrind), and deployment of the OrioleDB extension for PostgreSQL, with a focus on concurrency testing and performance analysis through stop events and CI workflows.
8+ The OrioleDB source code structure comprises various components, including
9+ workflows for CI/CD, documentation, tests, and C-source files. It is structured
10+ to facilitate development, testing (including under Valgrind), and deployment of
11+ the OrioleDB extension for PostgreSQL. A heavy focus is placed on concurrency
12+ testing and performance analysis through stop events and CI workflows.
913
1014## File structure
1115
@@ -54,52 +58,89 @@ orioledb
5458
5559## Makefile targets
5660
57- All test-related targets accept ` VALGRIND=1 ` argument, which makes the tests to
58- be run under [ valgrind] ( https://valgrind.org/ ) . Valgrind makes tests about ~ 100
59- times slower but catches uninitialized memory access. Another positive
60- side-effect of Valgrind's super slow test runs is completely different timings,
61- which can spot various types of errors.
61+ All test-related targets accept the ` VALGRIND=1 ` argument, which runs the tests
62+ under [ valgrind] ( https://valgrind.org/ ) . Valgrind makes tests about ~ 100 times
63+ slower but catches uninitialized memory access. Another positive side-effect of
64+ Valgrind's super- slow test runs is the altered timing, which can expose various
65+ types of concurrency errors.
6266
6367- ` regresscheck ` -- run SQL-tests (see below).
6468- ` isolationcheck ` -- run isolation tests (see below).
6569- ` testgrescheck ` -- run testgres tests (see below).
6670- ` testgrescheck_part_1 ` -- first half of testgres checks. Testgres tests are
67- splitted in a two nearly equal halfs to avoid too long individual CI runs.
71+ split into two nearly equal halves to avoid overly long individual CI runs.
6872- ` testgrescheck_part_2 ` -- second half of testgres checks.
69- - ` installcheck ` -- run all types of tests when installed using PostgreSQL
73+ - ` installcheck ` -- run all types of tests when installed using the PostgreSQL
7074 extension system (` USE_PGXS=1 ` ).
71- - ` check ` -- run all types of tests when installed from ` contrib ` folder of
72- PostgreSQL source code.
73- - ` pgindent ` -- automatically indents OrioleDB sources.
75+ - ` check ` -- run all types of tests when installed from the ` contrib ` folder of
76+ the PostgreSQL source code.
77+ - ` pgindent ` -- automatically indents OrioleDB sources. The
7478 [ pgindent] ( https://github.com/postgres/postgres/blob/master/src/tools/pgindent/pgindent )
75- tool should be available in ` $PATH ` . Note, that you need to install
79+ tool should be available in ` $PATH ` . Note that you need to install
7680 [ pg_bsd_indent] ( https://github.com/postgres/postgres/blob/master/src/tools/pg_bsd_indent/README#L17 )
7781 first. Also, you need GNU Objdump available in ` $PATH ` as ` objdump ` or
78- ` gobjdump ` , or be specified in ` OBJDUMP ` environment variable.
82+ ` gobjdump ` , or specified via the ` OBJDUMP ` environment variable.
83+
84+ ## Extension SQL scripts
85+
86+ OrioleDB extension files are organized using a base version installation script,
87+ followed by upgrade scripts for respective minor versions. For instance, when
88+ installing version ` 1.7 ` , PostgreSQL first applies the ` 1.0 ` script and then
89+ sequentially runs all upgrade scripts from ` 1.0 ` up to ` 1.7 ` .
90+
91+ To bump the extension version (for example, bumping from ` 1.6 ` to ` 1.7 ` ), follow
92+ these steps:
93+
94+ 1 . Edit the ` default_version ` parameter in the ` orioledb.control ` file to match
95+ the new version.
96+ 2 . Manually create development and production upgrade scripts in the ` sql `
97+ directory:
98+ - ` ./sql/orioledb--1.6--1.7_prod.sql `
99+ - ` ./sql/orioledb--1.6--1.7_dev.sql `
100+ 3 . Add the corresponding headers to the scripts and populate the changes:
101+ - Changes intended ** only** for the development environment (such as test
102+ functions that should not be exposed on production systems) go into
103+ ` _dev.sql ` .
104+ - All standard changes go into the ` _prod.sql ` file.
105+
106+ :::note
107+ The build system (` make ` ) utilizes both files to automatically generate the
108+ final ` ./sql/orioledb--1.6--1.7.sql ` script. Therefore, you do not need to
109+ create this final file manually. The contents of ` _dev.sql ` will only be
110+ included when the ` IS_DEV ` flag is specified during the build. There is no need
111+ to duplicate changes between the two files.
112+ :::
113+ 4 . Add the generated file (` ./sql/orioledb--1.6--1.7.sql ` ) to both ` .gitignore `
114+ and ` .dockerignore ` .
79115
80116## Tests
81117
82118OrioleDB has 3 groups of tests described below.
83119
84- - SQL tests are located in the ` sql ` folder. This is the most simple type of
85- test. The sql-file gets passed to ` psql ` and the result is compared to
86- the reference output in the ` expected ` folder. Note that there might be
87- multiple reference outputs for one input file. For instance, ` collate.sql `
88- contains collation-aware tests. The result may match to ` collate.out ` ,
89- ` collate_1.out ` , or ` collate_2.out ` depending on database encoding and the
90- presence of libicu.
120+ - SQL tests are located in the ` test/sql ` folder. These are the simplest types of
121+ tests. The SQL file is passed to ` psql ` and the result is compared to the
122+ reference output in the ` test/expected ` folder. Note that there might be multiple
123+ reference outputs for one input file. For instance, ` collate.sql ` contains
124+ collation-aware tests. The result may match ` collate.out ` , ` collate_1.out ` , or
125+ ` collate_2.out ` depending on database encoding and the presence of libicu.
91126
92127- Isolation tests are located in the ` specs ` folder. These tests simulate
93- multiple connections running simultaneously. See
128+ multiple connections running simultaneously. See the
94129 [ README] ( https://github.com/postgres/postgres/blob/master/src/test/isolation/README )
95130 in the PostgreSQL source tree. These tests are especially powerful in
96131 conjunction with stop events.
97132
98- - Python [ testgres] ( https://pypi.org/project/testgres/ ) tests located in ` t ` .
99- These are the most powerful and complex tests. Additionally to the ability
100- to simulate multiple simultaneous connections, they can perform actions with
101- the whole PostgreSQL instance such as start, stop, backup, replication, etc.
102- See the [ testgres docs] ( https://postgrespro.github.io/testgres/ ) for details.
133+ - Python [ testgres] ( https://pypi.org/project/testgres/ ) tests are located in
134+ ` t ` . These are the most powerful and complex tests. Additionally to the
135+ ability to simulate multiple simultaneous connections, they can perform
136+ actions with the whole PostgreSQL instance such as start, stop, backup,
137+ replication, etc. See the [ testgres
138+ docs] ( https://postgrespro.github.io/testgres/ ) for details.
139+
140+ :::note
141+ For proper integration into the test suite, the test file names should
142+ end with ` _test.py ` .
143+ :::
103144
104145## CI
105146
@@ -111,92 +152,89 @@ This workflow runs the following tests for each of the two compilers (gcc and
111152clang) and each of the supported PostgreSQL major versions (16 and 17).
112153
113154- ` normal ` -- run tests without asserts and without debug symbols.
114- - ` debug ` -- run test with asserts and with debug symbols.
115- - ` sanitize ` -- run test with asserts, with debug symbols, with alignment
116- and other sanitizers. This replaces running tests on strict alignment
117- architectures providing even somewhat stricter checks
118- (for instance, it traps you on accessing a properly-aligned
119- member of an unproperly aligned structure, which real hardware
120- wouldn't do).
121- - ` check_page ` -- runs tests with asserts, with debug symbols, and with
122- ` CHECK_PAGE_STRUCT ` macro enabled. This macro provides
123- the page structure check on every page unlock.
124- - ` valgrind_1 ` -- runs ` regresscheck ` , ` isolationcheck ` and
125- ` testgrescheck_part_1 ` under valgrind with asserts and
126- with debug symbols.
155+ - ` debug ` -- run tests with asserts and with debug symbols.
156+ - ` sanitize ` -- run tests with asserts, with debug symbols, with alignment, and
157+ other sanitizers. This replaces running tests on strict alignment
158+ architectures, providing even somewhat stricter checks (for instance, it traps
159+ you on accessing a properly-aligned member of an improperly aligned structure,
160+ which real hardware wouldn't do).
161+ - ` check_page ` -- runs tests with asserts, with debug symbols, and with the
162+ ` CHECK_PAGE_STRUCT ` macro enabled. This macro provides the page structure
163+ check on every page unlock.
164+ - ` valgrind_1 ` -- runs ` regresscheck ` , ` isolationcheck ` , and
165+ ` testgrescheck_part_1 ` under valgrind with asserts and with debug symbols.
127166- ` valgrind_2 ` -- runs ` testgrescheck_part_2 ` under Valgrind with asserts and
128167 with debug symbols.
129168- ` static ` -- runs ` clang-analyzer ` or ` cppcheck ` over sources.
130169
131170### ` docker.yml `
132171
133172This workflow builds docker images for amd64 and arm64v8 architectures under
134- Alpine and Ubuntu Linux. This Dockerfile is slightly adjusted
135- [ PostgreSQL Dockerfile] ( https://github.com/docker-library/postgres ) .
136- See [ our dockerhub] ( https://hub.docker.com/r/orioledb/orioledb ) for details.
173+ Alpine and Ubuntu Linux. This Dockerfile is a slightly adjusted [ PostgreSQL
174+ Dockerfile] ( https://github.com/docker-library/postgres ) . See [ our
175+ dockerhub] ( https://hub.docker.com/r/orioledb/orioledb ) for details.
137176
138177### ` dockertest.yml `
139178
140179This workflow tests the Docker images. It runs on every push and pull request.
141180
142181### ` pgindent.yml `
143182
144- This workflow checks the code formatting using ` pgindent ` . It runs on every push and pull request.
183+ This workflow checks the code formatting using ` pgindent ` . It runs on every push
184+ and pull request.
145185
146186### ` rpm.yml `
147187
148- This workflow build RPM packages for CentOS 7 using specification from the
149- [ orioledb/pgrpms] ( https://github.com/orioledb/pgrpms ) repository, a fork
150- of [ pgrpms] ( https://git.postgresql.org/gitweb/?p=pgrpms.git;a=summary )
151- repository.
188+ This workflow builds RPM packages for CentOS 7 using the specification from the
189+ [ orioledb/pgrpms] ( https://github.com/orioledb/pgrpms ) repository, a fork of the
190+ [ pgrpms] ( https://git.postgresql.org/gitweb/?p=pgrpms.git;a=summary ) repository.
152191
153192### ` static.yml `
154193
155- This workflow runs static analysis on the code. It runs on every push and pull request.
194+ This workflow runs static analysis on the code. It runs on every push and pull
195+ request.
156196
157197## Stop events
158198
159- Stop events are special places in the code, where the execution could be stopped
160- on some condition . Stop events are used for the reliable reproduction of
199+ Stop events are special places in the code where execution can be paused based
200+ on specific conditions . Stop events are used for the reliable reproduction of
161201concurrency issues. OrioleDB isolation and testgres tests use stop events.
162202
163- Stop event exposes a set of parameters, encapsulated into jsonb value. The
164- condition over stop event parameters is defined using jsonpath
203+ A stop event exposes a set of parameters, encapsulated into a jsonb value. The
204+ conditions on stop event parameters are defined using the SQL/JSON path
165205language.
166206
167207The SQL-level functions and variables for stop events manipulation are listed
168208below.
169209
170210- ` orioledb.enable_stopevents ` -- enables stop events checking for the process.
171- Stop events checking is expensive and significantly affects the performance.
172- This is why stop events are disabled by default.
211+ Stop events checking is expensive and significantly affects performance. This
212+ is why stop events are disabled by default.
173213
174- - ` orioledb.trace_stopevents ` -- enables logging of all the stop events.
175- Disabled by default.
214+ - ` orioledb.trace_stopevents ` -- enables logging of all stop events. Disabled by
215+ default.
176216
177- - ` pg_stopevent_set(eventname text, condition jsonpath) RETURNS void ` --
178- set the condition for the stop event. Once the function is executed, all
179- the processes, which run a given stop event with parameters satisfying
180- the given jsonpath condition, will be stopped.
217+ - ` pg_stopevent_set(eventname text, condition jsonpath) RETURNS void ` -- set the
218+ condition for the stop event. Once the function is executed, all processes
219+ that run a given stop event with parameters satisfying the given jsonpath
220+ condition will be stopped.
181221
182- - ` pg_stopevent_reset(eventname text) RETURNS bool ` --
183- reset the stop event. All the processes previously stopped on the given
184- stop event will continue the execution.
222+ - ` pg_stopevent_reset(eventname text) RETURNS bool ` -- reset the stop event. All
223+ processes previously stopped on the given stop event will continue execution.
185224
186225- ` pg_stopevents(OUT stopevent text, OUT condition jsonpath, OUT waiter_pids int[]) RETURNS SETOF record ` --
187226 returns all the stop events currently set with their conditions and
188- waiter process pids .
227+ waiter process PIDs .
189228
190- At C- level, the following macros are there for managing stop events.
229+ At the C level, the following macros are provided for managing stop events.
191230
192231- ` STOPEVENTS_ENABLED() ` -- checks if stop events are enabled.
193- - ` STOPEVENT(event_id, params) ` -- raises given stop event with given jsonb
194- parameters.
195- - ` STOPEVENT_CONDITION(event_id, params) ` -- check stop event condition without
196- stopping the execution. Used for
197- error simulation.
232+ - ` STOPEVENT(event_id, params) ` -- raises the given stop event with the given
233+ jsonb parameters.
234+ - ` STOPEVENT_CONDITION(event_id, params) ` -- checks the stop event condition
235+ without stopping the execution. Used for error simulation.
198236
199237The list of stop events is defined in ` stopevents.txt ` file. The
200- ` stopevent_gen .py` script generates ` include/utils/stopevents_defs.h ` (macros)
201- and ` include/utils/stopevents_data.h ` (name strings) files with C- definitions
202- of the stop events list.
238+ ` stopevents_gen .py` script generates ` include/utils/stopevents_defs.h ` (macros)
239+ and ` include/utils/stopevents_data.h ` (name strings) files with C definitions of
240+ the stop events list.
0 commit comments