Icinga / icinga-notifications

Icinga Notifications: new and improved notifications and incident management for Icinga (work in progress, not ready for production yet)
GNU General Public License v2.0
10 stars 0 forks source link

object.FromEvent(): avoid database queries while holding mutex #266

Open julianbrost opened 3 months ago

julianbrost commented 3 months ago

Currently, object.FromEvent() performs some database interaction while holding a mutex: https://github.com/Icinga/icinga-notifications/blob/8102c7797364a1f184526a19083220fa7d7a46c9/internal/object/object.go

This obviously prevents part of the event processing from happening in parallel. It would of course be nicer if that wasn't the case.

There are two parts to this:

  1. The mutex currently implicitly prevents two goroutines from interfering with each other when fetching/updating the same object. To address this, some kind of more sophisticated locking mechanism would be necessary, i.e. one that takes the object ID into account and only prevents concurrent calls for the same object, maybe something similar to ObjectNameLock from https://github.com/Icinga/icinga2/pull/10013.
  2. While adding MySQL/MariaDB support, we noticed that the database queries currently performed are susceptible to InnoDB locking issues, see https://github.com/Icinga/icinga-notifications/pull/203#pullrequestreview-2180268854 and following comments. Currently, this happens to be prevented by the current locking, but if we improve this, this has to be addressed.