Skip to content

Commit f298a52

Browse files
committed
Decrease the amount of node saves
Rebase of PR crowbar#80 Only save the node when attribute(s) have changed Do not fetch monitor secret if we're the master
1 parent 3d3bc1d commit f298a52

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

chef/cookbooks/ceph/recipes/mon.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
add_key.run_command
5353
add_key.error!
5454

55+
# no need to check if the attribute is already set: it's part of the
56+
# only_if
5557
node.set["ceph"]["monitor-secret"] = monitor_key
5658
node.save
5759
end
@@ -85,10 +87,11 @@
8587
add_key.run_command
8688
add_key.error!
8789

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

chef/cookbooks/ceph/recipes/osd.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,19 @@
6969
end
7070

7171
if is_crowbar?
72-
node.set["ceph"]["osd_devices"] = [] if node["ceph"]["osd_devices"].nil?
72+
dirty = false
73+
74+
node.set["ceph"]["osd_devices"] ||= []
7375
min_size_blocks = node["ceph"]["osd"]["min_size_gb"] * 1024 * 1024 * 2
7476
unclaimed_disks = BarclampLibrary::Barclamp::Inventory::Disk.unclaimed(node).sort.select { |d| d.size >= min_size_blocks }
7577

7678
# if devices for journal are explicitely listed, do not use automatic journal assigning to SSD
7779
if !node["ceph"]["osd"]["journal_devices"].empty?
78-
node.set["ceph"]["osd"]["use_ssd_for_journal"] = false
80+
# explicit comparison because we don't want a condition that uses nil
81+
if node["ceph"]["osd"]["use_ssd_for_journal"] != false
82+
node.set["ceph"]["osd"]["use_ssd_for_journal"] = false
83+
dirty = true
84+
end
7985
end
8086

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

91-
node.set["ceph"]["osd"]["use_ssd_for_journal"] = false unless has_ssds && has_hdds
97+
use_ssd_for_journal = has_ssds && has_hdds
98+
if node["ceph"]["osd"]["use_ssd_for_journal"] != use_ssd_for_journal
99+
node.set["ceph"]["osd"]["use_ssd_for_journal"] = use_ssd_for_journal
100+
dirty = true
101+
end
92102
end
93103

94104
if node["ceph"]["disk_mode"] == "first" && node["ceph"]["osd_devices"].empty?
@@ -127,7 +137,7 @@
127137
end
128138
device["device"] = d.name
129139
node.set["ceph"]["osd_devices"].push(device)
130-
node.save
140+
dirty = true
131141
else
132142
Chef::Log.info("Ceph: Ignoring #{d.name}")
133143
end
@@ -198,8 +208,15 @@
198208
end
199209
end
200210
end
201-
node.set["ceph"]["osd_devices"][index]["status"] = "deployed"
202-
node.set["ceph"]["osd_devices"][index]["journal"] = journal_device unless journal_device.nil?
211+
if node["ceph"]["osd_devices"][index]["status"] != "deployed"
212+
node.set["ceph"]["osd_devices"][index]["status"] = "deployed"
213+
dirty = true
214+
end
215+
# if journal_device is nil, this will still work as expected
216+
if node["ceph"]["osd_devices"][index]["journal"] != journal_device
217+
node.set["ceph"]["osd_devices"][index]["journal"] = journal_device
218+
dirty = true
219+
end
203220

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

214230
service "ceph_osd" do
215231
case service_type
@@ -234,5 +250,7 @@
234250
end
235251
end
236252
end
253+
254+
node.save if dirty
237255
end
238256
end

0 commit comments

Comments
 (0)