Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
-- test_cfs--1.0.sql - test module for Compressed File Store (CFS)
 
CREATE FUNCTION cfs_run_tests(
    OUT test_name text,
    OUT result text,
    OUT detail text)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'cfs_run_tests'
LANGUAGE C STRICT;
 
CREATE FUNCTION test_cfs_roundtrip(algorithm text, payload bytea, level int)
RETURNS boolean
AS 'MODULE_PATHNAME', 'test_cfs_roundtrip'
LANGUAGE C STRICT;
 
CREATE FUNCTION test_cfs_corrupt_crc(algorithm text)
RETURNS text
AS 'MODULE_PATHNAME', 'test_cfs_corrupt_crc'
LANGUAGE C STRICT;
 
CREATE FUNCTION test_cfs_codec_available(algorithm text)
RETURNS boolean
AS 'MODULE_PATHNAME', 'test_cfs_codec_available'
LANGUAGE C STRICT;
 
-- On-disk format, path and fsck test runners.
CREATE FUNCTION cfs_run_format_tests(
    OUT test_name text,
    OUT result text,
    OUT detail text)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'cfs_run_format_tests'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_run_path_tests(
    OUT test_name text,
    OUT result text,
    OUT detail text)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'cfs_run_path_tests'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_run_fsck_tests(
    OUT test_name text,
    OUT result text,
    OUT detail text)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'cfs_run_fsck_tests'
LANGUAGE C STRICT;
 
-- Autonomous storage layer tests (create/open, write/read, journal
-- replay, checkpoint, crash injection, CfsStorageOps dispatch, compaction).
CREATE FUNCTION cfs_run_storage_tests(
    OUT test_name text,
    OUT result text,
    OUT detail text)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'cfs_run_storage_tests'
LANGUAGE C STRICT;
 
-- Shared-memory map cache, statistics, eviction and cached I/O.
CREATE FUNCTION cfs_run_shmem_tests(
    OUT test_name text,
    OUT result text,
    OUT detail text)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'cfs_run_shmem_tests'
LANGUAGE C STRICT;
 
-- Assert-only shared-map tests (driven by t/002_cfs_shmem_hooks.pl).
CREATE FUNCTION cfs_run_shmem_hook_tests(
    OUT test_name text,
    OUT result text,
    OUT detail text)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'cfs_run_shmem_hook_tests'
LANGUAGE C STRICT;
 
-- .cfp segmentation (1 GiB segment rollover) and streaming fsck on
-- files larger than MaxAllocSize, plus journal generation monotonicity.
CREATE FUNCTION cfs_run_segment_tests(
    OUT test_name text,
    OUT result text,
    OUT detail text)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'cfs_run_segment_tests'
LANGUAGE C STRICT;
 
-- Inspect the resolved CFS policy of a relation (reloptions + GUC
-- fallback + TOAST / index inheritance).
CREATE FUNCTION cfs_relation_policy(regclass,
    OUT is_cfs boolean,
    OUT algorithm text,
    OUT level integer,
    OUT min_gain_bytes integer)
AS 'MODULE_PATHNAME', 'cfs_relation_policy'
LANGUAGE C STRICT;
 
-- Report whether the sidecar files (.cfp/.cfsmap/.cfsjrn) exist on
-- disk for a relation's main fork.  Used to verify that the smgr layer
-- creates and removes sidecars together with the relation lifecycle.
CREATE FUNCTION cfs_relation_has_sidecars(regclass)
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_relation_has_sidecars'
LANGUAGE C STRICT;
 
-- Read the last record of the relation's .cfp file: its algorithm and
-- sizes (the record header carries no compression level - decompression
-- does not need it).  Used to pin the runtime level resolve to the
-- actual bytes: identical pages written under different effective
-- levels must yield records of different compressed_size.
CREATE FUNCTION cfs_relation_last_record(regclass,
    OUT algorithm text,
    OUT original_size bigint,
    OUT compressed_size bigint,
    OUT records bigint)
AS 'MODULE_PATHNAME', 'cfs_relation_last_record'
LANGUAGE C STRICT;
 
-- Queue a deferred CFS policy publication for the relation (as if an ALTER
-- had changed the level), and inspect the deferred/effective shared state.
CREATE FUNCTION cfs_test_defer_publish(regclass, int)
RETURNS void
AS 'MODULE_PATHNAME', 'cfs_test_defer_publish'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_test_publish_pending(regclass)
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_test_publish_pending'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_test_shared_level(regclass)
RETURNS integer
AS 'MODULE_PATHNAME', 'cfs_test_shared_level'
LANGUAGE C STRICT;
 
-- Same two probes addressed by relfilenode (in the current database,
-- default tablespace): the relation itself may have been rewritten to a
-- new storage node, and the check must target the old one.
CREATE FUNCTION cfs_test_publish_pending_at(oid)
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_test_publish_pending_at'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_test_shared_level_at(oid)
RETURNS integer
AS 'MODULE_PATHNAME', 'cfs_test_shared_level_at'
LANGUAGE C STRICT;
 
