Skip to content

Commit

Permalink
Merge pull request #730 from StatensPensjonskasse/cleanup-journaling-…
Browse files Browse the repository at this point in the history
…config

Remove nojournal parameter; Cleanup journal management
  • Loading branch information
h-haaks authored Apr 5, 2024
2 parents 943126d + b6dcd67 commit 4c5f8af
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 28 deletions.
14 changes: 3 additions & 11 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ The following parameters are available in the `mongodb::server` class:
* [`fork`](#-mongodb--server--fork)
* [`port`](#-mongodb--server--port)
* [`journal`](#-mongodb--server--journal)
* [`nojournal`](#-mongodb--server--nojournal)
* [`smallfiles`](#-mongodb--server--smallfiles)
* [`cpu`](#-mongodb--server--cpu)
* [`auth`](#-mongodb--server--auth)
Expand Down Expand Up @@ -1103,16 +1102,9 @@ Default value: `undef`

Data type: `Optional[Boolean]`

Set to true to enable operation journaling to ensure write durability and data consistency.

Default value: `undef`

##### <a name="-mongodb--server--nojournal"></a>`nojournal`

Data type: `Optional[Boolean]`

Set nojournal = true to disable durability journaling. By default, mongod enables journaling in 64-bit versions after v2.0.
Note: You must use journal to enable journaling on 32-bit systems.
Enable or disable the durability journal to ensure data files remain valid and recoverable.
Available in MongoDB < 7.0
Default: true on 64-bit systems, false on 32-bit systems

Default value: `undef`

Expand Down
1 change: 0 additions & 1 deletion data/Debian-family.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
mongodb::server::user: 'mongodb'
mongodb::server::group: 'mongodb'
mongodb::server::dbpath: '/var/lib/mongodb'
mongodb::server::journal: false
mongodb::mongos::service_user: 'mongodb'
mongodb::mongos::service_group: 'mongodb'
1 change: 0 additions & 1 deletion data/Linux-family.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
mongodb::server::user: 'mongod'
mongodb::server::group: 'mongod'
mongodb::server::dbpath: '/var/lib/mongodb'
mongodb::server::journal: true
mongodb::mongos::service_user: 'mongod'
mongodb::mongos::service_group: 'mongod'
1 change: 0 additions & 1 deletion data/RedHat-family.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
mongodb::server::user: 'mongod'
mongodb::server::group: 'mongod'
mongodb::server::dbpath: '/var/lib/mongo'
mongodb::server::journal: true
mongodb::mongos::service_user: 'mongod'
mongodb::mongos::service_group: 'mongod'
1 change: 0 additions & 1 deletion data/Suse-family.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
mongodb::server::user: 'mongod'
mongodb::server::group: 'mongod'
mongodb::server::dbpath: '/var/lib/mongodb'
mongodb::server::journal: true
mongodb::mongos::service_user: 'mongod'
mongodb::mongos::service_group: 'mongod'
31 changes: 25 additions & 6 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@
# Specifies a TCP port for the server instance to listen for client connections.
#
# @param journal
# Set to true to enable operation journaling to ensure write durability and data consistency.
#
# @param nojournal
# Set nojournal = true to disable durability journaling. By default, mongod enables journaling in 64-bit versions after v2.0.
# Note: You must use journal to enable journaling on 32-bit systems.
# Enable or disable the durability journal to ensure data files remain valid and recoverable.
# Available in MongoDB < 7.0
# Default: true on 64-bit systems, false on 32-bit systems
#
# @param smallfiles
# Set to true to modify MongoDB to use a smaller default data file size. Specifically, smallfiles reduces
Expand Down Expand Up @@ -323,7 +321,6 @@
Boolean $fork = false,
Optional[Integer[1, 65535]] $port = undef,
Optional[Boolean] $journal = undef,
Optional[Boolean] $nojournal = undef,
Optional[Boolean] $smallfiles = undef,
Optional[Boolean] $cpu = undef,
Boolean $auth = false,
Expand Down Expand Up @@ -383,6 +380,28 @@
'clusterManager', 'clusterMonitor', 'hostManager', 'root', 'restore',
],
) inherits mongodb::globals {
if $journal != undef {
if $mongodb::globals::repo_location == undef {
$_repo_loc_version_match = undef
} else {
$_repo_loc_version_match = $mongodb::globals::repo_location.match(/[0-9]+\.[0-9]+/)
}
if (
$mongodb::globals::manage_package_repo
and $mongodb::globals::repo_location == undef
and versioncmp($mongodb::globals::repo_version, '7.0') >= 0
) or (
$mongodb::globals::manage_package_repo
and $mongodb::globals::repo_location != undef
and $_repo_loc_version_match != undef
and versioncmp($_repo_loc_version_match[0], '7.0') >= 0
) or (
$package_ensure =~ /\./ and versioncmp($package_ensure, '7.0.0') >= 0
) {
fail('`journal` parameter is only supported for MongoDB < 7.0')
}
}

contain mongodb::server::install
contain mongodb::server::config
contain mongodb::server::service
Expand Down
1 change: 0 additions & 1 deletion manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
$fork = $mongodb::server::fork
$port = $mongodb::server::port
$journal = $mongodb::server::journal
$nojournal = $mongodb::server::nojournal
$smallfiles = $mongodb::server::smallfiles
$cpu = $mongodb::server::cpu
$auth = $mongodb::server::auth
Expand Down
100 changes: 98 additions & 2 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
with_content(%r{^storage\.dbPath: #{db_path}$}).
with_content(%r{^net\.bindIp: 127\.0\.0\.1$}).
with_content(%r{^systemLog\.logAppend: true$}).
with_content(%r{^systemLog\.path: #{log_path}$})
with_content(%r{^systemLog\.path: #{log_path}$}).
without_content(%r{^storage\.journal\.enabled:})
end

it { is_expected.to contain_class('mongodb::repo') }
Expand Down Expand Up @@ -198,7 +199,7 @@
it { is_expected.to contain_file(config_file).with_content(%r{^setParameter:\n textSearchEnable=true}) }
end

describe 'with journal:' do
describe 'with journal: true' do
let :params do
{
journal: true
Expand All @@ -208,6 +209,101 @@
it { is_expected.to contain_file(config_file).with_content(%r{^storage\.journal\.enabled: true$}) }
end

describe 'with journal: false' do
let :params do
{
journal: false
}
end

it { is_expected.to contain_file(config_file).with_content(%r{^storage\.journal\.enabled: false$}) }
end

describe 'with journal and package_version < 7.0.0' do
let :params do
{
package_ensure: '6.0.0',
journal: true
}
end

it { is_expected.to contain_file(config_file).with_content(%r{^storage\.journal\.enabled: true$}) }
end

describe 'with journal and package_version >= 7.0.0' do
let :params do
{
package_ensure: '7.0.0',
journal: true
}
end

it { is_expected.to raise_error(Puppet::Error) }
end

describe 'with journal and user defined repo_location without version' do
let :params do
{
journal: true
}
end
let(:pre_condition) do
[
'class mongodb::globals {
$manage_package_repo = true
$version = "5.0"
$edition = "org"
$repo_location = "https://repo.myorg.com/"
}',
'class{"mongodb::globals": }'
]
end

it { is_expected.to contain_file(config_file).with_content(%r{^storage\.journal\.enabled: true$}) }
end

describe 'with journal and user defined repo_location with version < 7.0' do
let :params do
{
journal: true
}
end
let(:pre_condition) do
[
'class mongodb::globals {
$manage_package_repo = true
$version = "5.0"
$edition = "org"
$repo_location = "https://repo.myorg.com/6.0/"
}',
'class{"mongodb::globals": }'
]
end

it { is_expected.to contain_file(config_file).with_content(%r{^storage\.journal\.enabled: true$}) }
end

describe 'with journal and user defined repo_location with version >= 7.0' do
let :params do
{
journal: true
}
end
let(:pre_condition) do
[
'class mongodb::globals {
$manage_package_repo = true
$version = "5.0"
$edition = "org"
$repo_location = "https://repo.myorg.com/7.0/"
}',
'class{"mongodb::globals": }'
]
end

it { is_expected.to raise_error(Puppet::Error) }
end

# check nested quota and quotafiles
describe 'with quota to' do
context 'true and without quotafiles' do
Expand Down
6 changes: 2 additions & 4 deletions templates/mongodb.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ processManagement:

#Storage
storage.dbPath: <%= @dbpath %>
<% if @nojournal -%>
storage.journal.enabled: false
<% elsif @journal -%>
storage.journal.enabled: true
<% if @journal != nil -%>
storage.journal.enabled: <%= @journal %>
<% end -%>
<% if @noprealloc -%>
storage.preallocDataFiles: <%= !@noprealloc %>
Expand Down

0 comments on commit 4c5f8af

Please sign in to comment.