proxysqlweightlifter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/proxysqlweightlifter.rb +5 -4
- data/lib/proxysqlweightlifter/lift.rb +16 -4
- data/lib/proxysqlweightlifter/version.rb +1 -1
- 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: d20c202dbb5e6fd963e4d5b58f52a4ac7766bfcd43009e79cbf8b10b0dc7272e
|
4
|
+
data.tar.gz: bb9faa6666c5babf550175365aae062fd11d9e5853596039cdd4a2fd7354a300
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f05d6b3a374739a7aa845f1c5b7ce778fb1dc8dd3e125b6a7e79d79133a83328c211002b844f5213a73127e9ac76e4a6f21c319348df4e694bd97836201a47e0
|
7
|
+
data.tar.gz: e762f7d8f221ce83d08215f391952dc494489ea1fad5136d78033b793bd012ab2cfd7dd965d88c84b5b9eb225d266b84a27d07a2b6e357aa51c881984e43f246
|
data/lib/proxysqlweightlifter.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'mysql2'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'proxysqlweightlifter/version'
|
3
|
+
require 'proxysqlweightlifter/lift'
|
4
4
|
|
5
5
|
module Proxysqlweightlifter
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
8
|
def self.run(argv)
|
9
|
-
host, port, user, pass, weight = argv
|
9
|
+
host, port, user, pass, weight, custom_weight = argv
|
10
10
|
Lift.new(
|
11
11
|
Mysql2::Client.new(
|
12
12
|
host: host,
|
@@ -15,7 +15,8 @@ module Proxysqlweightlifter
|
|
15
15
|
password: pass,
|
16
16
|
database: 'main'
|
17
17
|
),
|
18
|
-
weight || 9
|
18
|
+
weight || 9,
|
19
|
+
custom_weight
|
19
20
|
).run
|
20
21
|
end
|
21
22
|
end
|
@@ -2,11 +2,12 @@ module Proxysqlweightlifter
|
|
2
2
|
# Lift is responsible for resolving current slaves from
|
3
3
|
# mysql_replication_hostgroups table
|
4
4
|
class Lift
|
5
|
-
attr_reader :db, :
|
5
|
+
attr_reader :db, :default_weight
|
6
6
|
|
7
|
-
def initialize(database,
|
7
|
+
def initialize(database, default_weight = 10, custom_weight = '')
|
8
8
|
@db = database
|
9
|
-
@
|
9
|
+
@default_weight = default_weight
|
10
|
+
@custom_weight = custom_weight.to_s
|
10
11
|
end
|
11
12
|
|
12
13
|
def run
|
@@ -30,6 +31,16 @@ module Proxysqlweightlifter
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
def hostgroup_weights
|
35
|
+
@hostgroup_weights ||= @custom_weight.split(',').map do |cs|
|
36
|
+
hostgroup_id, group_id, weight = cs.split(':')
|
37
|
+
raise 'Invalid or unsupported format: hostgroup_id:9100:70' if hostgroup_id != 'hostgroup_id'
|
38
|
+
{
|
39
|
+
group_id.to_i => weight.to_i
|
40
|
+
}
|
41
|
+
end.reduce(&:merge) || {}
|
42
|
+
end
|
43
|
+
|
33
44
|
def hostgroups
|
34
45
|
db.query(%(
|
35
46
|
SELECT writer_hostgroup,reader_hostgroup
|
@@ -69,9 +80,10 @@ module Proxysqlweightlifter
|
|
69
80
|
end
|
70
81
|
|
71
82
|
def update_weight(hostname:, port:, hostgroup_id:)
|
83
|
+
weight = hostgroup_weights[hostgroup_id] || default_weight || 1
|
72
84
|
db.query(%(
|
73
85
|
UPDATE mysql_servers
|
74
|
-
SET weight = #{weight
|
86
|
+
SET weight = #{weight}
|
75
87
|
WHERE hostname = "#{hostname}" AND port = "#{port}" AND hostgroup_id = "#{hostgroup_id}";
|
76
88
|
))
|
77
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxysqlweightlifter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernestas Poskus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|