Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1b71f1

Browse files
committed
Fix race conditions when an event trigger is added concurrently with DDL.
EventTriggerTableRewrite crashed if there were table_rewrite triggerspresent, but there had not been when the calling command started.EventTriggerDDLCommandEnd called ddl_command_end triggers if present,even if there had been no such triggers when the calling command started,which would lead to a failure in pg_event_trigger_ddl_commands.In both cases, fix by doing nothing; it's better to wait till the nextcommand when things will be properly initialized.In passing, remove an elog(DEBUG1) call that might have seemed interestingfour years ago but surely isn't today.We found this because of intermittent failures in the buildfarm. Thanksto Alvaro Herrera and Andrew Gierth for analysis.Back-patch to 9.5; some of this code exists before that, but the specifichazards we need to guard against don't.Discussion:https://postgr.es/m/5767.1523995174@sss.pgh.pa.us
1 parentec38dcd commitb1b71f1

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

‎src/backend/commands/event_trigger.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,19 @@ EventTriggerDDLCommandEnd(Node *parsetree)
836836
if (!IsUnderPostmaster)
837837
return;
838838

839+
/*
840+
* Also do nothing if our state isn't set up, which it won't be if there
841+
* weren't any relevant event triggers at the start of the current DDL
842+
* command. This test might therefore seem optional, but it's important
843+
* because EventTriggerCommonSetup might find triggers that didn't exist
844+
* at the time the command started. Although this function itself
845+
* wouldn't crash, the event trigger functions would presumably call
846+
* pg_event_trigger_ddl_commands which would fail. Better to do nothing
847+
* until the next command.
848+
*/
849+
if (!currentEventTriggerState)
850+
return;
851+
839852
runlist=EventTriggerCommonSetup(parsetree,
840853
EVT_DDLCommandEnd,"ddl_command_end",
841854
&trigdata);
@@ -887,9 +900,10 @@ EventTriggerSQLDrop(Node *parsetree)
887900
&trigdata);
888901

889902
/*
890-
* Nothing to do if run list is empty. Note thisshouldn't happen,
903+
* Nothing to do if run list is empty. Note thistypically can't happen,
891904
* because if there are no sql_drop events, then objects-to-drop wouldn't
892905
* have been collected in the first place and we would have quit above.
906+
* But it could occur if event triggers were dropped partway through.
893907
*/
894908
if (runlist==NIL)
895909
return;
@@ -936,8 +950,6 @@ EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
936950
List*runlist;
937951
EventTriggerDatatrigdata;
938952

939-
elog(DEBUG1,"EventTriggerTableRewrite(%u)",tableOid);
940-
941953
/*
942954
* Event Triggers are completely disabled in standalone mode. There are
943955
* (at least) two reasons for this:
@@ -957,6 +969,16 @@ EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
957969
if (!IsUnderPostmaster)
958970
return;
959971

972+
/*
973+
* Also do nothing if our state isn't set up, which it won't be if there
974+
* weren't any relevant event triggers at the start of the current DDL
975+
* command. This test might therefore seem optional, but it's
976+
* *necessary*, because EventTriggerCommonSetup might find triggers that
977+
* didn't exist at the time the command started.
978+
*/
979+
if (!currentEventTriggerState)
980+
return;
981+
960982
runlist=EventTriggerCommonSetup(parsetree,
961983
EVT_TableRewrite,
962984
"table_rewrite",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp