lhm-shopify 3.5.1 → 3.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b5fbf9905c14cd938075e3f6b930de0b52cdbc7c048f8ed572c654824681d99
4
- data.tar.gz: c950dd9650c4e04412a91a9d21b6bbff3b3f092ecbbce1474a77518716737d62
3
+ metadata.gz: 1ad526041b49fe42d906fc27a697c3d0982332a7f256f40c179071e954a33d37
4
+ data.tar.gz: 35647043caa59111fd09770a38f160e959baa2022d73d82e1061777423fdc6bb
5
5
  SHA512:
6
- metadata.gz: e92c7cc7cefa85e18a9c5b3d17966574324c8fe8e067f4ac4203241d18e8dae836c82554f92685e90978af26451422852c654fed8f0b855032dee0ac3d0f130d
7
- data.tar.gz: 8755a2814d7d92d015d35ae3636993e39a66b5d27d1980a002eec96a2e33012350310d5f903b5f3b225d6b4bf60295841ee4e35919b927914a0cc700683d357b
6
+ metadata.gz: efce8e7d38b5f5e9769675e423e73d784837b8493d70f11e349041e9356a28078216784b670e246f4adffe8bd594a885ef86148a8da01c0356392219f8e94a40
7
+ data.tar.gz: 4bb36dd1c70a509dcbf3802c2ed2a9ad788253fdb7414e0c7bb3838fe8f68156a2782a3377f3ec1da472e50a463e6d6577330119f41b726c94499f8a7d2a40bf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # 3.5.2 (Dec, 2021)
2
+ * Fixed error on undefined connection, when calling `Lhm.connection` without calling `Lhm.setup` first
3
+ * Changed `Lhm.connection.connection` to `lhm.connection.ar_connection` for increased clarity and readability
4
+
5
+ # 3.5.1 (Dec , 2021)
6
+ * Add better logging to the LHM components (https://github.com/Shopify/lhm/pull/112)
7
+ * Slave lag throttler now supports ActiveRecord > 6.0
8
+ * [Dev] Add `Appraisals` to test against multiple version
9
+
10
+ # 3.5.0 (Dec , 2021)
11
+ * Duplicate of 3.4.2 (unfortunate mistake)
12
+
13
+ # 3.4.2 (Sept, 2021)
14
+ * Fixed Chunker's undefined name error (https://github.com/Shopify/lhm/pull/110)
15
+
1
16
  # 3.4.1 (Sep 22, 2021)
2
17
 
3
18
  * Add better logging to the LHM components (https://github.com/Shopify/lhm/pull/108)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lhm-shopify (3.5.1)
4
+ lhm-shopify (3.5.2)
5
5
  retriable (>= 3.0.0)
6
6
 
7
7
  GEM
data/Rakefile CHANGED
@@ -23,7 +23,6 @@ Rake::TestTask.new('dev') do |t|
23
23
  t.libs << 'spec'
24
24
  t.test_files = FileList[
25
25
  'spec/test_helper.rb',
26
- 'spec/integration/lhm_spec.rb'
27
26
  # Add file to test individually
28
27
  ]
29
28
  t.verbose = true
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- lhm-shopify (3.5.1)
4
+ lhm-shopify (3.5.2)
5
5
  retriable (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- lhm-shopify (3.5.1)
4
+ lhm-shopify (3.5.2)
5
5
  retriable (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- lhm-shopify (3.5.1)
4
+ lhm-shopify (3.5.2)
5
5
  retriable (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- lhm-shopify (3.5.1)
4
+ lhm-shopify (3.5.2)
5
5
  retriable (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -3,12 +3,12 @@ require 'lhm/proxysql_helper'
3
3
 
4
4
  module Lhm
5
5
  class ChunkInsert
6
- def initialize(migration, connection, lowest, highest, options = {})
6
+ def initialize(migration, connection, lowest, highest, retry_options = {})
7
7
  @migration = migration
8
8
  @connection = connection
9
9
  @lowest = lowest
10
10
  @highest = highest
11
- @retry_options = options[:retriable] || {}
11
+ @retry_options = retry_options
12
12
  end
13
13
 
14
14
  def insert_and_return_count_of_rows_created
data/lib/lhm/chunker.rb CHANGED
@@ -31,7 +31,7 @@ module Lhm
31
31
  @retry_options = options[:retriable] || {}
32
32
  @retry_helper = SqlRetry.new(
33
33
  @connection,
34
- options: {
34
+ retry_options: {
35
35
  log_prefix: "Chunker"
36
36
  }.merge!(@retry_options)
37
37
  )
@@ -2,19 +2,15 @@ require 'delegate'
2
2
  require 'lhm/sql_retry'
3
3
 
4
4
  module Lhm
5
- class Connection < SimpleDelegator
6
-
7
5
  # Lhm::Connection inherits from SingleDelegator. It will forward any unknown method calls to the ActiveRecord
8
6
  # connection.
9
- alias connection __getobj__
10
- alias connection= __setobj__
7
+ class Connection < SimpleDelegator
11
8
 
12
- def initialize(connection:, default_log_prefix: nil, options: {}, retry_config: {})
9
+ def initialize(connection:, default_log_prefix: nil, options: {})
13
10
  @default_log_prefix = default_log_prefix
14
- @retry_options = retry_config || default_retry_config
15
11
  @sql_retry = Lhm::SqlRetry.new(
16
12
  connection,
17
- options: retry_config,
13
+ retry_options: options[:retriable] || {},
18
14
  reconnect_with_consistent_host: options[:reconnect_with_consistent_host] || false
19
15
  )
20
16
 
@@ -22,7 +18,20 @@ module Lhm
22
18
  super(connection)
23
19
  end
24
20
 
25
- def options=(options)
21
+ def ar_connection
22
+ # Get object from the simple delegator
23
+ __getobj__
24
+ end
25
+
26
+ def ar_connection=(connection)
27
+ raise Lhm::Error.new("Lhm::Connection requires an active record connection to operate") if connection.nil?
28
+
29
+ @sql_retry.connection = connection
30
+ # Sets connection as the delegated object
31
+ __setobj__(connection)
32
+ end
33
+
34
+ def process_connection_options(options)
26
35
  # If any other flags are added. Add the "processing" here
27
36
  @sql_retry.reconnect_with_consistent_host = options[:reconnect_with_consistent_host] || false
28
37
  end
@@ -70,7 +79,7 @@ module Lhm
70
79
  private
71
80
 
72
81
  def exec(method, sql)
73
- connection.public_send(method, Lhm::ProxySQLHelper.tagged(sql))
82
+ ar_connection.public_send(method, Lhm::ProxySQLHelper.tagged(sql))
74
83
  end
75
84
 
76
85
  def exec_with_retries(method, sql, retry_options = {})
data/lib/lhm/sql_retry.rb CHANGED
@@ -28,10 +28,10 @@ module Lhm
28
28
  # This internal error is used to trigger retries from the parent Retriable.retriable in #with_retries
29
29
  class ReconnectToHostSuccessful < Lhm::Error; end
30
30
 
31
- def initialize(connection, options: {}, reconnect_with_consistent_host: true)
31
+ def initialize(connection, retry_options: {}, reconnect_with_consistent_host: false)
32
32
  @connection = connection
33
- @log_prefix = options.delete(:log_prefix)
34
- @global_retry_config = default_retry_config.dup.merge!(options)
33
+ @log_prefix = retry_options.delete(:log_prefix)
34
+ @global_retry_config = default_retry_config.dup.merge!(retry_options)
35
35
  if (@reconnect_with_consistent_host = reconnect_with_consistent_host)
36
36
  @initial_hostname = hostname
37
37
  @initial_server_id = server_id
@@ -63,7 +63,7 @@ module Lhm
63
63
  end
64
64
 
65
65
  attr_reader :global_retry_config
66
- attr_accessor :reconnect_with_consistent_host
66
+ attr_accessor :connection, :reconnect_with_consistent_host
67
67
 
68
68
  private
69
69
 
data/lib/lhm/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Schmidt
3
3
 
4
4
  module Lhm
5
- VERSION = '3.5.1'
5
+ VERSION = '3.5.2'
6
6
  end
data/lib/lhm.rb CHANGED
@@ -28,7 +28,7 @@ module Lhm
28
28
  extend Throttler
29
29
  extend self
30
30
 
31
- DEFAULT_LOGGER_OPTIONS = { level: Logger::INFO, file: STDOUT }
31
+ DEFAULT_LOGGER_OPTIONS = { level: Logger::INFO, file: STDOUT }
32
32
 
33
33
  # Alters a table with the changes described in the block
34
34
  #
@@ -99,12 +99,13 @@ module Lhm
99
99
  # @option connection_options [Boolean] :reconnect_with_consistent_host
100
100
  # Active / Deactivate ProxySQL-aware reconnection procedure (default to: false)
101
101
  def connection(connection_options = nil)
102
- if @@connection.nil?
102
+ @@connection ||= begin
103
103
  raise 'Please call Lhm.setup' unless defined?(ActiveRecord)
104
104
  @@connection = Connection.new(connection: ActiveRecord::Base.connection, options: connection_options || {})
105
- else
106
- @@connection.options = connection_options unless connection_options.nil?
107
105
  end
106
+
107
+ @@connection.process_connection_options(connection_options) unless connection_options.nil?
108
+
108
109
  @@connection
109
110
  end
110
111
 
@@ -55,7 +55,7 @@ describe Lhm::SqlRetry do
55
55
  it "successfully executes the SQL despite the errors encountered" do
56
56
  # Start a thread to retry, once the lock is held, execute the block
57
57
  @helper.with_waiting_lock do |waiting_connection|
58
- sql_retry = Lhm::SqlRetry.new(waiting_connection, options: {
58
+ sql_retry = Lhm::SqlRetry.new(waiting_connection, retry_options: {
59
59
  base_interval: 0.2, # first retry after 200ms
60
60
  multiplier: 1, # subsequent retries wait 1x longer than first retry (no change)
61
61
  tries: 3, # we only need 3 tries (including the first) for the scenario described below
@@ -98,7 +98,7 @@ describe Lhm::SqlRetry do
98
98
  puts "*" * 64
99
99
  # Start a thread to retry, once the lock is held, execute the block
100
100
  @helper.with_waiting_lock do |waiting_connection|
101
- sql_retry = Lhm::SqlRetry.new(waiting_connection, options: {
101
+ sql_retry = Lhm::SqlRetry.new(waiting_connection, retry_options: {
102
102
  base_interval: 0.2, # first retry after 200ms
103
103
  multiplier: 1, # subsequent retries wait 1x longer than first retry (no change)
104
104
  tries: 2, # we need 3 tries (including the first) for the scenario described below, but we only get two...we will fail
@@ -18,7 +18,7 @@ describe Lhm::SqlRetry, "ProxiSQL tests for LHM retry" do
18
18
 
19
19
  @connection = DBConnectionHelper::new_mysql_connection(:proxysql, true, true)
20
20
 
21
- @lhm_retry = Lhm::SqlRetry.new(@connection, options: {},
21
+ @lhm_retry = Lhm::SqlRetry.new(@connection, retry_options: {},
22
22
  reconnect_with_consistent_host: true)
23
23
  end
24
24
 
@@ -63,7 +63,7 @@ describe Lhm::SqlRetry, "ProxiSQL tests for LHM retry" do
63
63
  Lhm::SqlRetry.any_instance.stubs(:hostname).returns("mysql-1").then.returns("mysql-2")
64
64
 
65
65
  # Need new instance for stub to take into effect
66
- lhm_retry = Lhm::SqlRetry.new(@connection, options: {},
66
+ lhm_retry = Lhm::SqlRetry.new(@connection, retry_options: {},
67
67
  reconnect_with_consistent_host: true)
68
68
 
69
69
  e = assert_raises Lhm::Error do
@@ -26,4 +26,21 @@ describe Lhm do
26
26
  value(Lhm.logger.instance_eval { @logdev }.dev.path).must_equal 'omg.ponies'
27
27
  end
28
28
  end
29
+
30
+ describe 'api' do
31
+
32
+ before(:each) do
33
+ @connection = mock()
34
+ end
35
+
36
+ it 'should create a new connection when calling setup' do
37
+ Lhm.setup(@connection)
38
+ value(Lhm.connection).must_be_kind_of(Lhm::Connection)
39
+ end
40
+
41
+ it 'should create a new connection when none is created' do
42
+ ActiveRecord::Base.stubs(:connection).returns(@connection)
43
+ value(Lhm.connection).must_be_kind_of(Lhm::Connection)
44
+ end
45
+ end
29
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhm-shopify
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.1
4
+ version: 3.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - SoundCloud
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-12-06 00:00:00.000000000 Z
15
+ date: 2021-12-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: retriable