switchman 2.0.0 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/switchman/shard.rb +3 -1
  3. data/db/migrate/20130328212039_create_switchman_shards.rb +2 -0
  4. data/db/migrate/20130328224244_create_default_shard.rb +2 -0
  5. data/db/migrate/20161206323434_add_back_default_string_limits_switchman.rb +2 -0
  6. data/db/migrate/20180828183945_add_default_shard_index.rb +2 -0
  7. data/db/migrate/20180828192111_add_timestamps_to_shards.rb +2 -0
  8. data/db/migrate/20190114212900_add_unique_name_indexes.rb +2 -0
  9. data/lib/switchman.rb +2 -0
  10. data/lib/switchman/action_controller/caching.rb +2 -0
  11. data/lib/switchman/active_record/abstract_adapter.rb +6 -0
  12. data/lib/switchman/active_record/association.rb +10 -4
  13. data/lib/switchman/active_record/attribute_methods.rb +2 -0
  14. data/lib/switchman/active_record/base.rb +4 -2
  15. data/lib/switchman/active_record/batches.rb +2 -0
  16. data/lib/switchman/active_record/calculations.rb +2 -0
  17. data/lib/switchman/active_record/connection_handler.rb +2 -0
  18. data/lib/switchman/active_record/connection_pool.rb +2 -0
  19. data/lib/switchman/active_record/finder_methods.rb +2 -0
  20. data/lib/switchman/active_record/log_subscriber.rb +2 -0
  21. data/lib/switchman/active_record/migration.rb +3 -1
  22. data/lib/switchman/active_record/model_schema.rb +2 -0
  23. data/lib/switchman/active_record/persistence.rb +3 -1
  24. data/lib/switchman/active_record/postgresql_adapter.rb +2 -0
  25. data/lib/switchman/active_record/predicate_builder.rb +2 -0
  26. data/lib/switchman/active_record/query_cache.rb +2 -0
  27. data/lib/switchman/active_record/query_methods.rb +2 -0
  28. data/lib/switchman/active_record/reflection.rb +2 -0
  29. data/lib/switchman/active_record/relation.rb +2 -0
  30. data/lib/switchman/active_record/spawn_methods.rb +2 -0
  31. data/lib/switchman/active_record/statement_cache.rb +2 -0
  32. data/lib/switchman/active_record/table_definition.rb +2 -0
  33. data/lib/switchman/active_record/type_caster.rb +2 -0
  34. data/lib/switchman/active_record/where_clause_factory.rb +2 -0
  35. data/lib/switchman/active_support/cache.rb +4 -2
  36. data/lib/switchman/arel.rb +2 -0
  37. data/lib/switchman/call_super.rb +2 -0
  38. data/lib/switchman/connection_pool_proxy.rb +2 -0
  39. data/lib/switchman/database_server.rb +2 -0
  40. data/lib/switchman/default_shard.rb +2 -0
  41. data/lib/switchman/engine.rb +2 -0
  42. data/lib/switchman/environment.rb +2 -0
  43. data/lib/switchman/errors.rb +2 -0
  44. data/lib/switchman/guard_rail.rb +2 -0
  45. data/lib/switchman/guard_rail/relation.rb +2 -0
  46. data/lib/switchman/open4.rb +2 -0
  47. data/lib/switchman/r_spec_helper.rb +2 -0
  48. data/lib/switchman/rails.rb +2 -0
  49. data/lib/switchman/schema_cache.rb +2 -0
  50. data/lib/switchman/sharded_instrumenter.rb +2 -0
  51. data/lib/switchman/standard_error.rb +2 -0
  52. data/lib/switchman/test_helper.rb +2 -0
  53. data/lib/switchman/version.rb +3 -1
  54. metadata +24 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cec081d77daa09b754a98ce7bc335198b2dfbdbcd093df492a43803ff7a2742
4
- data.tar.gz: d93576725471024b24c4622d33e0eff9c1b61498b6c037e624d9b6ff8c78a442
3
+ metadata.gz: 9dc22c0bf7a00cd1591602240e782813882155b744fa682a26ac20201a45c0e6
4
+ data.tar.gz: fe72352d11d0e81e6e216ba028578c5a4b0f8600fb603f2d5100f99dd4d54721
5
5
  SHA512:
