Skip to content

PostgreSQL notifications listener

Pavlo Strokov requested to merge ps-postgres-listener into master

Praefect strongly depends on the state of the PostgreSQL database. Usually we execute a query to get the latest information about the state. But it doesn't scale well in case query is heavy or there are too many round trips to the database. To address it the data could be cached locally in the memory, so we can reduce amount of trips to the database. The downside of this approach is that we should invalidate local cache when data in database changes.

To address this we decided to allow Praefect to have a direct connection to the PostgreSQL database and benefit from LISTEN/NOTIFY functionality of it. Implemented listener triggers passed in callback function with payload it receives from the database. The call is handled in separate goroutine taken from the predefined pool. In case there are too many notifications and no available goroutines in the pool to process - the new one will be started to process the notification. If listener lost connection to the database it tries to re-establish it until it reaches 3 fails in period of 1 min.

Part of: #3053 (closed)

Merge request reports