Add support for --sleep option of the archive command
Now 'nova-manage db archive_deleted_rows' command provides --sleep to define sleep between batches of rows, to busy database operation caused by the archive command. This change introduces the parameter so that the option can be defined in cron job definition. Depends-on: https://review.opendev.org/771749 Change-Id: Ibeb2d24e47a82596acda21289b4ef9b3f36c66a0
This commit is contained in:
parent
74e34d163c
commit
16e7f4c501
@ -79,7 +79,11 @@
|
|||||||
# (optional) Adds a retention policy when purging the shadow tables
|
# (optional) Adds a retention policy when purging the shadow tables
|
||||||
# Defaults to undef.
|
# Defaults to undef.
|
||||||
#
|
#
|
||||||
|
# [*sleep*]
|
||||||
|
# (optional) The amount of time in seconds to sleep between batches when
|
||||||
|
# until_complete is used
|
||||||
|
# Defaults to undef.
|
||||||
|
#
|
||||||
class nova::cron::archive_deleted_rows (
|
class nova::cron::archive_deleted_rows (
|
||||||
$minute = 1,
|
$minute = 1,
|
||||||
$hour = 0,
|
$hour = 0,
|
||||||
@ -95,6 +99,7 @@ class nova::cron::archive_deleted_rows (
|
|||||||
$all_cells = false,
|
$all_cells = false,
|
||||||
$task_log = false,
|
$task_log = false,
|
||||||
$age = undef,
|
$age = undef,
|
||||||
|
$sleep = undef,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include nova::deps
|
include nova::deps
|
||||||
@ -129,9 +134,9 @@ class nova::cron::archive_deleted_rows (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if $maxdelay == 0 {
|
if $maxdelay == 0 {
|
||||||
$sleep = ''
|
$delay_cmd = ''
|
||||||
} else {
|
} else {
|
||||||
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
$delay_cmd = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
||||||
}
|
}
|
||||||
|
|
||||||
if $age {
|
if $age {
|
||||||
@ -140,10 +145,16 @@ class nova::cron::archive_deleted_rows (
|
|||||||
$age_real = ''
|
$age_real = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if $sleep != undef {
|
||||||
|
$sleep_real = " --sleep ${sleep}"
|
||||||
|
} else {
|
||||||
|
$sleep_real = ''
|
||||||
|
}
|
||||||
|
|
||||||
$cron_cmd = 'nova-manage db archive_deleted_rows'
|
$cron_cmd = 'nova-manage db archive_deleted_rows'
|
||||||
|
|
||||||
cron { 'nova-manage db archive_deleted_rows':
|
cron { 'nova-manage db archive_deleted_rows':
|
||||||
command => "${sleep}${cron_cmd}${purge_real} --max_rows ${max_rows}${age_real}${until_complete_real}${all_cells_real}${task_log_real} \
|
command => "${delay_cmd}${cron_cmd}${purge_real} --max_rows ${max_rows}${age_real}${until_complete_real}${all_cells_real}${task_log_real}${sleep_real} \
|
||||||
>>${destination} 2>&1",
|
>>${destination} 2>&1",
|
||||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
user => pick($user, $::nova::params::nova_user),
|
user => pick($user, $::nova::params::nova_user),
|
||||||
|
@ -93,15 +93,15 @@ class nova::cron::purge_shadow_tables (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if $maxdelay == 0 {
|
if $maxdelay == 0 {
|
||||||
$sleep = ''
|
$delay_cmd = ''
|
||||||
} else {
|
} else {
|
||||||
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
$delay_cmd = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
||||||
}
|
}
|
||||||
|
|
||||||
$cron_cmd = 'nova-manage db purge'
|
$cron_cmd = 'nova-manage db purge'
|
||||||
|
|
||||||
cron { 'nova-manage db purge':
|
cron { 'nova-manage db purge':
|
||||||
command => "${sleep}${cron_cmd} --before `date --date='today - ${age} days' +\\%D`${verbose_real}${all_cells_real} \
|
command => "${delay_cmd}${cron_cmd} --before `date --date='today - ${age} days' +\\%D`${verbose_real}${all_cells_real} \
|
||||||
>>${destination} 2>&1",
|
>>${destination} 2>&1",
|
||||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
user => pick($user, $::nova::params::nova_user),
|
user => pick($user, $::nova::params::nova_user),
|
||||||
|
5
releasenotes/notes/archive-sleep-c3de94ddd2066c01.yaml
Normal file
5
releasenotes/notes/archive-sleep-c3de94ddd2066c01.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The new ``nova::cron::archive_deleted_rows::sleep`` parameter has been
|
||||||
|
added.
|
@ -191,6 +191,28 @@ describe 'nova::cron::archive_deleted_rows' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'until_complete enabled and sleep set' do
|
||||||
|
before :each do
|
||||||
|
params.merge!(
|
||||||
|
:until_complete => true,
|
||||||
|
:sleep => 5,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configures a cron with --before' do
|
||||||
|
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
|
||||||
|
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --until-complete --sleep #{params[:sleep]} >>#{params[:destination]} 2>&1",
|
||||||
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
|
:user => params[:user],
|
||||||
|
:minute => params[:minute],
|
||||||
|
:hour => params[:hour],
|
||||||
|
:monthday => params[:monthday],
|
||||||
|
:month => params[:month],
|
||||||
|
:weekday => params[:weekday],
|
||||||
|
:require => 'Anchor[nova::dbsync::end]',
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
on_supported_os({
|
on_supported_os({
|
||||||
|
Loading…
Reference in New Issue
Block a user