6
- metadata.gz: 6d4c7b1e82460fbdfda1659fc09379583c5e63ecc21d412466563a62c42679db864f8f09c2eaa2bed17b53216c64d18c42caabec76291f25e00bfc1e6a2499a1
7
- data.tar.gz: e52baf68ce2301dfa26abffd423e9855c875232871539fea59ae88ffd8f3b355299cb4c0bb60e32bf90555e7e935d2f73954ec01919cab16993bee73b39e56b6
6
+ metadata.gz: 2311f1ad0547735b6ffa51b18790564b67db99009b1ca4d0080eec7e881dd5e735e745dc6c78c0a5f26b8ca2ef0bc9afeaa5c9fe6cfac0aa882f5c3cb8c7d82c
7
+ data.tar.gz: 6b2f5e2cab99c42d5358c464e22a0dd267a2b66108e3e62f252970735d1482618460b37fc730ec4be2bdeb791e33bb6549ebc939ec9714f4fad21a48bcb01108
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'switchman/database_server'
2
4
  require 'switchman/default_shard'
3
5
  require 'switchman/environment'
@@ -40,7 +42,7 @@ module Switchman
40
42
  def default(reload_deprecated = false, reload: false, with_fallback: false)
41
43
  if reload_deprecated
42
44
  reload = reload_deprecated
43
- ActiveSupport::Deprecation.warn("positional reload parameter to Switchman::Shard.default is deprecated; use `reload: true`")
45
+ ::ActiveSupport::Deprecation.warn("positional reload parameter to Switchman::Shard.default is deprecated; use `reload: true`")
44
46
  end
45
47
  if !@default || reload
46
48
  # Have to create a dummy object so that several key methods still work
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateSwitchmanShards < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table :switchman_shards do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateDefaultShard < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  unless Switchman::Shard.default.is_a?(Switchman::Shard)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddBackDefaultStringLimitsSwitchman < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  add_string_limit_if_missing :switchman_shards, :name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddDefaultShardIndex < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  Switchman::Shard.where(default: nil).update_all(default: false)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddTimestampsToShards < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_timestamps :switchman_shards, null: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddUniqueNameIndexes < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_index :switchman_shards, [:database_server_id, :name], unique: true
data/lib/switchman.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "guard_rail"
2
4
  require "switchman/open4"
3
5
  require "switchman/engine"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActionController
3
5
  module Caching
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'switchman/sharded_instrumenter'
2
4
 
3
5
  module Switchman
@@ -27,6 +29,10 @@ module Switchman
27
29
  quote_table_name(name)
28
30
  end
29
31
 
32
+ def schema_migration
33
+ ::ActiveRecord::SchemaMigration
34
+ end
35
+
30
36
  protected
31
37
 
