fluent-plugin-mysql-replicator 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,7 +20,7 @@ gem install fluent-plugin-mysql-replicator
20
20
 
21
21
  It is useful for these purpose.
22
22
 
23
- * try it on this plugin.
23
+ * try it on this plugin quickly.
24
24
  * replicate small record under a millons table.
25
25
 
26
26
  **Note:**
@@ -71,6 +71,9 @@ On syncing 300 million rows table, it will consume around 800MB of memory with r
71
71
 
72
72
  # Set frequency of sending bulk request to Elasticsearch node.
73
73
  flush_interval 5s
74
+
75
+ # Queued chunks are flushed at shutdown process.
76
+ flush_at_shutdown yes
74
77
  </store>
75
78
  </match>
76
79
  `````
@@ -139,7 +142,7 @@ CREATE TABLE `settings` (
139
142
  `database` varchar(255) NOT NULL,
140
143
  `query` TEXT NOT NULL,
141
144
  `interval` int(11) NOT NULL,
142
- `primary_key` varchar(11) DEFAULT 'id',
145
+ `primary_key` varchar(255) DEFAULT 'id',
143
146
  `enable_delete` int(11) DEFAULT '1',
144
147
  PRIMARY KEY (`id`),
145
148
  UNIQUE KEY `name` (`name`)
@@ -198,6 +201,9 @@ it is a sample which you have inserted row.
198
201
 
199
202
  # Set frequency of sending bulk request to Elasticsearch node.
200
203
  flush_interval 5s
204
+
205
+ # Queued chunks are flushed at shutdown process.
206
+ flush_at_shutdown yes
201
207
  </match>
202
208
  `````
203
209
 
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "fluent-plugin-mysql-replicator"
4
- s.version = "0.2.0"
4
+ s.version = "0.2.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"
@@ -43,6 +43,7 @@ module Fluent
43
43
  begin
44
44
  poll
45
45
  rescue StandardError => e
46
+ $log.error "mysql_replicator: failed to execute query."
46
47
  $log.error "error: #{e.message}"
47
48
  $log.error e.backtrace.join("\n")
48
49
  end
@@ -52,6 +53,7 @@ module Fluent
52
53
  table_hash = Hash.new
53
54
  ids = Array.new
54
55
  loop do
56
+ start_time = Time.now
55
57
  previous_ids = ids
56
58
  current_ids = Array.new
57
59
  query(@query).each do |row|
@@ -69,7 +71,11 @@ module Fluent
69
71
  end
70
72
  ids = current_ids
71
73
  if @enable_delete
72
- deleted_ids = previous_ids - current_ids
74
+ if previous_ids.empty?
75
+ deleted_ids = [*1...current_ids.max] - current_ids
76
+ else
77
+ deleted_ids = previous_ids - current_ids
78
+ end
73
79
  if deleted_ids.count > 0
74
80
  hash_delete_by_list(table_hash, deleted_ids)
75
81
  deleted_ids.each do |id|
@@ -78,6 +84,8 @@ module Fluent
78
84
  end
79
85
  end
80
86
  end
87
+ elapsed_time = sprintf("%0.02f", (Time.now - start_time) % 60)
88
+ $log.info "mysql_replicator: finished execution :tag=>#{tag} :elapsed_time=>#{elapsed_time} seconds"
81
89
  sleep @interval
82
90
  end
83
91
  end
@@ -65,6 +65,7 @@ module Fluent
65
65
  primary_key = config['primary_key']
66
66
  previous_id = current_id = 0
67
67
  loop do
68
+ start_time = Time.now
68
69
  db = get_origin_connection(config)
69
70
  db.query(config['query']).each do |row|
70
71
  @mutex.lock
@@ -76,11 +77,16 @@ module Fluent
76
77
  @mutex.unlock
77
78
  end
78
79
  db.close
80
+ elapsed_time = sprintf("%0.02f", (Time.now - start_time) % 60)
81
+ $log.info "mysql_replicator_multi: finished execution :setting_name=>#{config['name']} :elapsed_time=>#{elapsed_time} seconds"
79
82
  sleep config['interval']
80
83
  end
81
84
  rescue StandardError => e
82
- $log.error "error: #{e.message}"
83
- $log.error e.backtrace.join("\n")
85
+ @mutex.synchronize {
86
+ $log.error "mysql_replicator_multi: failed to execute query. :config=>#{masked_config}"
87
+ $log.error "error: #{e.message}"
88
+ $log.error e.backtrace.join("\n")
89
+ }
84
90
  end
85
91
  end
86
92
 
@@ -21,7 +21,7 @@ CREATE TABLE `settings` (
21
21
  `database` varchar(255) NOT NULL,
22
22
  `query` TEXT NOT NULL,
23
23
  `interval` int(11) NOT NULL,
24
- `primary_key` varchar(11) DEFAULT 'id',
24
+ `primary_key` varchar(255) DEFAULT 'id',
25
25
  `enable_delete` int(11) DEFAULT '1',
26
26
  PRIMARY KEY (`id`),
27
27
  UNIQUE KEY `name` (`name`)
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.2.0
4
+ version: 0.2.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-11 00:00:00.000000000 Z
12
+ date: 2013-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake