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 +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +0 -1
- data/gemfiles/activerecord_5.2.gemfile.lock +1 -1
- data/gemfiles/activerecord_6.0.gemfile.lock +1 -1
- data/gemfiles/activerecord_6.1.gemfile.lock +1 -1
- data/gemfiles/activerecord_7.0.0.alpha2.gemfile.lock +1 -1
- data/lib/lhm/chunk_insert.rb +2 -2
- data/lib/lhm/chunker.rb +1 -1
- data/lib/lhm/connection.rb +18 -9
- data/lib/lhm/sql_retry.rb +4 -4
- data/lib/lhm/version.rb +1 -1
- data/lib/lhm.rb +5 -4
- data/spec/integration/sql_retry/lock_wait_spec.rb +2 -2
- data/spec/integration/sql_retry/retry_with_proxysql_spec.rb +2 -2
- data/spec/unit/lhm_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ad526041b49fe42d906fc27a697c3d0982332a7f256f40c179071e954a33d37
|
4
|
+
data.tar.gz: 35647043caa59111fd09770a38f160e959baa2022d73d82e1061777423fdc6bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/Rakefile
CHANGED
data/lib/lhm/chunk_insert.rb
CHANGED
@@ -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,
|
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 =
|
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
data/lib/lhm/connection.rb
CHANGED
@@ -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
|
-
|
10
|
-
alias connection= __setobj__
|
7
|
+
class Connection < SimpleDelegator
|
11
8
|
|
12
|
-
def initialize(connection:, default_log_prefix: nil, options: {}
|
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:
|
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
|
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
|
-
|
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,
|
31
|
+
def initialize(connection, retry_options: {}, reconnect_with_consistent_host: false)
|
32
32
|
@connection = connection
|
33
|
-
@log_prefix =
|
34
|
-
@global_retry_config = default_retry_config.dup.merge!(
|
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
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 =
|
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
|
-
|
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,
|
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,
|
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,
|
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,
|
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
|
data/spec/unit/lhm_spec.rb
CHANGED
@@ -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.
|
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-
|
15
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: retriable
|