Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Remove ServerVariables module
Browse files Browse the repository at this point in the history
This module adds confusion to the implementation, one could mistakenly
think it's how to configure a production database, instead,
remove it and rely on the database.yml to have the variables set on
in the dev and test environment for this gem.

For production, clients should be setting the values directly in their
MySQL configuration.
https://dev.mysql.com/doc/refman/5.6/en/replication-options-master.html#sysvar_auto_increment_increment

The `offset` variables were also unused and have been removed
  • Loading branch information
mriddle committed Mar 27, 2020
1 parent 4e32e35 commit ff0b673
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 41 deletions.
2 changes: 0 additions & 2 deletions lib/global_uid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class ConnectionTimeoutException < StandardError ; end
class TimeoutException < StandardError ; end
class InvalidIncrementException < StandardError ; end
class InvalidIncrementPreventionException < StandardError ; end

autoload :ServerVariables, "global_uid/server_variables"
end

ActiveRecord::Base.send(:include, GlobalUid::ActiveRecordExtension)
Expand Down
8 changes: 2 additions & 6 deletions lib/global_uid/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.drop_uid_tables(id_table_name, options={})
end
end

def self.new_connection(name, connection_timeout, offset, increment_by)
def self.new_connection(name, connection_timeout)
raise "No id server '#{name}' configured in database.yml" unless ActiveRecord::Base.configurations.to_h.has_key?(name)
config = ActiveRecord::Base.configurations.to_h[name]
c = config.symbolize_keys
Expand All @@ -76,18 +76,14 @@ def self.init_server_info(options)
raise "You haven't configured any id servers" if id_servers.nil? or id_servers.empty?
raise "More servers configured than increment_by: #{id_servers.size} > #{options[:increment_by]} -- this will create duplicate IDs." if id_servers.size > options[:increment_by]

offset = 1

id_servers.map do |name, i|
info = {}
info[:cx] = nil
info[:name] = name
info[:retry_at] = nil
info[:offset] = offset
info[:rand] = rand
info[:new?] = true
info[:allocated_ids] = Allocations.new(incrementing_by: self.global_uid_increment_by)
offset +=1
info
end
end
Expand All @@ -113,7 +109,7 @@ def self.setup_connections!(options)
info[:new?] = false

begin
connection = new_connection(info[:name], connection_timeout, info[:offset], increment_by)
connection = new_connection(info[:name], connection_timeout)
if !connection.nil? && increment_by != (db_increment = connection.select_value("SELECT @@auto_increment_increment"))
raise InvalidIncrementPreventionException, "Configured: '#{increment_by}', Found: '#{db_increment}' on '#{connection.current_database}'"
end
Expand Down
30 changes: 0 additions & 30 deletions lib/global_uid/server_variables.rb

This file was deleted.

6 changes: 6 additions & 0 deletions test/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ test:
test_id_server_1:
<<: *MYSQL
database: global_uid_test_id_server_1
variables:
auto_increment_increment: 5
auto_increment_offset: 1

test_id_server_2:
<<: *MYSQL
database: global_uid_test_id_server_2
variables:
auto_increment_increment: 5
auto_increment_offset: 2
2 changes: 1 addition & 1 deletion test/global_uid_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def table_exists?(connection, table)
describe "With a timing out server" do
before do
reset_connections!
@a_decent_cx = GlobalUid::Base.new_connection(GlobalUid::Base.global_uid_servers.first, 50, 1, 5)
@a_decent_cx = GlobalUid::Base.new_connection(GlobalUid::Base.global_uid_servers.first, 50)
ActiveRecord::Base.stubs(:mysql2_connection).raises(GlobalUid::ConnectionTimeoutException).then.returns(@a_decent_cx)
@connections = GlobalUid::Base.get_connections
end
Expand Down
2 changes: 0 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
require 'global_uid'
require 'phenix'

GlobalUid::Base.extend(GlobalUid::ServerVariables)

Phenix.configure do |config|
config.database_config_path = File.join(File.dirname(__FILE__), "config/database.yml")
end
Expand Down

0 comments on commit ff0b673

Please sign in to comment.