When two messages for the same originator and alarm type arrived
simultaneously at the create-alarm rule node, both could pass the
"no existing active alarm" check inside create_or_update_active_alarm
and proceed to INSERT, because SELECT ... FOR UPDATE does not lock a
row that does not yet exist and the partial index on (originator_id,
type) WHERE cleared = false is not UNIQUE.
Serialize concurrent callers per (originator_id, type) with a
transaction-scoped advisory lock so the SELECT/INSERT pair inside the
function cannot interleave.
- Moved filtering logic for active edges from inline native query to a database view (edge_active_attribute_view)
to simplify the query and improve maintainability.