Skip to content

Commit 993abab

Browse files
committed
Improve differences between generated mysql service id values
This uses the entire mac address then reduces the value to the acceptable range for mysql.
1 parent 95f9b98 commit 993abab

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/facter/mysql_server_id.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
def mysql_id_get
2-
Facter.value(:macaddress).split(':')[2..-1].reduce(0) { |total, value| (total << 6) + value.hex }
2+
# Convert the existing mac to an integer
3+
macval = Facter.value(:macaddress).gsub(':', '').to_i(16)
4+
5+
# Valid range is from 1 - 4294967295 for replication hosts.
6+
# We can not guarantee a fully unique value, this reduces the
7+
# full mac value down to into that number space.
8+
#
9+
# The -1/+1 ensures that we keep above 1 if we get unlucky
10+
# enough to hit a mac address that evenly divides.
11+
return (macval % (4_294_967_295 - 1)) + 1
312
end
413

514
Facter.add('mysql_server_id') do

spec/unit/facter/mysql_server_id_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Facter.fact(:macaddress).stubs(:value).returns('3c:97:0e:69:fb:e1')
1212
end
1313
it do
14-
Facter.fact(:mysql_server_id).value.to_s.should == '4116385'
14+
Facter.fact(:mysql_server_id).value.to_s.should == '241857808'
1515
end
1616
end
1717

@@ -20,7 +20,7 @@
2020
Facter.fact(:macaddress).stubs(:value).returns('00:00:00:00:00:00')
2121
end
2222
it do
23-
Facter.fact(:mysql_server_id).value.to_s.should == '0'
23+
Facter.fact(:mysql_server_id).value.to_s.should == '1'
2424
end
2525
end
2626

0 commit comments

Comments
 (0)