-- Dump the .cfsjrn header summary together with the map row generation
-- watermark computed from the .cfsmap entries.
CREATE FUNCTION cfs_test_journal_header(oid)
RETURNS table(incarnation integer, max_generation integer,
              map_max_generation bigint)
AS 'MODULE_PATHNAME', 'cfs_test_journal_header'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_test_publish_false_at(oid)
RETURNS void
AS 'MODULE_PATHNAME', 'cfs_test_publish_false_at'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_test_sidecars_at(oid)
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_test_sidecars_at'
LANGUAGE C STRICT;
 
-- True when the shared policy cache holds a slot for the relfilenode,
-- whatever the slot says — distinguishes "no slot" from "a slot lying
-- is_cfs=false".
CREATE FUNCTION cfs_test_slot_present_at(oid)
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_test_slot_present_at'
LANGUAGE C STRICT;
 
-- Read block 0 through the smgr bridge after dropping the metadata slot and
-- report the published nblocks value (NULL when nothing was published).
CREATE FUNCTION cfs_test_smgr_read_meta(regclass)
RETURNS bigint
AS 'MODULE_PATHNAME', 'cfs_test_smgr_read_meta'
LANGUAGE C STRICT;
 
-- Measure the size through the smgr bridge with a cold metadata slot and
-- report how many throwaway full-map handles it opened.
CREATE FUNCTION cfs_test_smgr_size_full_opens(regclass)
RETURNS bigint
AS 'MODULE_PATHNAME', 'cfs_test_smgr_size_full_opens'
LANGUAGE C STRICT;
 
-- Run a real immediate checkpoint and report how many throwaway full-map
-- handles the CFS checkpoint path opened for THIS relation (0 expected:
-- the fold works off the sidecar files and never assembles the in-memory
-- map; the per-relation count keeps unrelated background opens out of
-- the measurement).
CREATE FUNCTION cfs_test_checkpoint_full_opens(regclass)
RETURNS bigint
AS 'MODULE_PATHNAME', 'cfs_test_checkpoint_full_opens'
LANGUAGE C STRICT;
 
-- Run smgrimmedsync() on the relation's main fork: the SQL-reachable way
-- to open a CFS full map handle lock-free on demand (immedsync path).
CREATE FUNCTION cfs_test_immedsync(regclass)
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_test_immedsync'
LANGUAGE C STRICT;
 
-- The pin-owner registry must exist for every cfs_map_memory value (0
-- included), or pins of dead processes could never be reaped.
CREATE FUNCTION cfs_test_map_pin_registry()
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_test_map_pin_registry'
LANGUAGE C STRICT;
 
-- Run smgrtruncate() on the relation's main fork through the backend's
-- cached SMgrRelation (and its cached CFS handle): the SQL-reachable way
-- to truncate with a handle that predates a sidecar swap.
CREATE FUNCTION cfs_test_smgr_truncate(regclass, int)
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_test_smgr_truncate'
LANGUAGE C STRICT;
 
-- The D1 two-backend write-path exercise: write one page of a synthetic
-- CFS relation through the real locked append path (pinned metadata slot,
-- append lock, handle refresh, cfs_write_page_cached) and return the
-- record's .cfp offset; verify reads every block back and proves the
-- offsets are strictly increasing (no backend overwrote a peer's record);
-- cleanup drops the synthetic sidecars and cache entries.
CREATE FUNCTION cfs_test_tail_write(bigint, int)
RETURNS bigint
AS 'MODULE_PATHNAME', 'cfs_test_tail_write'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_test_tail_verify(bigint, int)
RETURNS bigint
AS 'MODULE_PATHNAME', 'cfs_test_tail_verify'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_test_tail_cleanup(bigint)
RETURNS boolean
AS 'MODULE_PATHNAME', 'cfs_test_tail_cleanup'
LANGUAGE C STRICT;
 
-- QDB-1513 batched read path: advisory contiguous-run lengths and a
-- byte-for-byte comparison of cfs_read_pages_batch() against the per-block
-- cfs_read_page_cached() on a real relation (full private-map handle).
CREATE FUNCTION cfs_test_read_batch(regclass)
RETURNS TABLE(run0 integer, run_max integer, pages_checked bigint,
              batch_ok boolean)
AS 'MODULE_PATHNAME', 'cfs_test_read_batch'
LANGUAGE C STRICT;
 
-- QDB-1513 span failure semantics: corrupt one payload byte of a record
-- inside a contiguous run, demand CFS_STORAGE_CORRUPT with the exact
-- failing block from a batched range read, restore and demand a clean
-- re-read.
CREATE FUNCTION cfs_test_read_batch_corrupt(regclass, integer)
RETURNS text
AS 'MODULE_PATHNAME', 'cfs_test_read_batch_corrupt'
LANGUAGE C STRICT;
 
CREATE FUNCTION cfs_test_lz4_record(regclass, integer,
    OUT records bigint, OUT record_offset bigint, OUT record_end bigint,
    OUT page bytea, OUT payload bytea, OUT matches_fast boolean,
    OUT matches_hc boolean)
RETURNS record
AS 'MODULE_PATHNAME', 'cfs_test_lz4_record'
LANGUAGE C STRICT;