-
Notifications
You must be signed in to change notification settings - Fork 17
Stop all background workers for the duration of the upgrade #290
Conversation
This will address some of the potential slowness seen in #274 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The background workers should also be stopped at the beginning of promscale--0.0.0.sql
.
migration/bootstrap/002-stop-bgw.sql
Outdated
|
||
-- TimescaleDB itself does the same thing: | ||
-- https://github.com/timescale/timescaledb/blob/72d03e6f7d30cc4794c9263445f14199241e2eb5/sql/updates/pre-update.sql#L34 | ||
SELECT _timescaledb_internal.restart_background_workers(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work without timescaledb. I know that we're planning on not supporting installations without timescaledb, but that will also require improving our test infra at least a little. I would suggest the following:
+-- stop all background workers in the current db so they don't interfere
+-- with the upgrade (by e.g. holding locks).
+--
+-- Note: this stops the scheduler (and thus all jobs)
+-- and waits for the current txn (the one doing the upgrade) to finish
+-- before starting it up again. Thus, no jobs will be running during
+-- the upgrade.
+
+-- TimescaleDB itself does the same thing:
+-- https://github.com/timescale/timescaledb/blob/72d03e6f7d30cc4794c9263445f14199241e2eb5/sql/updates/pre-update.sql#L34
+DO
+$stop_bgw$
+DECLARE
+ _is_timescaledb_installed boolean = false;
+BEGIN
+ SELECT count(*) > 0
+ INTO STRICT _is_timescaledb_installed
+ FROM pg_extension
+ WHERE extname='timescaledb';
+
+ IF _is_timescaledb_installed THEN
+ SELECT _timescaledb_internal.restart_background_workers();
+ END IF;
+END;
+$stop_bgw$;
Implementation of #291 |
Sorry for a stupid question, but I failed to get the answer by just glancing through the code of |
It looks like it can be blocking, if the message queue to the background worker process is full. The comment on /*
* Write element to queue, wait/error if queue is full
* consumes message and deallocates
*/
extern bool
ts_bgw_message_send_and_wait(BgwMessageType message_type, Oid db_oid) @cevian On another note, I tested this change out in my test environment, by adding the "stop bgw" snippet to the |
I also added a commit to make CI pass. Feel free to squash it down. |
@cevian are you waiting on anything to merge this? |
This commit stops bgws while upgrading the Promscale extension. This prevents lock contention between jobs and upgrades and thus seems safer.
This commit stops bgws while upgrading the Promscale extension.
This prevents lock contention between jobs and upgrades and thus
seems safer.