-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pg_repack as default maintenance strategy #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.rb eol=lf | ||
*.erb eol=lf | ||
*.pp eol=lf | ||
*.sh eol=lf | ||
*.epp eol=lf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--relative | ||
--no-2sp_soft_tabs-check | ||
--no-arrow_alignment-check |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,25 @@ | ||
class pe_databases::maintenance ( | ||
Boolean $disable_maintenace = false, | ||
Optional[Integer] $maint_cron_weekday = undef, #DEPRECATED | ||
Optional[Integer] $maint_cron_hour = undef, #DEPRECATED | ||
Optional[Integer] $maint_cron_minute = undef, #DEPRECATED | ||
Boolean $disable_maintenance = false, | ||
String $logging_directory = '/var/log/puppetlabs/pe_databases_cron', | ||
String $script_directory = $pe_databases::scripts_dir, | ||
){ | ||
|
||
$ensure_cron = $disable_maintenace ? { | ||
true => absent, | ||
default => present | ||
#If the PE Version includes pg_repack (2018.1.7 and 2019.0.2) then use pg_repack and remove the old script and cron jobs | ||
if ( versioncmp( '2018.1.7', $facts['pe_server_version']) <= 0 and versioncmp($facts['pe_server_version'], '2019.0.0') < 0 ) { | ||
include pe_databases::maintenance::pg_repack | ||
class { 'pe_databases::maintenance::vacuum_full': | ||
disable_maintenance => true, | ||
} | ||
} elsif ( versioncmp( '2019.0.2', $facts['pe_server_version']) <= 0 ) { | ||
include pe_databases::maintenance::pg_repack | ||
class { 'pe_databases::maintenance::vacuum_full': | ||
disable_maintenance => true, | ||
} | ||
} else { | ||
include pe_databases::maintenance::vacuum_full | ||
} | ||
|
||
file { $logging_directory : | ||
ensure => directory, | ||
} | ||
|
||
$vacuum_script_path = "${script_directory}/vacuum_full_tables.sh" | ||
|
||
file { $vacuum_script_path: | ||
ensure => file, | ||
source => 'puppet:///modules/pe_databases/vacuum_full_tables.sh', | ||
owner => 'pe-postgres', | ||
group => 'pe-postgres', | ||
mode => '0744', | ||
} | ||
|
||
cron { 'VACUUM FULL facts tables' : | ||
ensure => $ensure_cron, | ||
user => 'root', | ||
weekday => [2,6], | ||
hour => 4, | ||
minute => 30, | ||
command => "${vacuum_script_path} facts", | ||
require => File[$logging_directory, $script_directory], | ||
} | ||
|
||
cron { 'VACUUM FULL catalogs tables' : | ||
ensure => $ensure_cron, | ||
user => 'root', | ||
weekday => [0,4], | ||
hour => 4, | ||
minute => 30, | ||
command => "${vacuum_script_path} catalogs", | ||
require => File[$logging_directory, $script_directory], | ||
} | ||
|
||
cron { 'VACUUM FULL other tables' : | ||
ensure => $ensure_cron, | ||
user => 'root', | ||
monthday => 20, | ||
hour => 5, | ||
minute => 30, | ||
command => "${vacuum_script_path} other", | ||
require => File[$logging_directory, $script_directory], | ||
} | ||
|
||
#Remove old versions of maintenance cron jobs | ||
cron { 'Maintain PE databases' : | ||
ensure => absent, | ||
user => 'root', | ||
weekday => $maint_cron_weekday, | ||
hour => $maint_cron_hour, | ||
minute => $maint_cron_minute, | ||
command => "su - pe-postgres -s /bin/bash -c '/opt/puppetlabs/server/bin/reindexdb --all; /opt/puppetlabs/server/bin/vacuumdb --analyze --verbose --all' > ${logging_directory}/output.log 2> ${logging_directory}/output_error.log", | ||
require => File[$logging_directory, $script_directory], | ||
} | ||
|
||
if empty($maint_cron_weekday) == false { | ||
warning('pe_databases::maintenance::maint_cron_weekday is deprecated and will be removed in a future release') | ||
} | ||
if empty($maint_cron_hour) == false { | ||
warning('pe_databases::maintenance::maint_cron_hour is deprecated and will be removed in a future release') | ||
} | ||
if empty($maint_cron_minute) == false { | ||
warning('pe_databases::maintenance::maint_cron_minute is deprecated and will be removed in a future release') | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# A description of what this class does | ||
# | ||
# @summary A short summary of the purpose of this class | ||
# | ||
# @example | ||
# include pe_databases::maintenance::pg_repack | ||
class pe_databases::maintenance::pg_repack ( | ||
Boolean $disable_maintenance = $pe_databases::maintenance::disable_maintenance, | ||
String $logging_directory = $pe_databases::maintenance::logging_directory, | ||
) { | ||
|
||
$ensure_cron = $disable_maintenance ? { | ||
true => absent, | ||
default => present | ||
} | ||
|
||
$repack = 'su - pe-postgres -s /bin/bash -c "/opt/puppetlabs/server/apps/postgresql/bin/pg_repack -d pe-puppetdb' | ||
$facts_tables = '-t factsets -t fact_paths"' | ||
$catalogs_tables = '-t catalogs -t catalog_resources -t edges -t certnames"' | ||
$other_tables = '-t producers -t resource_params -t resource_params_cache"' | ||
$reports_tables = '-t reports"' | ||
$logging = "> ${logging_directory}/output.log 2>&1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any logic to ensure that multiple repacks cannot be started simultaneously? That's the biggest danger of automated repacking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only ones that could overlap are the other tables and the reports table which run at 5:30 on 1 day of the month while facts and catalogs run at 4:30 2 days a week. I'm not particularly concerned about them overlapping... but if we thought it was a serious concern then we could move the times they run further apart. |
||
|
||
Cron { | ||
ensure => $ensure_cron, | ||
user => 'root', | ||
require => File[$logging_directory], | ||
} | ||
|
||
cron { 'pg_repack facts tables' : | ||
weekday => [2,6], | ||
hour => 4, | ||
minute => 30, | ||
command => "${repack} ${facts_tables} ${logging}", | ||
} | ||
|
||
cron { 'pg_repack catalogs tables' : | ||
weekday => [0,4], | ||
hour => 4, | ||
minute => 30, | ||
command => "${repack} ${catalogs_tables} ${logging}", | ||
} | ||
|
||
cron { 'pg_repack other tables' : | ||
monthday => 20, | ||
hour => 5, | ||
minute => 30, | ||
command => "${repack} ${other_tables} ${logging}", | ||
} | ||
|
||
cron { 'pg_repack reports tables' : | ||
ensure => $ensure_cron, | ||
user => 'root', | ||
monthday => 10, | ||
hour => 5, | ||
minute => 30, | ||
command => "${repack} ${reports_tables} ${logging}", | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# A description of what this class does | ||
# | ||
# @summary A short summary of the purpose of this class | ||
# | ||
# @example | ||
# include pe_databases::maintenance::vacuum_full | ||
class pe_databases::maintenance::vacuum_full ( | ||
Boolean $disable_maintenance = $pe_databases::maintenance::disable_maintenance, | ||
String $logging_directory = $pe_databases::maintenance::logging_directory, | ||
String $script_directory = $pe_databases::maintenance::script_directory, | ||
){ | ||
|
||
$ensure_cron = $disable_maintenance ? { | ||
true => absent, | ||
default => present | ||
} | ||
|
||
$ensure_vacuum_script = $disable_maintenance ? { | ||
true => absent, | ||
default => file | ||
} | ||
|
||
$vacuum_script_path = "${script_directory}/vacuum_full_tables.sh" | ||
|
||
file { $vacuum_script_path: | ||
ensure => $ensure_vacuum_script, | ||
source => 'puppet:///modules/pe_databases/vacuum_full_tables.sh', | ||
owner => 'pe-postgres', | ||
group => 'pe-postgres', | ||
mode => '0744', | ||
} | ||
|
||
cron { 'VACUUM FULL facts tables' : | ||
ensure => $ensure_cron, | ||
user => 'root', | ||
weekday => [2,6], | ||
hour => 4, | ||
minute => 30, | ||
command => "${vacuum_script_path} facts", | ||
require => File[$logging_directory, $script_directory], | ||
} | ||
|
||
cron { 'VACUUM FULL catalogs tables' : | ||
ensure => $ensure_cron, | ||
user => 'root', | ||
weekday => [0,4], | ||
hour => 4, | ||
minute => 30, | ||
command => "${vacuum_script_path} catalogs", | ||
require => File[$logging_directory, $script_directory], | ||
} | ||
|
||
cron { 'VACUUM FULL other tables' : | ||
ensure => $ensure_cron, | ||
user => 'root', | ||
monthday => 20, | ||
hour => 5, | ||
minute => 30, | ||
command => "${vacuum_script_path} other", | ||
require => File[$logging_directory, $script_directory], | ||
} | ||
|
||
#Remove old versions of maintenance cron jobs | ||
cron { 'Maintain PE databases' : | ||
ensure => absent, | ||
user => 'root', | ||
command => "su - pe-postgres -s /bin/bash -c '/opt/puppetlabs/server/bin/reindexdb --all; /opt/puppetlabs/server/bin/vacuumdb --analyze --verbose --all' > ${logging_directory}/output.log 2> ${logging_directory}/output_error.log", | ||
require => File[$logging_directory, $script_directory], | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'spec_helper' | ||
|
||
describe 'pe_databases::maintenance::pg_repack' do | ||
on_supported_os.each do |os, os_facts| | ||
context "on #{os}" do | ||
let(:pre_condition) { "class { 'pe_databases': }" } | ||
let(:facts) { os_facts } | ||
|
||
it { is_expected.to compile } | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'spec_helper' | ||
|
||
describe 'pe_databases::maintenance::vacuum_full' do | ||
on_supported_os.each do |os, os_facts| | ||
context "on #{os}" do | ||
let(:pre_condition) { "class { 'pe_databases': }" } | ||
let(:facts) { os_facts } | ||
|
||
it { is_expected.to compile } | ||
end | ||
end | ||
end |
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.
Could this instead check something more direct than PE Version, such as the existence of pg_repack itself?
Then, this module could be used with manual installs of pg_repack in older versions of PE.
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.
Untested:
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.
if someone really wants to use pg_repack on an older version of PE they can set manage_database_maintenance to false and then include the pg_repack manifest via a profile.
I don't suspect the use of manually installed pg_repack will be high in older installs.