Skip to content

Commit

Permalink
(PE-36120) Do not kill connections when no migrations are pending
Browse files Browse the repository at this point in the history
Previous behavior would cause compilers to be disconnected from
postgresql ever time the primary's pe-puppetdb was restarted. This was because the
restart invokes the migration code path, which, in PE with a
migrator-account set leads to connection blocking even when the
migration itself is ultimately a noop.

Now it tests whether any migrations are pending before calling
call-with-connections-blocked-during-migration. This change also means
that update-schema will return nil in this case, and initialize-schema
will return false, which is a change from previous noop migrations where
initialize-schema would have returned true.
  • Loading branch information
jpartlow committed Jun 28, 2023
1 parent 6f278fa commit 7ef9852
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/puppetlabs/puppetdb/scf/migrate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2617,16 +2617,17 @@
tables))]
(if-not write-user
(migrate)
(call-with-connections-blocked-during-migration
db-name
(distinct [read-user write-user])
(fn []
;; So new tables, etc. are owned by the write-user
(jdbc/do-commands (str "set role " (jdbc/double-quote write-user)))
(try!
(migrate)
(finally
(jdbc/do-commands (str "set role " (jdbc/double-quote orig-user))))))))))
(when-not (empty? (pending-migrations))
(call-with-connections-blocked-during-migration
db-name
(distinct [read-user write-user])
(fn []
;; So new tables, etc. are owned by the write-user
(jdbc/do-commands (str "set role " (jdbc/double-quote write-user)))
(try!
(migrate)
(finally
(jdbc/do-commands (str "set role " (jdbc/double-quote orig-user)))))))))))

(defn initialize-schema
"Ensures the database is migrated to the latest version, and returns
Expand Down

0 comments on commit 7ef9852

Please sign in to comment.