Database: add slave_connection support

Nova is able to talk to a read-only database for some tables so it
improves the scalability of MySQL server and reduce the access to the
server in charge of writes.

More documentation: https://wiki.openstack.org/wiki/Slave_usage

Change-Id: I1d44332acb381b11d90b63535d274f535be26d55
This commit is contained in:
Emilien Macchi 2015-01-26 16:10:54 -05:00
parent f0227c71b1
commit 1b2725b551
6 changed files with 32 additions and 0 deletions

View File

@ -24,16 +24,22 @@
# (optional) Connection url to connect to nova database.
# Defaults to undef
#
# [*slave_connection*]
# (optional) Connection url to connect to nova slave database (read-only).
# Defaults to undef
#
# [*database_idle_timeout*]
# (optional) Timeout before idle db connections are reaped.
# Defaults to undef
#
class nova::db (
$database_connection = undef,
$slave_connection = undef,
$database_idle_timeout = undef,
) {
$database_connection_real = pick($database_connection, $::nova::database_connection, false)
$slave_connection_real = pick($slave_connection, $::nova::slave_connection, false)
$database_idle_timeout_real = pick($database_idle_timeout, $::nova::database_idle_timeout, false)
if $database_connection_real {
@ -51,6 +57,15 @@ class nova::db (
'database/connection': value => $database_connection_real, secret => true;
'database/idle_timeout': value => $database_idle_timeout_real;
}
if $slave_connection_real {
nova_config {
'database/slave_connection': value => $slave_connection_real, secret => true;
}
} else {
nova_config {
'database/slave_connection': ensure => absent;
}
}
}
}

View File

@ -13,6 +13,10 @@
# (optional) Connection url to connect to nova database.
# Defaults to false
#
# [*slave_connection*]
# (optional) Connection url to connect to nova slave database (read-only).
# Defaults to false
#
# [*database_idle_timeout*]
# (optional) Timeout before idle db connections are reaped.
# Defaults to 3600
@ -227,6 +231,7 @@
class nova(
$ensure_package = 'present',
$database_connection = false,
$slave_connection = false,
$database_idle_timeout = 3600,
$rpc_backend = 'rabbit',
$image_service = 'nova.image.glance.GlanceImageService',

View File

@ -230,6 +230,7 @@ describe 'nova::api' do
end
it { should_not contain_nova_config('database/connection') }
it { should_not contain_nova_config('database/slave_connection') }
it { should_not contain_nova_config('database/idle_timeout').with_value('3600') }
end
@ -237,12 +238,14 @@ describe 'nova::api' do
let :pre_condition do
"class { 'nova':
database_connection => 'mysql://user:pass@db/db',
slave_connection => 'mysql://user:pass@slave/db',
database_idle_timeout => '30',
}
"
end
it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) }
it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) }
it { should contain_nova_config('database/idle_timeout').with_value('30') }
end

View File

@ -56,6 +56,7 @@ describe 'nova::conductor' do
end
it { should_not contain_nova_config('database/connection') }
it { should_not contain_nova_config('database/slave_connection') }
it { should_not contain_nova_config('database/idle_timeout').with_value('3600') }
end
@ -63,12 +64,14 @@ describe 'nova::conductor' do
let :pre_condition do
"class { 'nova':
database_connection => 'mysql://user:pass@db/db',
slave_connection => 'mysql://user:pass@slave/db',
database_idle_timeout => '30',
}
"
end
it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) }
it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) }
it { should contain_nova_config('database/idle_timeout').with_value('30') }
end

View File

@ -10,6 +10,7 @@ describe 'nova::db' do
context 'with default parameters' do
it { should_not contain_nova_config('database/connection') }
it { should_not contain_nova_config('database/slave_connection') }
it { should_not contain_nova_config('database/idle_timeout') }
end
@ -17,11 +18,13 @@ describe 'nova::db' do
before :each do
params.merge!(
:database_connection => 'mysql://user:pass@db/db',
:slave_connection => 'mysql://user:pass@slave/db',
:database_idle_timeout => '30',
)
end
it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) }
it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) }
it { should contain_nova_config('database/idle_timeout').with_value('30') }
end

View File

@ -49,6 +49,7 @@ describe 'nova::scheduler' do
end
it { should_not contain_nova_config('database/connection') }
it { should_not contain_nova_config('database/slave_connection') }
it { should_not contain_nova_config('database/idle_timeout').with_value('3600') }
end
@ -56,12 +57,14 @@ describe 'nova::scheduler' do
let :pre_condition do
"class { 'nova':
database_connection => 'mysql://user:pass@db/db',
slave_connection => 'mysql://user:pass@slave/db',
database_idle_timeout => '30',
}
"
end
it { should contain_nova_config('database/connection').with_value('mysql://user:pass@db/db').with_secret(true) }
it { should contain_nova_config('database/slave_connection').with_value('mysql://user:pass@slave/db').with_secret(true) }
it { should contain_nova_config('database/idle_timeout').with_value('30') }
end