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

Remove the concept of dry_run #64

Merged
merged 1 commit into from
Apr 1, 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
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Removed
- Removed the `dry_run` option (https://github.com/zendesk/global_uid/pull/64)

## [3.7.1] - 2020-02-06
### Added
- Support for Rails 6.0. (https://github.com/zendesk/global_uid/pull/60)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Here's a complete list of the options you can use:
| Name | Default | Description |
| --------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| `:disabled` | `false` | Disable GlobalUid entirely |
| `:dry_run` | `false` | Setting this parameter causes the REPLACE INTO statements to run, but the id picked up will not be used. |
| `:connection_timeout` | 3 seconds | Timeout for connecting to a global UID server |
| `:query_timeout` | 10 seconds | Timeout for retrieving a global UID from a server before we move on to the next server |
| `:connection_retry` | 10 minutes | After failing to connect or query a UID server, how long before we retry |
Expand Down
12 changes: 1 addition & 11 deletions lib/global_uid/active_record_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@ def global_uid_before_create
return if GlobalUid::Base.global_uid_options[:disabled]
return if self.class.global_uid_disabled

global_uid = nil
realtime = Benchmark::realtime do
global_uid = self.class.generate_uid
end

if GlobalUid::Base.global_uid_options[:dry_run]
ActiveRecord::Base.logger.info("GlobalUid dry-run: #{self.class.name}\t#{global_uid}\t#{"%.4f" % realtime}")
return
end

self.id = global_uid
self.id = self.class.generate_uid
end

module ClassMethods
Expand Down
3 changes: 1 addition & 2 deletions lib/global_uid/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class Base
:query_timeout => 10,
:increment_by => 5, # This will define the maximum number of servers that you can have
:disabled => false,
:per_process_affinity => true,
:dry_run => false
:per_process_affinity => true
}

def self.servers
Expand Down
4 changes: 2 additions & 2 deletions lib/global_uid/migration_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module MigrationExtension
def create_table(name, options = {}, &blk)
uid_enabled = !(GlobalUid::Base.global_uid_options[:disabled] || options[:use_global_uid] == false)

# rules for stripping out auto_increment -- enabled, not dry-run, and not a "PK-less" table
remove_auto_increment = uid_enabled && !GlobalUid::Base.global_uid_options[:dry_run] && !(options[:id] == false)
# rules for stripping out auto_increment -- enabled and not a "PK-less" table
remove_auto_increment = uid_enabled && !(options[:id] == false)

options.merge!(:id => false) if remove_auto_increment

Expand Down
29 changes: 0 additions & 29 deletions test/global_uid_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,34 +328,6 @@ def table_exists?(connection, table)
end
end

describe "In dry-run mode" do
before do
GlobalUid::Base.global_uid_options[:dry_run] = true
CreateWithNoParams.up
end

it "increment normally1" do
(1..10).each do |i|
assert_equal i, WithGlobalUID.create!.id
end
end

it "insert into the UID servers nonetheless" do
GlobalUid::Base.expects(:get_uid_for_class).at_least(10)
10.times { WithGlobalUID.create! }
end

it "log the results" do
ActiveRecord::Base.logger.expects(:info).at_least(10)
10.times { WithGlobalUID.create! }
end

after do
reset_connections!
CreateWithNoParams.down
end
end

describe "with forking" do
def parent_child_fork_values
IO.pipe do |read_pipe, write_pipe|
Expand Down Expand Up @@ -441,7 +413,6 @@ def reset_connections!
def restore_defaults!
GlobalUid::Base.global_uid_options[:storage_engine] = nil
GlobalUid::Base.global_uid_options[:disabled] = false
GlobalUid::Base.global_uid_options[:dry_run] = false
end

def show_create_sql(klass, table)
Expand Down