mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
Events_Lock holds advisory locks over events, so that two filters do not work on the same event at the same time. Claiming an event is a single autocommitted INSERT of one row, which means no InnoDB lock is held while the filter actually works on the event. No foreign key to Events on purpose: it would make every event delete take a lock in this table, which is the coupling this exists to avoid. Rows left behind for deleted events are harmless and expire. ZM_FILTER_LOCK_TIMEOUT (default 3600) is how long a claim lasts. A filter that is killed part way through an event cannot release anything, so claims have to expire on their own. It needs to be longer than the slowest thing a filter does to a single event, which is why it is configurable rather than fixed. Adds migration db/zm_update-1.39.21.sql.
28 lines
1.1 KiB
SQL
28 lines
1.1 KiB
SQL
--
|
|
-- Events_Lock: advisory locks over events for filters with LockRows set.
|
|
--
|
|
-- Replaces the SELECT ... FOR UPDATE [SKIP LOCKED] that LockRows filters used
|
|
-- to run over their whole result set. That held every row lock the batch took -
|
|
-- Events, Events_Hour/Day/Week/Month, Event_Summaries, Storage - until the
|
|
-- batch committed, which deadlocked two filters against each other and blocked
|
|
-- zmc from opening new events on any monitor the filter had touched.
|
|
--
|
|
-- Claiming an event is now a single autocommitted INSERT of one row in here, so
|
|
-- no lock is held while the filter works on the event.
|
|
--
|
|
-- No foreign key to Events on purpose: it would make every event delete take a
|
|
-- lock in this table, which is the coupling being removed. Rows left behind for
|
|
-- deleted events are harmless and expire.
|
|
--
|
|
-- Idempotent, so re-running is a no-op.
|
|
--
|
|
|
|
CREATE TABLE IF NOT EXISTS `Events_Lock` (
|
|
`EventId` BIGINT unsigned NOT NULL,
|
|
`LockedBy` varchar(64) NOT NULL,
|
|
`LockedAt` datetime NOT NULL,
|
|
`ExpiresAt` datetime NOT NULL,
|
|
PRIMARY KEY (`EventId`),
|
|
KEY `Events_Lock_ExpiresAt_idx` (`ExpiresAt`)
|
|
) ENGINE=InnoDB;
|