switchman 2.0.8 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/switchman/shard.rb +1 -0
- data/db/migrate/20180828183945_add_default_shard_index.rb +1 -1
- data/lib/switchman/active_record/connection_handler.rb +1 -1
- data/lib/switchman/active_record/migration.rb +33 -1
- data/lib/switchman/connection_pool_proxy.rb +4 -0
- data/lib/switchman/schema_cache.rb +9 -1
- data/lib/switchman/test_helper.rb +1 -1
- data/lib/switchman/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af9f8893be986771668662ceca8d3e36e28f5babf889a18e1e3efc237f7eae66
|
4
|
+
data.tar.gz: 675bd5b18076e8da86feb8a6e6271fffc1cd27939dedc1eb51c61bf165122b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aadb4a342920dfe24e6110546380aa83a9aa4f61722e8c4c7265d0bf4494a2e8e04975d00504f7a26f143b87595bdb8c47ea09b4f9344f4925af08055c9d23e5
|
7
|
+
data.tar.gz: 295a3b4490f511380dcaeb44a6a6985cdf97745e678054eaf46315fc89d3adafd7a84a7a3665ec4521a6baa3b9f787adfccdc6d814baab10999c148b75041773
|
@@ -135,7 +135,7 @@ module Switchman
|
|
135
135
|
primary_pool = retrieve_connection_pool("primary")
|
136
136
|
if primary_pool.is_a?(ConnectionPoolProxy)
|
137
137
|
pool = ConnectionPoolProxy.new(spec_name.to_sym, primary_pool.default_pool, @shard_connection_pools)
|
138
|
-
pool.schema_cache.
|
138
|
+
pool.schema_cache.copy_references(primary_pool.schema_cache)
|
139
139
|
pool
|
140
140
|
else
|
141
141
|
primary_pool
|
@@ -30,10 +30,42 @@ module Switchman
|
|
30
30
|
end
|
31
31
|
|
32
32
|
module Migrator
|
33
|
+
# significant change: hash shard id, not database name
|
33
34
|
def generate_migrator_advisory_lock_id
|
34
|
-
shard_name_hash = Zlib.crc32(
|
35
|
+
shard_name_hash = Zlib.crc32(Shard.current.name)
|
35
36
|
::ActiveRecord::Migrator::MIGRATOR_SALT * shard_name_hash
|
36
37
|
end
|
38
|
+
|
39
|
+
if ::Rails.version >= '6.0'
|
40
|
+
# copy/paste from Rails 6.1
|
41
|
+
def with_advisory_lock
|
42
|
+
lock_id = generate_migrator_advisory_lock_id
|
43
|
+
|
44
|
+
with_advisory_lock_connection do |connection|
|
45
|
+
got_lock = connection.get_advisory_lock(lock_id)
|
46
|
+
raise ::ActiveRecord::ConcurrentMigrationError unless got_lock
|
47
|
+
load_migrated # reload schema_migrations to be sure it wasn't changed by another process before we got the lock
|
48
|
+
yield
|
49
|
+
ensure
|
50
|
+
if got_lock && !connection.release_advisory_lock(lock_id)
|
51
|
+
raise ::ActiveRecord::ConcurrentMigrationError.new(
|
52
|
+
::ActiveRecord::ConcurrentMigrationError::RELEASE_LOCK_FAILED_MESSAGE
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# significant change: strip out prefer_secondary from config
|
59
|
+
def with_advisory_lock_connection
|
60
|
+
pool = ::ActiveRecord::ConnectionAdapters::ConnectionHandler.new.establish_connection(
|
61
|
+
::ActiveRecord::Base.connection_config.except(:prefer_secondary)
|
62
|
+
)
|
63
|
+
|
64
|
+
pool.with_connection { |connection| yield(connection) }
|
65
|
+
ensure
|
66
|
+
pool&.disconnect!
|
67
|
+
end
|
68
|
+
end
|
37
69
|
end
|
38
70
|
|
39
71
|
module MigrationContext
|
@@ -5,14 +5,22 @@ module Switchman
|
|
5
5
|
delegate :connection, to: :pool
|
6
6
|
attr_reader :pool
|
7
7
|
|
8
|
+
SHARED_IVS = %i{@columns @columns_hash @primary_keys @data_sources @indexes}.freeze
|
9
|
+
|
8
10
|
def initialize(pool)
|
9
11
|
@pool = pool
|
10
12
|
super(nil)
|
11
13
|
end
|
12
14
|
|
13
15
|
def copy_values(other_cache)
|
16
|
+
SHARED_IVS.each do |iv|
|
17
|
+
instance_variable_get(iv).replace(other_cache.instance_variable_get(iv))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_references(other_cache)
|
14
22
|
# use the same cached values but still fall back to the correct pool
|
15
|
-
|
23
|
+
SHARED_IVS.each do |iv|
|
16
24
|
instance_variable_set(iv, other_cache.instance_variable_get(iv))
|
17
25
|
end
|
18
26
|
end
|
@@ -24,7 +24,7 @@ module Switchman
|
|
24
24
|
else
|
25
25
|
server1 = Shard.default.database_server
|
26
26
|
end
|
27
|
-
server2 = DatabaseServer.create(Shard.default.database_server.config)
|
27
|
+
server2 = DatabaseServer.create(Shard.default.database_server.config.merge(server2: true))
|
28
28
|
|
29
29
|
if server1 == Shard.default.database_server && server1.config[:shard1] && server1.config[:shard2]
|
30
30
|
# look for the shards in the db already
|
data/lib/switchman/version.rb
CHANGED
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.
|
4
|
+
version: 2.0.9
|
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: 2021-04-
|
13
|
+
date: 2021-04-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -257,7 +257,7 @@ homepage: http://www.instructure.com/
|
|
257
257
|
licenses:
|
258
258
|
- MIT
|
259
259
|
metadata: {}
|
260
|
-
post_install_message:
|
260
|
+
post_install_message:
|
261
261
|
rdoc_options: []
|
262
262
|
require_paths:
|
263
263
|
- lib
|
@@ -272,8 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
272
|
- !ruby/object:Gem::Version
|
273
273
|
version: '0'
|
274
274
|
requirements: []
|
275
|
-
rubygems_version: 3.
|
276
|
-
signing_key:
|
275
|
+
rubygems_version: 3.2.15
|
276
|
+
signing_key:
|
277
277
|
specification_version: 4
|
278
278
|
summary: Rails sharding magic
|
279
279
|
test_files: []
|