Use "concurrent delete" in serialization error for TM_Deleted cases

In ExecLockRows() and ri_LockPKTuple(), the TM_Deleted code path was
using the same "could not serialize access due to concurrent update"
message as the TM_Updated path.  Use "concurrent delete" instead, since
the tuple was deleted, not updated.  The ExecLockRows() instance was
likely a copy-paste error per Andres; the ri_LockPKTuple() instance
was carried over from the same pattern in commit 2da86c1ef9.

Update affected isolation test expected files accordingly and add
a new test to fk-concurrent-pk-upd.spec with concurrent delete of the
PK row.

The ExecLockRows() change is master-only for lack of user complaints
and to avoid breaking anything that might match on the error text.

Reported-by: Jian He <jian.universality@gmail.com>
Author: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Discussion: https://postgr.es/m/CACJufxEG1JTCq4A1gnNAu-bGAq9Xn=Xkf7kC3TRWFz6iuUOuRA@mail.gmail.com
master
Amit Langote 1 week ago
parent 8d829f5a02
commit 410013d2a5
  1. 2
      src/backend/executor/nodeLockRows.c
  2. 2
      src/backend/utils/adt/ri_triggers.c
  3. 20
      src/test/isolation/expected/fk-concurrent-pk-upd.out
  4. 4
      src/test/isolation/expected/fk-partitioned-2.out
  5. 4
      src/test/isolation/expected/fk-snapshot-2.out
  6. 4
      src/test/isolation/expected/fk-snapshot-3.out
  7. 3
      src/test/isolation/specs/fk-concurrent-pk-upd.spec

@ -234,7 +234,7 @@ lnext:
if (IsolationUsesXactSnapshot())
ereport(ERROR,
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
errmsg("could not serialize access due to concurrent update")));
errmsg("could not serialize access due to concurrent delete")));
/* tuple was deleted so don't return it */
goto lnext;

@ -3244,7 +3244,7 @@ ri_LockPKTuple(Relation pk_rel, TupleTableSlot *slot, Snapshot snap,
if (IsolationUsesXactSnapshot())
ereport(ERROR,
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
errmsg("could not serialize access due to concurrent update")));
errmsg("could not serialize access due to concurrent delete")));
return false;
case TM_Updated:

@ -84,6 +84,26 @@ child_key|parent_key
(0 rows)
starting permutation: s2b s2dkey s3b s3i s2c s3c s2s s3s
step s2b: BEGIN;
step s2dkey: DELETE FROM parent WHERE parent_key = 1;
step s3b: BEGIN ISOLATION LEVEL REPEATABLE READ;
step s3i: INSERT INTO child VALUES (2, 1); <waiting ...>
step s2c: COMMIT;
step s3i: <... completed>
ERROR: could not serialize access due to concurrent delete
step s3c: COMMIT;
step s2s: SELECT * FROM parent;
parent_key|aux
----------+---
(0 rows)
step s3s: SELECT * FROM child;
child_key|parent_key
---------+----------
(0 rows)
starting permutation: s2b s2uaux s3b s3i s2c s3c s2s s3s
step s2b: BEGIN;
step s2uaux: UPDATE parent SET aux = 'bar' WHERE parent_key = 1;

@ -22,7 +22,7 @@ step s2bs: begin isolation level serializable; select 1;
step s2i: insert into pfk values (1); <waiting ...>
step s1c: commit;
step s2i: <... completed>
ERROR: could not serialize access due to concurrent update
ERROR: could not serialize access due to concurrent delete
step s2c: commit;
starting permutation: s1b s2b s1d s2i s1c s2c
@ -47,7 +47,7 @@ step s1d: delete from ppk where a = 1;
step s2i: insert into pfk values (1); <waiting ...>
step s1c: commit;
step s2i: <... completed>
ERROR: could not serialize access due to concurrent update
ERROR: could not serialize access due to concurrent delete
step s2c: commit;
starting permutation: s1b s2b s2i s1d s2c s1c

@ -17,7 +17,7 @@ step s1del: DELETE FROM parent WHERE parent_id = 1;
step s2ins: INSERT INTO child VALUES (1, 1); <waiting ...>
step s1c: COMMIT;
step s2ins: <... completed>
ERROR: could not serialize access due to concurrent update
ERROR: could not serialize access due to concurrent delete
step s2c: COMMIT;
starting permutation: s1rc s2rc s2ins s1del s2c s1c
@ -57,5 +57,5 @@ step s1del: DELETE FROM parent WHERE parent_id = 1;
step s2ins: INSERT INTO child VALUES (1, 1); <waiting ...>
step s1c: COMMIT;
step s2ins: <... completed>
ERROR: could not serialize access due to concurrent update
ERROR: could not serialize access due to concurrent delete
step s2c: COMMIT;

@ -21,7 +21,7 @@ step s2ins:
<waiting ...>
step s1c: COMMIT;
step s2ins: <... completed>
ERROR: could not serialize access due to concurrent update
ERROR: could not serialize access due to concurrent delete
step s2c: COMMIT;
starting permutation: s1rc s2rc s2ins s1del s2c s1c
@ -69,7 +69,7 @@ step s2ins:
<waiting ...>
step s1c: COMMIT;
step s2ins: <... completed>
ERROR: could not serialize access due to concurrent update
ERROR: could not serialize access due to concurrent delete
step s2c: COMMIT;
starting permutation: s1rc s2rc s2ins s1upok s2c s1c

@ -31,6 +31,7 @@ step s2b { BEGIN; }
step s2ukey { UPDATE parent SET parent_key = 2 WHERE parent_key = 1; }
step s2uaux { UPDATE parent SET aux = 'bar' WHERE parent_key = 1; }
step s2ukey2 { UPDATE parent SET parent_key = 1 WHERE parent_key = 2; }
step s2dkey { DELETE FROM parent WHERE parent_key = 1; }
step s2c { COMMIT; }
step s2s { SELECT * FROM parent; }
@ -49,5 +50,7 @@ permutation s2b s2ukey s1b s1i s2ukey2 s2c s1c s2s s1s
# RR: key update -> serialization failure
permutation s2b s2ukey s3b s3i s2c s3c s2s s3s
# RR: key delete -> serialization failure
permutation s2b s2dkey s3b s3i s2c s3c s2s s3s
# RR: non-key update -> old version visible via transaction snapshot
permutation s2b s2uaux s3b s3i s2c s3c s2s s3s

Loading…
Cancel
Save