32
38
  def log(*args, &block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module Association
@@ -75,7 +77,7 @@ module Switchman
75
77
  module Association
76
78
  if ::Rails.version >= "5.2" and ::Rails.version < "6.0"
77
79
  def run(preloader)
78
- associated_records_by_owner(preloader).each do |owner, records|
80
+ associated_records_by_owner.each do |owner, records|
79
81
  associate_records_to_owner(owner, records)
80
82
  end
81
83
  end
@@ -102,6 +104,7 @@ module Switchman
102
104
  end
103
105
 
104
106
  def associated_records_by_owner(preloader = nil)
107
+ return @associated_records_by_owner if defined?(@associated_records_by_owner)
105
108
  owners_map = owners_by_key
106
109
 
107
110
  if klass.nil? || owners_map.empty?
@@ -149,10 +152,13 @@ module Switchman
149
152
  records.flatten!
150
153
  end
151
154
 
155
+ # This ivar may look unused, but remember this is an extension of
156
+ # rails' AR::Associations::Preloader::Association class. It gets used
157
+ # by that class (and its subclasses).
152
158
  @preloaded_records = records
153
159
 
154
160
  # Each record may have multiple owners, and vice-versa
155
- records_by_owner = owners.each_with_object({}) do |owner,h|
161
+ @associated_records_by_owner = owners.each_with_object({}) do |owner,h|
156
162
  h[owner] = []
157
163
  end
158
164
  records.each do |record|
@@ -161,10 +167,10 @@ module Switchman
161
167
 
162
168
  owners_map[owner_key.to_s].each do |owner|
163
169
  owner.association(reflection.name).set_inverse_instance(record)
164
- records_by_owner[owner] << record
170
+ @associated_records_by_owner[owner] << record
165
171
  end
166
172
  end
167
- records_by_owner
173
+ @associated_records_by_owner
168
174
  end
169
175
 
170
176
  def owners_by_key
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module AttributeMethods
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module Base
@@ -128,9 +130,9 @@ module Switchman
128
130
  result
129
131
  end
130
132
 
131
- def transaction(options={}, &block)
133
+ def transaction(**kwargs, &block)
132
134
  shard.activate(self.class.shard_category) do
133
- self.class.transaction(options, &block)
135
+ self.class.transaction(**kwargs, &block)
134
136
  end
135
137
  end
136
138
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module Batches
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module Calculations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'switchman/connection_pool_proxy'
2
4
 
3
5
  module Switchman
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'switchman/errors'
2
4
 
3
5
  module Switchman
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module FinderMethods
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module LogSubscriber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module Migration
@@ -29,7 +31,7 @@ module Switchman
29
31
 
30
32
  module Migrator
31
33
  def generate_migrator_advisory_lock_id
32
- shard_name_hash = Zlib.crc32(Shard.current.name)
34
+ shard_name_hash = Zlib.crc32("#{Shard.current.id}:#{Shard.current.name}")
33
35
  ::ActiveRecord::Migrator::MIGRATOR_SALT * shard_name_hash
34
36
  end
35
37
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module ModelSchema
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module Persistence
4
6
  # touch reads the id attribute directly, so it's not relative to the current shard
5
- def touch(*)
7
+ def touch(*, **)
6
8
  shard.activate(self.class.shard_category) { super }
7
9
  end
8
10
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module PostgreSQLAdapter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module PredicateBuilder
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module QueryCache
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module QueryMethods
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module Reflection
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module Relation
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module SpawnMethods
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module StatementCache
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module TableDefinition
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module TypeCaster
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveRecord
3
5
  module WhereClauseFactory
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module ActiveSupport
3
5
  module Cache
@@ -15,12 +17,12 @@ module Switchman
15
17
  end
16
18
 
17
19
  module RedisCacheStore
18
- def clear(options = {})
20
+ def clear(namespace: nil, **)
19
21
  # RedisCacheStore tries to be smart and only clear the cache under your namespace, if you have one set
20
22
  # unfortunately, it uses the keys command, which is extraordinarily inefficient in a large redis instance
21
23
  # fortunately, we can assume we control the entire instance, because we set up the namespacing, so just
22
24
  # always unset it temporarily for clear calls
23
- options[:namespace] = nil
25
+ namespace = nil
24
26
  super
25
27
  end
26
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module Arel
3
5
  module Table
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module CallSuper
3
5
  def super_method_above(method_name, above_module)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'switchman/schema_cache'
2
4
 
3
5
  module Switchman
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "securerandom"
2
4
 
3
5
  module Switchman
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'switchman/database_server'
2
4
 
3
5
  module Switchman
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  class Engine < ::Rails::Engine
3
5
  isolate_namespace Switchman
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'etc'
2
4
 
3
5
  module Switchman
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  class NonExistentShardError < RuntimeError; end
3
5
  class ParallelShardExecError < RuntimeError; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module GuardRail
3
5
  module ClassMethods
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module GuardRail
3
5
  module Relation
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open4'
2
4
 
3
5
  # This fixes a bug with exception handling,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "switchman/test_helper"
2
4
 
3
5
  module Switchman
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman::Rails
2
4
  module ClassMethods
3
5
  def self.prepended(klass)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  class SchemaCache < ::ActiveRecord::ConnectionAdapters::SchemaCache
3
5
  delegate :connection, to: :pool
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  class ShardedInstrumenter < ::SimpleDelegator
3
5
  def initialize(instrumenter, shard_host)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module StandardError
3
5
  def initialize(*args)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
4
  module TestHelper
3
5
  class << self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Switchman
2
- VERSION = "2.0.0"
4
+ VERSION = "2.0.6"
3
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  - James Williams
9
9
  - Jacob Fugal
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-10-05 00:00:00.000000000 Z
13
+ date: 2021-03-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -140,16 +140,30 @@ dependencies:
140
140
  name: rspec-rails
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '='
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 3.5.2
145
+ version: '3.5'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '='
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.5'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-mocks
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.5'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: 3.5.2
166
+ version: '3.5'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: simplecov
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -243,7 +257,7 @@ homepage: http://www.instructure.com/
243
257
  licenses:
244
258
  - MIT
245
259
  metadata: {}
246
- post_install_message:
260
+ post_install_message:
247
261
  rdoc_options: []
248
262
  require_paths:
249
263
  - lib
@@ -258,8 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
272
  - !ruby/object:Gem::Version
259
273
  version: '0'
260
274
  requirements: []
261
- rubygems_version: 3.1.2
262
- signing_key:
275
+ rubygems_version: 3.0.3
276
+ signing_key:
263
277
  specification_version: 4
264
278
  summary: Rails sharding magic
265
279
  test_files: []