Исходный код СУБД 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
# Tests for concurrently dropping a relation while a publication's tables are
# being listed.
 
setup
{
    CREATE SCHEMA pubdrop;
    CREATE PUBLICATION pub_schema FOR TABLES IN SCHEMA pubdrop;
    CREATE TABLE pubdrop.dropme (id int);
    CREATE TABLE pubdrop.keepme (id int);
}
 
teardown
{
    DROP SCHEMA pubdrop CASCADE;
    DROP PUBLICATION pub_schema;
}
 
session s1
step lock   { BEGIN; LOCK pubdrop.dropme IN ACCESS EXCLUSIVE MODE; }
step drop_and_commit    { DROP TABLE pubdrop.dropme; COMMIT; }
 
session s2
step list_pub_tables
{
    SELECT relid::regclass AS tablename
    FROM pg_get_publication_tables('pub_schema')
    ORDER BY tablename;
}
 
# Hold an ACCESS EXCLUSIVE lock on the table in one session, so that the query
# listing a publication's tables in another session blocks when it tries to
# open the locked table. Then drop the table in the same lock-holding session
# and commit, releasing the lock, so the query in another session resumes and
# skips the now-dropped table instead of erroring with "could not open relation
# with OID".
permutation lock list_pub_tables drop_and_commit