Skip to content

Commit 9873756

Browse files
committed
[PGPRO-7614] Fix error that caused by replacement of package state at end of autonomous transaction
Tags: pg_variables, atx
1 parent afdef54 commit 9873756

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

expected/pg_variables_atx_pkg.out

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,37 @@ BEGIN;
343343
FETCH 1 IN r1_cur;
344344
ERROR: unrecognized package "test"
345345
ROLLBACK;
346+
--
347+
--
348+
-- Test for case: pgv_set() created regular a variable; rollback
349+
-- removes package state and creates a new state to make package valid.
350+
-- Commit of next autonomous transaction should not replace this new
351+
-- state (this is not allowed for autonomous transaction).
352+
--
353+
BEGIN;
354+
BEGIN AUTONOMOUS;
355+
SELECT pgv_set('vars', 'int1', 1);
356+
pgv_set
357+
---------
358+
359+
(1 row)
360+
361+
ROLLBACK;
362+
BEGIN AUTONOMOUS;
363+
SELECT pgv_set('vars', 'int1', 2);
364+
pgv_set
365+
---------
366+
367+
(1 row)
368+
369+
COMMIT;
370+
ROLLBACK;
371+
SELECT pgv_remove('vars', 'int1');
372+
pgv_remove
373+
------------
374+
375+
(1 row)
376+
346377
SELECT pgv_free();
347378
pgv_free
348379
----------

expected/pg_variables_atx_pkg_1.out

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,41 @@ ERROR: current transaction is aborted, commands ignored until end of transactio
375375
ERROR: cursor "r1_cur" does not exist
376376
ROLLBACK;
377377
WARNING: there is no transaction in progress
378+
--
379+
--
380+
-- Test for case: pgv_set() created regular a variable; rollback
381+
-- removes package state and creates a new state to make package valid.
382+
-- Commit of next autonomous transaction should not replace this new
383+
-- state (this is not allowed for autonomous transaction).
384+
--
385+
BEGIN;
386+
BEGIN AUTONOMOUS;
387+
ERROR: syntax error at or near "AUTONOMOUS"
388+
LINE 1: BEGIN AUTONOMOUS;
389+
^
390+
SELECT pgv_set('vars', 'int1', 1);
391+
ERROR: current transaction is aborted, commands ignored until end of transaction block
392+
ROLLBACK;
393+
BEGIN AUTONOMOUS;
394+
ERROR: syntax error at or near "AUTONOMOUS"
395+
LINE 1: BEGIN AUTONOMOUS;
396+
^
397+
SELECT pgv_set('vars', 'int1', 2);
398+
pgv_set
399+
---------
400+
401+
(1 row)
402+
403+
COMMIT;
404+
WARNING: there is no transaction in progress
405+
ROLLBACK;
406+
WARNING: there is no transaction in progress
407+
SELECT pgv_remove('vars', 'int1');
408+
pgv_remove
409+
------------
410+
411+
(1 row)
412+
378413
SELECT pgv_free();
379414
pgv_free
380415
----------

pg_variables.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,14 @@ rollbackSavepoint(TransObject *object, TransObjectType type)
23542354
/* ...create a new state to make package valid. */
23552355
initObjectHistory(object, type);
23562356
#ifdef PGPRO_EE
2357-
GetActualState(object)->levels.atxlevel = getNestLevelATX();
2357+
/*
2358+
* Package inside autonomous transaction should not be detected
2359+
* as 'object has been changed in upper level' because in this
2360+
* case we will remove state in releaseSavepoint() but this
2361+
* state may be used pgvRestoreContext(). So atxlevel should
2362+
* be 0.
2363+
*/
2364+
GetActualState(object)->levels.atxlevel = 0;
23582365
#endif
23592366
GetActualState(object)->levels.level = GetCurrentTransactionNestLevel() - 1;
23602367
if (!dlist_is_empty(changesStack))

sql/pg_variables_atx_pkg.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,21 @@ BEGIN;
166166
-- ERROR: unrecognized package "test"
167167
FETCH 1 IN r1_cur;
168168
ROLLBACK;
169+
--
170+
--
171+
-- Test for case: pgv_set() created regular a variable; rollback
172+
-- removes package state and creates a new state to make package valid.
173+
-- Commit of next autonomous transaction should not replace this new
174+
-- state (this is not allowed for autonomous transaction).
175+
--
176+
BEGIN;
177+
BEGIN AUTONOMOUS;
178+
SELECT pgv_set('vars', 'int1', 1);
179+
ROLLBACK;
180+
BEGIN AUTONOMOUS;
181+
SELECT pgv_set('vars', 'int1', 2);
182+
COMMIT;
183+
ROLLBACK;
184+
SELECT pgv_remove('vars', 'int1');
169185

170186
SELECT pgv_free();

0 commit comments

Comments
 (0)