Исходный код СУБД 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
setup
{
    CREATE EXTENSION injection_points;
 
    BEGIN;
    -- Generate a string of random characters that is not likely to be
    -- compressed, but is big enough to be stored externally.
    CREATE FUNCTION gen_external()
    RETURNS text
    LANGUAGE sql as $$
        SELECT string_agg(chr(65 + trunc(25 * random())::int), '')
        FROM generate_series(1, 2048) s(x);
    $$;
    COMMIT;
 
    SELECT pg_create_logical_replication_slot('s', 'test_decoding');
 
    CREATE TABLE repack_toast(i int PRIMARY KEY, t text);
    INSERT INTO repack_toast(i, t) VALUES (1, gen_external());
}
 
teardown
{
    DROP TABLE repack_toast;
    DROP EXTENSION injection_points;
    DROP FUNCTION gen_external();
    SELECT pg_drop_replication_slot('s');
}
 
session s1
setup
{
    SELECT injection_points_set_local();
    SELECT injection_points_attach('repack-concurrently-before-lock', 'wait');
}
# Perform the initial load and wait for s2 to do some data changes.
step s1_wait_before_lock
{
    REPACK (CONCURRENTLY) repack_toast;
}
step s1_decode
{
    SELECT count(*) FROM pg_logical_slot_peek_changes('s', NULL, NULL, 'include-rewrites', '1',
                              'skip-empty-xacts', '1', 'include-xids', '0');
}
# Show the decoded updates.  The row loaded by setup carries a random TOAST
# value, so only the updates are stable enough to display.
step s1_decode_updates
{
    SELECT data FROM pg_logical_slot_peek_changes('s', NULL, NULL, 'include-rewrites', '1',
                             'skip-empty-xacts', '1', 'include-xids', '0')
    WHERE data LIKE '%UPDATE%';
}
teardown
{
    SELECT injection_points_detach('repack-concurrently-before-lock');
}
 
session s2
step s2_changes
{
    UPDATE repack_toast SET t = gen_external() WHERE i=1;
}
# Change the row using a value small enough to stay in-line.
step s2_short_change
{
    UPDATE repack_toast SET t = 'short' WHERE i=1;
}
step s2_wakeup_before_lock
{
    SELECT injection_points_wakeup('repack-concurrently-before-lock');
}
 
permutation
    s1_wait_before_lock
    s2_changes
    s2_wakeup_before_lock
    s1_decode
 
# The changes REPACK applies to the transient heap must not be reported to an
# output plugin, not even as records that carry no tuple.  Unlike the
# permutation above, no TOAST value is involved here.
permutation
    s1_wait_before_lock
    s2_short_change
    s2_wakeup_before_lock
    s1_decode_updates