Skip to content

Commit

Permalink
Decrease the amount of node saves
Browse files Browse the repository at this point in the history
Rebase of PR crowbar#80
Only save the node when attribute(s) have changed
Do not fetch monitor secret if we're the master
  • Loading branch information
scottwulf committed Aug 1, 2017
1 parent 3d3bc1d commit f298a52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
5 changes: 4 additions & 1 deletion chef/cookbooks/ceph/recipes/mon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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 @@ -85,10 +87,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

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
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
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"
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
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

0 comments on commit f298a52

Please sign in to comment.