Skip to content

Commit b358a1f

Browse files
committed
Ensure the DDL trigger requests are cached (#7426)
While this commit does not fix all problems with cached triggers, I see no good reason to defer it.
1 parent 4f5d80a commit b358a1f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/jrd/exe.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,35 +560,49 @@ void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTri
560560
{
561561
TrigVector triggers;
562562
TrigVector* triggersPtr = &triggers;
563+
HalfStaticArray<Trigger*, 4> cachedTriggers;
563564

564-
for (const auto& trigger : *attachment->att_ddl_triggers)
565+
for (auto& trigger : *attachment->att_ddl_triggers)
565566
{
566567
const auto type = trigger.type & ~TRIGGER_TYPE_MASK;
567568
const bool preTrigger = ((type & 1) == 0);
568569

569570
if ((type & (1LL << action)) && (preTriggers == preTrigger))
570571
{
571572
triggers.add() = trigger;
573+
cachedTriggers.add(&trigger);
572574
}
573575
}
574576

575577
if (triggers.hasData())
576578
{
579+
FbLocalStatus tempStatus;
580+
577581
jrd_tra* const oldTransaction = tdbb->getTransaction();
578582
tdbb->setTransaction(transaction);
579583

580584
try
581585
{
582586
EXE_execute_triggers(tdbb, &triggersPtr, NULL, NULL, TRIGGER_DDL,
583587
preTriggers ? StmtNode::PRE_TRIG : StmtNode::POST_TRIG);
584-
585-
tdbb->setTransaction(oldTransaction);
586588
}
587-
catch (const Exception&)
589+
catch (const Exception& ex)
588590
{
589-
tdbb->setTransaction(oldTransaction);
590-
throw;
591+
ex.stuffException(&tempStatus);
591592
}
593+
594+
tdbb->setTransaction(oldTransaction);
595+
596+
// Triggers could be compiled inside EXE_execute_triggers(),
597+
// so ensure the new pointers are copied back to the cache
598+
fb_assert(triggers.getCount() == cachedTriggers.getCount());
599+
for (unsigned i = 0; i < triggers.getCount(); i++)
600+
{
601+
*cachedTriggers[i] = triggers[i];
602+
triggers[i].extTrigger = nullptr; // avoid deletion inside d'tor
603+
}
604+
605+
tempStatus.check();
592606
}
593607
}
594608
}

0 commit comments

Comments
 (0)