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

Improve differences between generated mysql service id values #1293

Merged
merged 1 commit into from
Mar 31, 2020
Merged
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
11 changes: 10 additions & 1 deletion lib/facter/mysql_server_id.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
def mysql_id_get
Facter.value(:macaddress).split(':')[2..-1].reduce(0) { |total, value| (total << 6) + value.hex }
# Convert the existing mac to an integer
macval = Facter.value(:macaddress).delete(':').to_i(16)

# Valid range is from 1 - 4294967295 for replication hosts.
# We can not guarantee a fully unique value, this reduces the
# full mac value down to into that number space.
#
# The -1/+1 ensures that we keep above 1 if we get unlucky
# enough to hit a mac address that evenly divides.
(macval % (4_294_967_295 - 1)) + 1
end

Facter.add('mysql_server_id') do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/facter/mysql_server_id_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Facter.fact(:macaddress).stubs(:value).returns('3c:97:0e:69:fb:e1')
end
it do
Facter.fact(:mysql_server_id).value.to_s.should == '4116385'
Facter.fact(:mysql_server_id).value.to_s.should == '241857808'
end
end

Expand All @@ -20,7 +20,7 @@
Facter.fact(:macaddress).stubs(:value).returns('00:00:00:00:00:00')
end
it do
Facter.fact(:mysql_server_id).value.to_s.should == '0'
Facter.fact(:mysql_server_id).value.to_s.should == '1'
end
end

Expand Down