fluent-plugin-mysql-replicator 0.1.0 → 0.1.1
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.
data/README.md
CHANGED
@@ -94,6 +94,7 @@ CREATE TABLE `hash_tables` (
|
|
94
94
|
|
95
95
|
CREATE TABLE `settings` (
|
96
96
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
97
|
+
`is_active` int(11) NOT NULL DEFAULT '1',
|
97
98
|
`name` varchar(255) NOT NULL,
|
98
99
|
`host` varchar(255) NOT NULL DEFAULT 'localhost',
|
99
100
|
`port` int(11) NOT NULL DEFAULT '3306',
|
@@ -102,7 +103,6 @@ CREATE TABLE `settings` (
|
|
102
103
|
`database` varchar(255) NOT NULL,
|
103
104
|
`query` TEXT NOT NULL,
|
104
105
|
`interval` int(11) NOT NULL,
|
105
|
-
`tag` varchar(255) NOT NULL,
|
106
106
|
`primary_key` varchar(11) DEFAULT 'id',
|
107
107
|
`enable_delete` int(11) DEFAULT '1',
|
108
108
|
PRIMARY KEY (`id`),
|
@@ -121,19 +121,30 @@ mysql> insert into source ...snip...;
|
|
121
121
|
`````
|
122
122
|
<source>
|
123
123
|
type mysql_replicator_multi
|
124
|
+
|
125
|
+
# Database connection setting for manager table.
|
124
126
|
manager_host localhost
|
125
127
|
manager_username your_mysql_user
|
126
128
|
manager_password your_mysql_password
|
127
129
|
manager_database replicator_manager
|
130
|
+
|
131
|
+
# Format output tag for each events. Placeholders usage as described below.
|
132
|
+
tag replicator.${name}.${event}.${primary_key}
|
133
|
+
# ${name} : the value of `replicator_manager.settings.name` in manager table.
|
134
|
+
# ${event} : the variation of row event type by insert/update/delete.
|
135
|
+
# ${primary_key} : the value of `replicator_manager.settings.primary_key` in manager table.
|
128
136
|
</source>
|
129
137
|
|
130
|
-
<match replicator
|
138
|
+
<match replicator.**>
|
131
139
|
type stdout
|
132
140
|
</match>
|
133
141
|
`````
|
134
142
|
|
135
143
|
## TODO
|
136
144
|
|
145
|
+
* support string type primary_key.
|
146
|
+
* support reload setting on demand.
|
147
|
+
|
137
148
|
Pull requests are very welcome!!
|
138
149
|
|
139
150
|
## Copyright
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = "fluent-plugin-mysql-replicator"
|
4
|
-
s.version = "0.1.
|
4
|
+
s.version = "0.1.1"
|
5
5
|
s.authors = ["Kentaro Yoshida"]
|
6
6
|
s.email = ["y.ken.studio@gmail.com"]
|
7
7
|
s.homepage = "https://github.com/y-ken/fluent-plugin-mysql-replicator"
|
8
|
-
s.summary = %q{Fluentd input plugin to track insert/update/delete event from MySQL databases. It
|
8
|
+
s.summary = %q{Fluentd input plugin to track insert/update/delete event from MySQL databases. It's comming support multiple table replication to another RDB/noSQL like Elasticsearch.}
|
9
9
|
|
10
10
|
s.files = `git ls-files`.split("\n")
|
11
11
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -52,6 +52,7 @@ module Fluent
|
|
52
52
|
query(@query).each do |row|
|
53
53
|
current_ids << row[@primary_key]
|
54
54
|
current_hash = Digest::SHA1.hexdigest(row.flatten.join)
|
55
|
+
row.each {|k, v| row[k] = v.to_s if v.is_a? Time}
|
55
56
|
if !table_hash.include?(row[@primary_key])
|
56
57
|
emit_record(:insert, row)
|
57
58
|
elsif table_hash[row[@primary_key]] != current_hash
|
@@ -13,10 +13,14 @@ module Fluent
|
|
13
13
|
config_param :manager_username, :string, :default => nil
|
14
14
|
config_param :manager_password, :string, :default => ''
|
15
15
|
config_param :manager_database, :string, :default => 'replicator_manager'
|
16
|
+
config_param :tag, :string, :default => nil
|
16
17
|
|
17
18
|
def configure(conf)
|
18
19
|
super
|
19
20
|
@reconnect_interval = Config.time_value('10sec')
|
21
|
+
if @tag.nil?
|
22
|
+
raise Fluent::ConfigError, "mysql_replicator_multi: missing 'tag' parameter. Please add following line into config like 'tag replicator.${name}.${event}.${primary_key}'"
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def start
|
@@ -44,7 +48,7 @@ module Fluent
|
|
44
48
|
def get_settings
|
45
49
|
manager_db = get_manager_connection
|
46
50
|
settings = []
|
47
|
-
query = "SELECT * FROM settings"
|
51
|
+
query = "SELECT * FROM settings WHERE is_active = 1;"
|
48
52
|
manager_db.query(query).each do |row|
|
49
53
|
settings << row
|
50
54
|
end
|
@@ -64,6 +68,7 @@ module Fluent
|
|
64
68
|
db = get_origin_connection(config)
|
65
69
|
db.query(config['query']).each do |row|
|
66
70
|
@mutex.lock
|
71
|
+
row.each {|k, v| row[k] = v.to_s if v.is_a? Time}
|
67
72
|
current_id = row[primary_key]
|
68
73
|
detect_insert_update(config, row)
|
69
74
|
detect_delete(config, current_id, previous_id)
|
@@ -92,7 +97,8 @@ module Fluent
|
|
92
97
|
event = :update
|
93
98
|
end
|
94
99
|
unless event.nil?
|
95
|
-
|
100
|
+
tag = format_tag(@tag, {:name => config['name'], :event => event, :primary_key => config['primary_key']})
|
101
|
+
emit_record(tag, row)
|
96
102
|
update_hashtable({:event => event, :ids => current_id, :setting_name => config['name'], :hash => current_hash})
|
97
103
|
end
|
98
104
|
end
|
@@ -110,7 +116,8 @@ module Fluent
|
|
110
116
|
unless deleted_ids.empty?
|
111
117
|
event = :delete
|
112
118
|
deleted_ids.each do |id|
|
113
|
-
|
119
|
+
tag = format_tag(@tag, {:name => config['name'], :event => event, :primary_key => config['primary_key']})
|
120
|
+
emit_record(tag, {config['primary_key'] => id})
|
114
121
|
end
|
115
122
|
update_hashtable({:event => event, :ids => deleted_ids, :setting_name => config['name']})
|
116
123
|
end
|
@@ -154,6 +161,14 @@ module Fluent
|
|
154
161
|
end
|
155
162
|
end
|
156
163
|
|
164
|
+
def format_tag(tag, param)
|
165
|
+
pattern = {'${name}' => param[:name], '${event}' => param[:event].to_s, '${primary_key}' => param[:primary_key]}
|
166
|
+
tag.gsub(/\${[a-z_]+(\[[0-9]+\])?}/, pattern) do
|
167
|
+
$log.warn "mysql_replicator_multi: missing placeholder. tag:#{tag} placeholder:#{$1}" unless pattern.include?($1)
|
168
|
+
pattern[$1]
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
157
172
|
def emit_record(tag, record)
|
158
173
|
Engine.emit(tag, Engine.now, record)
|
159
174
|
end
|
@@ -12,6 +12,7 @@ CREATE TABLE `hash_tables` (
|
|
12
12
|
|
13
13
|
CREATE TABLE `settings` (
|
14
14
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
15
|
+
`is_active` int(11) NOT NULL DEFAULT '1',
|
15
16
|
`name` varchar(255) NOT NULL,
|
16
17
|
`host` varchar(255) NOT NULL DEFAULT 'localhost',
|
17
18
|
`port` int(11) NOT NULL DEFAULT '3306',
|
@@ -20,7 +21,6 @@ CREATE TABLE `settings` (
|
|
20
21
|
`database` varchar(255) NOT NULL,
|
21
22
|
`query` TEXT NOT NULL,
|
22
23
|
`interval` int(11) NOT NULL,
|
23
|
-
`tag` varchar(255) NOT NULL,
|
24
24
|
`primary_key` varchar(11) DEFAULT 'id',
|
25
25
|
`enable_delete` int(11) DEFAULT '1',
|
26
26
|
PRIMARY KEY (`id`),
|
@@ -10,6 +10,7 @@ class MysqlReplicatorMultiInputTest < Test::Unit::TestCase
|
|
10
10
|
manager_port 3306
|
11
11
|
manager_username foo
|
12
12
|
manager_password bar
|
13
|
+
tag replicator.${name}.${event}.${primary_key}
|
13
14
|
]
|
14
15
|
|
15
16
|
def create_driver(conf=CONFIG,tag='test')
|
@@ -17,6 +18,9 @@ class MysqlReplicatorMultiInputTest < Test::Unit::TestCase
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_configure
|
21
|
+
assert_raise(Fluent::ConfigError) {
|
22
|
+
d = create_driver('')
|
23
|
+
}
|
20
24
|
d = create_driver(CONFIG)
|
21
25
|
d.instance.inspect
|
22
26
|
assert_equal 'localhost', d.instance.manager_host
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mysql-replicator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -103,7 +103,7 @@ rubygems_version: 1.8.23
|
|
103
103
|
signing_key:
|
104
104
|
specification_version: 3
|
105
105
|
summary: Fluentd input plugin to track insert/update/delete event from MySQL databases.
|
106
|
-
It
|
106
|
+
It's comming support multiple table replication to another RDB/noSQL like Elasticsearch.
|
107
107
|
test_files:
|
108
108
|
- test/helper.rb
|
109
109
|
- test/plugin/test_in_mysql_replicator.rb
|