sequel-schema-sharding 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -0
- data/lib/sequel/schema-sharding/configuration.rb +9 -1
- data/lib/sequel/schema-sharding/connection_manager.rb +1 -1
- data/lib/sequel/schema-sharding/version.rb +1 -1
- data/spec/fixtures/test_db_config.yml +6 -2
- data/spec/schema-sharding/configuration_spec.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2dce85ba1914970e81126721a1bfd51d6b9208d
|
4
|
+
data.tar.gz: 0376b7682b6ae4b35a91146bab97332eb208962e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f799c6bd555910a534954d137aac874f94ba9b57315c988066b696a09c381b6b81db75cfb6965d040e9a2ad26ccdd04f0bb1b562a5acfe7245658a315b1d19b2
|
7
|
+
data.tar.gz: a7cf6e434056d0cd54d693f9ffb09668e3e5bddebbe42fce825f5c36830ce0323173fdf6c8b039da16703f31f1df19478be2aa696be567c18cd183f81b7919ca
|
data/README.md
CHANGED
@@ -91,6 +91,44 @@ See Sequel documentation for more info:
|
|
91
91
|
|
92
92
|
TODO: rake tasks for running migrations
|
93
93
|
|
94
|
+
### Read/write splitting
|
95
|
+
|
96
|
+
Sequel supports read/write splitting, but sequel-schema-sharding needs a
|
97
|
+
few modifications in order to work with horizontal sharding. In order to
|
98
|
+
use read/write splitting across shards, the following configuration can
|
99
|
+
be used in your `sharding.yml`:
|
100
|
+
|
101
|
+
```yml
|
102
|
+
<env>:
|
103
|
+
tables:
|
104
|
+
<table_name>:
|
105
|
+
schema_name: "schema_%04d"
|
106
|
+
logical_shards:
|
107
|
+
<shard_name>: <1..n>
|
108
|
+
<shard_name>:<n+1..m>
|
109
|
+
physical_shards:
|
110
|
+
<shard_name>:
|
111
|
+
host: <hostname>
|
112
|
+
database: <database>
|
113
|
+
replicas:
|
114
|
+
<replica_name>:
|
115
|
+
host: <hostname>
|
116
|
+
database: <database>
|
117
|
+
...
|
118
|
+
common:
|
119
|
+
username: <pg_username>
|
120
|
+
password: <pg_password>
|
121
|
+
port: <pg_port>
|
122
|
+
```
|
123
|
+
|
124
|
+
Replica configuration is merged into common attributes, so are redundant
|
125
|
+
if they are not different from the master. Replica attributes take priority,
|
126
|
+
however, so if you use a proxy such as PGBouncer, you can specify a different
|
127
|
+
local database name.
|
128
|
+
|
129
|
+
See http://sequel.rubyforge.org/rdoc/files/doc/sharding_rdoc.html for more
|
130
|
+
information.
|
131
|
+
|
94
132
|
### Models
|
95
133
|
|
96
134
|
Models declare their table in the class definition. This allows Sequel
|
@@ -12,7 +12,15 @@ module Sequel
|
|
12
12
|
|
13
13
|
def physical_shard_configs
|
14
14
|
@physical_shard_configs ||= config['physical_shards'].inject({}) do |hash, value|
|
15
|
-
|
15
|
+
shard_config = config['common'].merge(value[1])
|
16
|
+
|
17
|
+
if shard_config['replicas']
|
18
|
+
shard_config['replicas'] = shard_config['replicas'].map do |name, replica|
|
19
|
+
config['common'].merge(replica)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
hash[value[0]] = shard_config
|
16
24
|
hash
|
17
25
|
end
|
18
26
|
end
|
@@ -20,7 +20,9 @@ test:
|
|
20
20
|
host: 127.0.0.1
|
21
21
|
database: sequel_test_shard2
|
22
22
|
replicas:
|
23
|
-
|
23
|
+
replica_1:
|
24
|
+
host: 127.0.0.1
|
25
|
+
database: sequel_test_shard2
|
24
26
|
common:
|
25
27
|
username: postgres
|
26
28
|
password: boomboomkaboom
|
@@ -46,7 +48,9 @@ boom:
|
|
46
48
|
host: 127.0.0.1
|
47
49
|
database: sequel_boom_shard2
|
48
50
|
replicas:
|
49
|
-
|
51
|
+
replica_1:
|
52
|
+
host: 127.0.0.1
|
53
|
+
database: sequel_boom_shard2
|
50
54
|
common:
|
51
55
|
username: postgres
|
52
56
|
password: boomboomkaboom
|
@@ -43,7 +43,11 @@ describe Sequel::SchemaSharding::Configuration do
|
|
43
43
|
expect(value['username']).to eq('postgres')
|
44
44
|
expect(value['password']).to eq('boomboomkaboom')
|
45
45
|
expect(value['port']).to eq(5432)
|
46
|
-
expect(value['replicas']).to eq(['127.0.0.1'
|
46
|
+
expect(value['replicas']).to eq([{'host' => '127.0.0.1',
|
47
|
+
'database' => 'sequel_boom_shard2',
|
48
|
+
'port' => 5432,
|
49
|
+
'username' => 'postgres',
|
50
|
+
'password' => 'boomboomkaboom'}]) if key == 'shard2'
|
47
51
|
|
48
52
|
i += 1
|
49
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-schema-sharding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Henry
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-10-
|
13
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sequel
|