Skip to content

Commit

Permalink
(PE-39351) Update add_database plan to work with patching/HAC
Browse files Browse the repository at this point in the history
This commit updates the add_database plan to include the pe-patching and
pe-hac databases when it cleans up the original postgres on the primary.

The add_database plan uses pg_basebackup to copy the entire contents of
the postgres DB from the original primary DB to the new DB node's
postgres. That process doesn't individually update a list of databases,
so there's no context of "which DBs to move", because it just moves
everything. However, during the cleanup process on the original DB That
exists on the primary, the plan _does_ need to list the individual
internal postgres dbs that need to be deleted.
  • Loading branch information
mcdonaldseanp committed Dec 11, 2024
1 parent 66567dc commit d5ab3a4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
40 changes: 40 additions & 0 deletions functions/pe_db_names.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function peadm::pe_db_names (
String $pe_ver,
) >> Array {
case $pe_ver {
# The patching service was added in 2025.0.0
SemVerRange('>= 2025.0.0'): {

Check warning on line 6 in functions/pe_db_names.pp

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

unquoted string in case (check: unquoted_string_in_case)

Check warning on line 6 in functions/pe_db_names.pp

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

unquoted string in case (check: unquoted_string_in_case)
[
'pe-activity',
'pe-classifier',
'pe-inventory',
'pe-orchestrator',
'pe-rbac',
'pe-hac',
'pe-patching',
]
}

# The host-action-collector (hac) was added in 2023.8
SemVerRange('>= 2023.8.0'): {

Check warning on line 19 in functions/pe_db_names.pp

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

unquoted string in case (check: unquoted_string_in_case)

Check warning on line 19 in functions/pe_db_names.pp

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

unquoted string in case (check: unquoted_string_in_case)
[
'pe-activity',
'pe-classifier',
'pe-inventory',
'pe-orchestrator',
'pe-rbac',
'pe-hac',
]
}

default: {
[
'pe-activity',
'pe-classifier',
'pe-inventory',
'pe-orchestrator',
'pe-rbac',
]
}
}
}
15 changes: 5 additions & 10 deletions plans/add_database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Get current peadm config before making modifications and shutting down
# PuppetDB
$peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value
$pe_ver = $peadm_config['pe_version']

$compilers = $peadm_config['params']['compilers']

Expand All @@ -41,7 +42,7 @@
$operating_mode = $mode
out::message("Operating mode overridden by parameter mode set to ${mode}")
} else {
# If array is empty then no external databases were previously configured
# If array is empty then no external databases were previously configured
$no_external_db = peadm::flatten_compact([
$postgresql_a_host,
$postgresql_b_host,
Expand Down Expand Up @@ -87,7 +88,7 @@

peadm::plan_step('init-db-node') || {
# Install PSQL on new node to be used as external PuppetDB backend by using
# puppet in lieu of installer
# puppet in lieu of installer
run_plan('peadm::subplans::component_install', $postgresql_target,
primary_host => $primary_target,
avail_group_letter => $avail_group_letter,
Expand Down Expand Up @@ -162,16 +163,10 @@
if $operating_mode == 'init' {
# Clean up old puppetdb database on primary and those which were copied to
# new host.
$target_db_purge = [
'pe-activity',
'pe-classifier',
'pe-inventory',
'pe-orchestrator',
'pe-rbac',
]
$target_db_purge = peadm::pe_db_names($pe_ver)

# If a primary replica exists then pglogical is enabled and will prevent
# the clean up of databases on our target because it opens a connection.
# the clean up of databases on our target because it opens a connection.
if $replica_host {
run_plan('peadm::util::db_disable_pglogical', $postgresql_target, databases => $target_db_purge)
}
Expand Down

0 comments on commit d5ab3a4

Please sign in to comment.