sequel-schema-sharding 0.10.0 → 0.11.0
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/lib/sequel/schema-sharding/connection_manager.rb +6 -2
- data/lib/sequel/schema-sharding/dtrace_provider.rb +8 -0
- data/lib/sequel/schema-sharding/model.rb +1 -0
- data/lib/sequel/schema-sharding/version.rb +1 -1
- data/spec/schema-sharding/dtrace_provider_spec.rb +36 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6650670d2e7f69baf78e74a8078fb54199874b0
|
4
|
+
data.tar.gz: 397407436c70d317b8c18cdbf17e297225885045
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9b175af8ac8e3ae327b66510f9ed6022ca1f978284770dd223a4f51937486e08dae239acb6075416a6f627bb67e6d0ac8593f04ef38188b11c10c90c5bc698b
|
7
|
+
data.tar.gz: 7064d7b970634745107c39eceda413d84b4df64afad13e1c4419302b792deec5848140050ebca22bedf9c06de1f7749c7542b4991b48b0a75e11f9ecf67654ac
|
@@ -76,11 +76,15 @@ module Sequel
|
|
76
76
|
|
77
77
|
def replica_hash_for(config)
|
78
78
|
return {} if config['replicas'].nil?
|
79
|
-
|
79
|
+
size = config['replicas'].size
|
80
|
+
i = rand(size)
|
80
81
|
{
|
81
82
|
:servers => {
|
82
83
|
:read_only => ->(db) do
|
83
|
-
|
84
|
+
choice = i % size
|
85
|
+
probe = Sequel::SchemaSharding::DTraceProvider.provider.replica_hash_for
|
86
|
+
probe.fire(choice, size) if probe.enabled?
|
87
|
+
sequel_connection_config_for(config['replicas'][choice]).tap do
|
84
88
|
i += 1
|
85
89
|
end
|
86
90
|
end
|
@@ -13,6 +13,14 @@ module Sequel
|
|
13
13
|
@read_only_probe ||= provider.probe(:model, :read_only_shard_for, :string)
|
14
14
|
end
|
15
15
|
|
16
|
+
def replica_hash_for
|
17
|
+
@replica_hash_for ||= provider.probe(:connection_manager, :replica_hash_for, :integer, :integer)
|
18
|
+
end
|
19
|
+
|
20
|
+
def shard_for
|
21
|
+
@shard_for_probe ||= provider.probe(:model, :shard_for, :string)
|
22
|
+
end
|
23
|
+
|
16
24
|
def self.provider
|
17
25
|
@provider ||= new.tap do |p|
|
18
26
|
p.read_only_shard_for
|
@@ -48,6 +48,7 @@ module Sequel
|
|
48
48
|
# Return a valid Sequel::Dataset that is tied to the shard table and connection for the id and will load values
|
49
49
|
# run by the query into the model.
|
50
50
|
def shard_for(id)
|
51
|
+
Sequel::SchemaSharding::DTraceProvider.provider.shard_for.fire(id.to_s) if Sequel::SchemaSharding::DTraceProvider.provider.shard_for.enabled?
|
51
52
|
result = self.result_for(id)
|
52
53
|
ds = result.connection[schema_and_table(result)]
|
53
54
|
ds.row_proc = self
|
@@ -11,6 +11,24 @@ describe Sequel::SchemaSharding::DTraceProvider do
|
|
11
11
|
describe 'probes' do
|
12
12
|
let(:provider) { Sequel::SchemaSharding::DTraceProvider.new }
|
13
13
|
|
14
|
+
describe '#replica_hash_for' do
|
15
|
+
it 'is a probe' do
|
16
|
+
expect(provider.replica_hash_for).to be_a USDT::Probe
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has :model for its function' do
|
20
|
+
expect(provider.replica_hash_for.function).to eq(:connection_manager)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has :read_only_shard_for for its name' do
|
24
|
+
expect(provider.replica_hash_for.name).to eq(:replica_hash_for)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'takes a string argument' do
|
28
|
+
expect(provider.replica_hash_for.arguments).to eq([:integer, :integer])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
14
32
|
describe '#read_only_shard_for' do
|
15
33
|
it 'is a probe' do
|
16
34
|
expect(provider.read_only_shard_for).to be_a USDT::Probe
|
@@ -28,6 +46,24 @@ describe Sequel::SchemaSharding::DTraceProvider do
|
|
28
46
|
expect(provider.read_only_shard_for.arguments).to eq([:string])
|
29
47
|
end
|
30
48
|
end
|
49
|
+
|
50
|
+
describe '#shard_for' do
|
51
|
+
it 'is a probe' do
|
52
|
+
expect(provider.shard_for).to be_a USDT::Probe
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'has :model for its function' do
|
56
|
+
expect(provider.shard_for.function).to eq(:model)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'has :read_only_shard_for for its name' do
|
60
|
+
expect(provider.shard_for.name).to eq(:shard_for)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'takes a string argument' do
|
64
|
+
expect(provider.read_only_shard_for.arguments).to eq([:string])
|
65
|
+
end
|
66
|
+
end
|
31
67
|
end
|
32
68
|
|
33
69
|
describe '::provider' do
|