2019-08-01 17:50:00 +02:00
|
|
|
# Test deadlock resolution with parallel process groups.
|
|
|
|
|
|
|
|
# It's fairly hard to get parallel worker processes to block on locks,
|
|
|
|
# since generally they don't want any locks their leader didn't already
|
|
|
|
# take. We cheat like mad here by making a function that takes a lock,
|
|
|
|
# and is incorrectly marked parallel-safe so that it can execute in a worker.
|
|
|
|
|
|
|
|
# Note that we explicitly override any global settings of isolation level
|
2023-02-15 09:21:59 +01:00
|
|
|
# or debug_parallel_query, to ensure we're testing what we intend to.
|
2019-08-01 17:50:00 +02:00
|
|
|
|
|
|
|
# Otherwise, this is morally equivalent to deadlock-soft.spec:
|
|
|
|
# Four-process deadlock with two hard edges and two soft edges.
|
|
|
|
# d2 waits for e1 (soft edge), e1 waits for d1 (hard edge),
|
|
|
|
# d1 waits for e2 (soft edge), e2 waits for d2 (hard edge).
|
|
|
|
# The deadlock detector resolves the deadlock by reversing the d1-e2 edge,
|
|
|
|
# unblocking d1.
|
|
|
|
|
2019-08-18 00:15:38 +02:00
|
|
|
# However ... it's not actually that well-defined whether the deadlock
|
|
|
|
# detector will prefer to unblock d1 or d2. It depends on which backend
|
|
|
|
# is first to run DeadLockCheck after the deadlock condition is created:
|
|
|
|
# that backend will search outwards from its own wait condition, and will
|
|
|
|
# first find a loop involving the *other* lock. We encourage that to be
|
|
|
|
# one of the d2a1 parallel workers, which will therefore unblock d1a2
|
|
|
|
# workers, by setting a shorter deadlock_timeout in session d2. But on
|
|
|
|
# slow machines, one or more d1a2 workers may not yet have reached their
|
|
|
|
# lock waits, so that they're not unblocked by the first DeadLockCheck.
|
|
|
|
# The next DeadLockCheck may choose to unblock the d2a1 workers instead,
|
|
|
|
# which would allow d2a1 to complete before d1a2, causing the test to
|
|
|
|
# freeze up because isolationtester isn't expecting that completion order.
|
|
|
|
# (In effect, we have an undetectable deadlock because d2 is waiting for
|
|
|
|
# d1's completion, but on the client side.) To fix this, introduce an
|
|
|
|
# additional lock (advisory lock 3), which is initially taken by d1 and
|
|
|
|
# then d2a1 will wait for it after completing the main part of the test.
|
|
|
|
# In this way, the deadlock detector can see that d1 must be completed
|
|
|
|
# first, regardless of timing.
|
|
|
|
|
2019-08-01 17:50:00 +02:00
|
|
|
setup
|
|
|
|
{
|
|
|
|
create function lock_share(int,int) returns int language sql as
|
|
|
|
'select pg_advisory_xact_lock_shared($1); select 1;' parallel safe;
|
|
|
|
|
|
|
|
create function lock_excl(int,int) returns int language sql as
|
|
|
|
'select pg_advisory_xact_lock($1); select 1;' parallel safe;
|
|
|
|
|
|
|
|
create table bigt as select x from generate_series(1, 10000) x;
|
|
|
|
analyze bigt;
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown
|
|
|
|
{
|
|
|
|
drop function lock_share(int,int);
|
|
|
|
drop function lock_excl(int,int);
|
|
|
|
drop table bigt;
|
|
|
|
}
|
|
|
|
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
session d1
|
2019-08-01 17:50:00 +02:00
|
|
|
setup { BEGIN isolation level repeatable read;
|
2023-02-15 09:21:59 +01:00
|
|
|
SET debug_parallel_query = off;
|
2019-08-01 17:50:00 +02:00
|
|
|
SET deadlock_timeout = '10s';
|
|
|
|
}
|
2019-08-18 00:15:38 +02:00
|
|
|
# these locks will be taken in the leader, so they will persist:
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
step d1a1 { SELECT lock_share(1,x), lock_excl(3,x) FROM bigt LIMIT 1; }
|
2019-08-01 17:50:00 +02:00
|
|
|
# this causes all the parallel workers to take locks:
|
2023-02-15 09:21:59 +01:00
|
|
|
step d1a2 { SET debug_parallel_query = on;
|
2019-08-01 17:50:00 +02:00
|
|
|
SET parallel_setup_cost = 0;
|
|
|
|
SET parallel_tuple_cost = 0;
|
|
|
|
SET min_parallel_table_scan_size = 0;
|
|
|
|
SET parallel_leader_participation = off;
|
2019-08-18 00:15:38 +02:00
|
|
|
SET max_parallel_workers_per_gather = 3;
|
2019-08-01 17:50:00 +02:00
|
|
|
SELECT sum(lock_share(2,x)) FROM bigt; }
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
step d1c { COMMIT; }
|
2019-08-01 17:50:00 +02:00
|
|
|
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
session d2
|
2019-08-01 17:50:00 +02:00
|
|
|
setup { BEGIN isolation level repeatable read;
|
2023-02-15 09:21:59 +01:00
|
|
|
SET debug_parallel_query = off;
|
2019-08-01 17:50:00 +02:00
|
|
|
SET deadlock_timeout = '10ms';
|
|
|
|
}
|
|
|
|
# this lock will be taken in the leader, so it will persist:
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
step d2a2 { select lock_share(2,x) FROM bigt LIMIT 1; }
|
2019-08-18 00:15:38 +02:00
|
|
|
# this causes all the parallel workers to take locks;
|
|
|
|
# after which, make the leader take lock 3 to prevent client-driven deadlock
|
2023-02-15 09:21:59 +01:00
|
|
|
step d2a1 { SET debug_parallel_query = on;
|
2019-08-01 17:50:00 +02:00
|
|
|
SET parallel_setup_cost = 0;
|
|
|
|
SET parallel_tuple_cost = 0;
|
|
|
|
SET min_parallel_table_scan_size = 0;
|
|
|
|
SET parallel_leader_participation = off;
|
2019-08-18 00:15:38 +02:00
|
|
|
SET max_parallel_workers_per_gather = 3;
|
|
|
|
SELECT sum(lock_share(1,x)) FROM bigt;
|
2023-02-15 09:21:59 +01:00
|
|
|
SET debug_parallel_query = off;
|
2019-08-18 00:15:38 +02:00
|
|
|
RESET parallel_setup_cost;
|
|
|
|
RESET parallel_tuple_cost;
|
|
|
|
SELECT lock_share(3,x) FROM bigt LIMIT 1; }
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
step d2c { COMMIT; }
|
2019-08-01 17:50:00 +02:00
|
|
|
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
session e1
|
2019-08-01 17:50:00 +02:00
|
|
|
setup { BEGIN isolation level repeatable read;
|
2023-02-15 09:21:59 +01:00
|
|
|
SET debug_parallel_query = on;
|
2019-08-01 17:50:00 +02:00
|
|
|
SET deadlock_timeout = '10s';
|
|
|
|
}
|
|
|
|
# this lock will be taken in a parallel worker, but we don't need it to persist
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
step e1l { SELECT lock_excl(1,x) FROM bigt LIMIT 1; }
|
|
|
|
step e1c { COMMIT; }
|
2019-08-01 17:50:00 +02:00
|
|
|
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
session e2
|
2019-08-01 17:50:00 +02:00
|
|
|
setup { BEGIN isolation level repeatable read;
|
2023-02-15 09:21:59 +01:00
|
|
|
SET debug_parallel_query = on;
|
2019-08-01 17:50:00 +02:00
|
|
|
SET deadlock_timeout = '10s';
|
|
|
|
}
|
|
|
|
# this lock will be taken in a parallel worker, but we don't need it to persist
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
step e2l { SELECT lock_excl(2,x) FROM bigt LIMIT 1; }
|
|
|
|
step e2c { COMMIT; }
|
2019-08-01 17:50:00 +02:00
|
|
|
|
Allow non-quoted identifiers as isolation test session/step names.
For no obvious reason, isolationtester has always insisted that
session and step names be written with double quotes. This is
fairly tedious and does little for test readability, especially
since the names that people actually choose almost always look
like normal identifiers. Hence, let's tweak the lexer to allow
SQL-like identifiers not only double-quoted strings.
(They're SQL-like, not exactly SQL, because I didn't add any
case-folding logic. Also there's no provision for U&"..." names,
not that anyone's likely to care.)
There is one incompatibility introduced by this change: if you write
"foo""bar" with no space, that used to be taken as two identifiers,
but now it's just one identifier with an embedded quote mark.
I converted all the src/test/isolation/ specfiles to remove
unnecessary double quotes, but stopped there because my
eyes were glazing over already.
Like 741d7f104, back-patch to all supported branches, so that this
isn't a stumbling block for back-patching isolation test changes.
Discussion: https://postgr.es/m/759113.1623861959@sss.pgh.pa.us
2021-06-24 00:41:39 +02:00
|
|
|
permutation d1a1 d2a2 e1l e2l d1a2 d2a1 d1c e1c d2c e2c
|