Skip to content
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

Decrease amount of node saves #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion chef/cookbooks/ceph/recipes/mon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
add_key.run_command
add_key.error!

# no need to check if the attribute is already set: it's part of the
# only_if
node.set["ceph"]["monitor-secret"] = monitor_key
node.save
end
Expand Down Expand Up @@ -83,10 +85,11 @@
add_key.run_command
add_key.error!

# no need to check if the attribute is already set: it's part of the
node.set["ceph"]["monitor-secret"] = monitor_key
node.save
end
only_if { node["ceph"]["monitor-secret"].empty? }
only_if { node["ceph"]["monitor-secret"].empty? && !node[:ceph][:master] }
notifies :run, "execute[ceph-mon mkfs]", :immediately
end

Expand Down
32 changes: 25 additions & 7 deletions chef/cookbooks/ceph/recipes/osd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@
end

if is_crowbar?
node.set["ceph"]["osd_devices"] = [] if node["ceph"]["osd_devices"].nil?
dirty = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call it changed ;)


node.set["ceph"]["osd_devices"] ||= []
min_size_blocks = node["ceph"]["osd"]["min_size_gb"] * 1024 * 1024 * 2
unclaimed_disks = BarclampLibrary::Barclamp::Inventory::Disk.unclaimed(node).sort.select { |d| d.size >= min_size_blocks }

# if devices for journal are explicitely listed, do not use automatic journal assigning to SSD
if !node["ceph"]["osd"]["journal_devices"].empty?
node.set["ceph"]["osd"]["use_ssd_for_journal"] = false
# explicit comparison because we don't want a condition that uses nil
if node["ceph"]["osd"]["use_ssd_for_journal"] != false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockNesting: Avoid more than 3 levels of block nesting. (https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count)

node.set["ceph"]["osd"]["use_ssd_for_journal"] = false
dirty = true
end
end

# If no OSDs have yet been deployed, check what type of disks are available.
Expand All @@ -88,7 +94,11 @@
has_ssds = unclaimed_disks.any? { |d| node[:block_device][d.name.gsub("/dev/", "")]["rotational"] == "0" }
has_hdds = unclaimed_disks.any? { |d| node[:block_device][d.name.gsub("/dev/", "")]["rotational"] == "1" }

node.set["ceph"]["osd"]["use_ssd_for_journal"] = false unless has_ssds && has_hdds
use_ssd_for_journal = has_ssds && has_hdds
if node["ceph"]["osd"]["use_ssd_for_journal"] != use_ssd_for_journal

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockNesting: Avoid more than 3 levels of block nesting. (https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count)

node.set["ceph"]["osd"]["use_ssd_for_journal"] = use_ssd_for_journal
dirty = true
end
end

if node["ceph"]["disk_mode"] == "first" && node["ceph"]["osd_devices"].empty?
Expand Down Expand Up @@ -127,7 +137,7 @@
end
device["device"] = d.name
node.set["ceph"]["osd_devices"].push(device)
node.save
dirty = true
else
Chef::Log.info("Ceph: Ignoring #{d.name}")
end
Expand Down Expand Up @@ -198,8 +208,15 @@
end
end
end
node.set["ceph"]["osd_devices"][index]["status"] = "deployed"
node.set["ceph"]["osd_devices"][index]["journal"] = journal_device unless journal_device.nil?
if node["ceph"]["osd_devices"][index]["status"] != "deployed"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockNesting: Avoid more than 3 levels of block nesting. (https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count)

node.set["ceph"]["osd_devices"][index]["status"] = "deployed"
dirty = true
end
# if journal_device is nil, this will still work as expected
if node["ceph"]["osd_devices"][index]["journal"] != journal_device

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockNesting: Avoid more than 3 levels of block nesting. (https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count)

node.set["ceph"]["osd_devices"][index]["journal"] = journal_device
dirty = true
end

execute "Writing Ceph OSD device mappings to fstab" do
command "tail -n1 /etc/mtab >> /etc/fstab"
Expand All @@ -209,7 +226,6 @@
# No need to specifically enable ceph-osd@N on systemd systems, as this
# is done automatically by ceph-disk-activate
end
node.save

service "ceph_osd" do
case service_type
Expand All @@ -234,5 +250,7 @@
end
end
end

node.save if dirty
end
end