flydata 0.6.4 → 0.6.5

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +2 -0
  4. data/VERSION +1 -1
  5. data/flydata-core/lib/flydata-core/table_def/base.rb +31 -0
  6. data/flydata-core/lib/flydata-core/table_def/mysql_table_def.rb +9 -30
  7. data/flydata-core/lib/flydata-core/table_def/postgresql_table_def.rb +111 -0
  8. data/flydata-core/lib/flydata-core/table_def/redshift_table_def.rb +4 -1
  9. data/flydata-core/spec/table_def/postgresql_table_def_spec.rb +348 -0
  10. data/flydata-core/spec/table_def/redshift_table_def_spec.rb +25 -0
  11. data/flydata.gemspec +0 -0
  12. data/lib/flydata.rb +0 -7
  13. data/lib/flydata/command/base.rb +3 -2
  14. data/lib/flydata/fluent-plugins/flydata_plugin_ext/base.rb +5 -0
  15. data/lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb +52 -0
  16. data/lib/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync.rb +55 -0
  17. data/lib/flydata/fluent-plugins/{idle_event_detector.rb → flydata_plugin_ext/idle_event_detector.rb} +0 -0
  18. data/lib/flydata/fluent-plugins/{preference.rb → flydata_plugin_ext/preference.rb} +2 -14
  19. data/lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb +58 -0
  20. data/lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb +55 -135
  21. data/lib/flydata/fluent-plugins/mysql/dml_record_handler.rb +9 -4
  22. data/lib/flydata/helper/server.rb +7 -0
  23. data/lib/flydata/preference/data_entry_preference.rb +5 -13
  24. data/lib/flydata/source.rb +1 -1
  25. data/lib/flydata/source/data_entry.rb +29 -0
  26. data/lib/flydata/source/sync.rb +19 -0
  27. data/lib/flydata/source/sync_generate_table_ddl.rb +47 -7
  28. data/lib/flydata/source_mysql/data_entry.rb +22 -0
  29. data/lib/flydata/source_mysql/parser/dump_parser.rb +1 -1
  30. data/lib/flydata/source_mysql/parser/mysql_alter_table.treetop +8 -3
  31. data/lib/flydata/source_mysql/sync.rb +1 -8
  32. data/lib/flydata/source_mysql/sync_generate_table_ddl.rb +11 -16
  33. data/lib/flydata/source_postgresql/data_entry.rb +21 -0
  34. data/lib/flydata/source_postgresql/sync.rb +29 -0
  35. data/lib/flydata/source_postgresql/sync_generate_table_ddl.rb +126 -0
  36. data/spec/flydata/fluent-plugins/{idle_event_detector_spec.rb → flydata_plugin_ext/idle_event_detector_spec.rb} +1 -1
  37. data/spec/flydata/fluent-plugins/in_mysql_binlog_flydata_spec.rb +10 -0
  38. data/spec/flydata/source_mysql/parser/alter_table_parser_spec.rb +119 -0
  39. data/spec/flydata/source_mysql/parser/dump_parser_spec.rb +32 -1
  40. data/spec/flydata/source_mysql/sync_generate_table_ddl_spec.rb +4 -4
  41. metadata +31 -5
@@ -233,6 +233,15 @@ EOT
233
233
  let(:default_sql) { " DEFAULT #{default_value_sql}" }
234
234
  it_behaves_like *examples
235
235
  end
236
+ context "replaced nil default" do
237
+ before do
238
+ column[:default] = default_value
239
+ allow(subject_object).to receive(:replace_default_value).
240
+ and_return(nil)
241
+ end
242
+ let(:default_sql) { no_default_sql }
243
+ it_behaves_like *examples
244
+ end
236
245
  end
237
246
 
238
247
  shared_examples "not null values" do |*examples|
@@ -977,6 +986,22 @@ EOS
977
986
  end
978
987
  end
979
988
  end
989
+ describe '.replace_default_value' do
990
+ subject { subject_object.replace_default_value(flydata_type, redshift_type,
991
+ default_value) }
992
+
993
+ context 'with integer type' do
994
+ let(:flydata_type) { "int8" }
995
+ let(:redshift_type) { "int8" }
996
+
997
+ context "nextval() as the value" do
998
+ let(:default_value) { "nextval('test_id_seq'::regclass)" }
999
+ it 'returns nil because Redshift does not support nextval()' do
1000
+ is_expected.to be_nil
1001
+ end
1002
+ end
1003
+ end
1004
+ end
980
1005
  end
981
1006
 
982
1007
  end
data/flydata.gemspec CHANGED
Binary file
data/lib/flydata.rb CHANGED
@@ -36,10 +36,3 @@ module Flydata
36
36
  VERSION_PATH = File.join(FLYDATA_GEM_HOME, 'VERSION')
37
37
  include Flydata::Heroku
38
38
  end
39
-
40
- # Require all helper files -
41
- # TODO : Check if this should be moved else where or can be more generic (not just helper files)
42
- lib_dir = File.dirname(File.absolute_path(__FILE__))
43
- FileUtils.cd(lib_dir) do
44
- Dir["flydata/helper/**/*.rb"].each { |file| require file }
45
- end
@@ -27,10 +27,11 @@ module Flydata
27
27
  raise "Failed to retrieve data_entries"
28
28
  end
29
29
  data_entries.collect do |de|
30
+ source = Source.create(de)
30
31
  if Flydata::Preference::DataEntryPreference.conf_exists?(de)
31
- Flydata::Preference::DataEntryPreference.load_conf(de)
32
+ Flydata::Preference::DataEntryPreference.load_conf(de, source)
32
33
  else
33
- Flydata::Preference::DataEntryPreference.filter_data_entry(de)
34
+ Flydata::Preference::DataEntryPreference.filter_data_entry(de, source)
34
35
  de
35
36
  end
36
37
  end
@@ -0,0 +1,5 @@
1
+ # Load client library(flydata-agent/lib)
2
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '../../../'))
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'flydata'
@@ -0,0 +1,52 @@
1
+ module Fluent
2
+
3
+ #Monkey-patch fluentd class (EngineClass) to support shutdown for input plugin.
4
+ #This will be called when USR1 signal is received
5
+ class EngineClass
6
+ #Send shutdown to all the sources
7
+ def shutdown_source
8
+ @sources.map {|s|
9
+ Thread.new do
10
+ begin
11
+ s.shutdown
12
+ rescue => e
13
+ $log.warn "unexpected error while shutting down", :error_class=>e.class, :error=>e
14
+ $log.warn_backtrace
15
+ end
16
+ end
17
+ }.each {|t|
18
+ t.join
19
+ }
20
+ end
21
+ end
22
+
23
+ module FlushSupport
24
+ def initialize
25
+ super
26
+ install_custom_signal_handler
27
+ end
28
+
29
+ #Hack: All that has been added here is `Fluent::Engine.shutdown_source`. This should be in
30
+ #fluentd's supervisor#install_main_process_signal_handlers
31
+ def install_custom_signal_handler
32
+ trap :USR1 do
33
+ $log.debug "fluentd main process get SIGUSR1"
34
+ $log.info "force flushing buffered events"
35
+ #@log.reopen!
36
+
37
+ # Creating new thread due to mutex can't lock
38
+ # in main thread during trap context
39
+ Thread.new {
40
+ begin
41
+ Fluent::Engine.shutdown_source
42
+ Fluent::Engine.flush!
43
+ $log.debug "flushing thread: flushed"
44
+ rescue Exception => e
45
+ $log.warn "flushing thread error: #{e}"
46
+ end
47
+ }.run
48
+ end
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,55 @@
1
+ require 'flydata/sync_file_manager'
2
+ require 'flydata-core/fluent/config_helper'
3
+ require 'flydata/fluent-plugins/flydata_plugin_ext/flush_support'
4
+ require 'flydata/fluent-plugins/flydata_plugin_ext/transaction_support'
5
+
6
+ module Fluent
7
+
8
+ module FlydataSync
9
+ def self.included(base)
10
+ base.class_eval do
11
+ include FlushSupport
12
+ prepend TransactionSupport
13
+
14
+ config_param :tables, :string
15
+ config_param :tables_append_only, :string
16
+
17
+ # binlog plugin
18
+ # TODO: Need to check if not configured or not
19
+ #config_param :tag, :string
20
+ #config_param :position_file, :string, :default => 'position.log'
21
+ end
22
+ end
23
+
24
+ def configure(conf)
25
+ super
26
+
27
+ @binlog_position_file = self.class::BINLOG_POSITION_FILE_CLASS.new(@position_file)
28
+ unless @binlog_position_file.exists?
29
+ raise "No position file(#{@binlog_position_file.path}). Initial synchronization is required before starting."
30
+ end
31
+
32
+ @sync_fm = Flydata::SyncFileManager.new(nil) # Passing nil for data_entry as this class does not use methods which require data_entry
33
+ sent_position_file_path = @sync_fm.sent_source_pos_path(@position_file)
34
+ @sent_position_file = self.class::BINLOG_POSITION_FILE_CLASS.new(sent_position_file_path)
35
+
36
+ # Create positions dir
37
+ positions_path = @sync_fm.table_positions_dir_path
38
+ Dir.mkdir positions_path unless File.exists? positions_path
39
+
40
+ load_custom_conf
41
+
42
+ @tables = @tables.split(/(?:\s*,\s*|\s+)/)
43
+ @omit_events = Hash.new
44
+ @tables_append_only.split(/(?:\s*,\s*|\s+)/).each do |table|
45
+ @tables << table unless @tables.include?(table)
46
+ @omit_events[table] = [:delete, :truncate_table]
47
+ end
48
+
49
+ # Remove tables that do not have pos files
50
+ new_tables = @sync_fm.get_new_table_list(@tables, "pos")
51
+ @tables -= new_tables
52
+ $log.info "Not watching these tables: #{new_tables.join(", ")}"
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'flydata/util/encryptor'
3
+ require 'flydata/source_mysql/data_entry'
3
4
 
4
5
  module Fluent
5
6
  module DataEntryPreferenceConfigurable
@@ -68,23 +69,10 @@ module Fluent
68
69
  end
69
70
 
70
71
  module MysqlBinlogFlydataInputPreference
71
- CUSTOM_CONFIG_PARAMS = {
72
- mysql_data_entry_preference: {
73
- database: {},
74
- tables: {},
75
- tables_append_only: {},
76
- host: {},
77
- username: {},
78
- password: {encrypted: true},
79
- ssl_ca_content: {},
80
- ssl_cipher: {},
81
- },
82
- }
83
-
84
72
  def self.included(base)
85
73
  base.class_eval do
86
74
  include DataEntryPreferenceConfigurable
87
- CUSTOM_CONFIG_PARAMS.each do |type, custom_conf|
75
+ Flydata::SourceMysql::DataEntry::CONFIG_PARAMS.each do |type, custom_conf|
88
76
  custom_conf.each do |key, option|
89
77
  custom_config_param key, type, option
90
78
  end
@@ -0,0 +1,58 @@
1
+ module Fluent
2
+
3
+ class TransactionContext
4
+ def set_transaction_broken
5
+ @transaction_broken = true
6
+ end
7
+
8
+ def transaction_broken?
9
+ @transaction_broken == true
10
+ end
11
+ end
12
+
13
+ # Transaction support
14
+ # This module is expected to be prepended
15
+ module TransactionSupport
16
+ def self.included(base)
17
+ raise "This module is expected to be prepended"
18
+ end
19
+
20
+ #def self.prepended(base)
21
+ #end
22
+
23
+ def configure(conf)
24
+ @lock_file = Flydata::FLYDATA_LOCK
25
+ super
26
+ end
27
+
28
+ def start
29
+ if File.exists?(@lock_file)
30
+ $log.error "Previous process was terminated abnormally. To start, remove the lock file after checking data integrity."
31
+ @abort = true
32
+ Process.kill(:TERM, Process.ppid)
33
+ return
34
+ end
35
+
36
+ super
37
+ end
38
+
39
+ def process_aborted?
40
+ instance_variable_defined? :@abort
41
+ end
42
+
43
+ def do_transaction
44
+ transaction_context =TransactionContext.new
45
+ File.open(@lock_file, "w") {|f| f.write(Process.pid)}
46
+ begin
47
+ yield(transaction_context)
48
+ ensure
49
+ # leave the lock file when a transaction is broken
50
+ if !transaction_context.transaction_broken? && File.exists?(@lock_file) &&
51
+ Process.pid == File.open(@lock_file, "r") {|f| f.read}.to_i
52
+ File.delete(@lock_file)
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ end
@@ -1,54 +1,32 @@
1
+ require_relative 'flydata_plugin_ext/base'
2
+
1
3
  module Fluent
2
4
 
3
5
  require 'fluent/plugin/in_mysql_binlog'
4
6
  require 'binlog'
5
7
  require 'kodama'
6
8
 
7
- # Load client library(flydata-agent/lib)
8
- lib = File.expand_path(File.join(File.dirname(__FILE__), '../../'))
9
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
10
- require 'flydata'
11
9
  require 'flydata/sync_file_manager'
12
10
  require 'flydata-core/mysql/command_generator'
13
- require 'flydata/fluent-plugins/preference'
11
+ require 'flydata/fluent-plugins/flydata_plugin_ext/preference'
14
12
  require 'flydata/fluent-plugins/mysql/binlog_position_file'
15
13
  require 'flydata/fluent-plugins/mysql/binlog_record_dispatcher'
16
14
  require 'flydata/fluent-plugins/mysql/context'
17
- require 'flydata/fluent-plugins/idle_event_detector'
15
+ require 'flydata/fluent-plugins/flydata_plugin_ext/idle_event_detector'
18
16
  require 'flydata/fluent-plugins/mysql/table_meta'
19
17
  require 'flydata/source_mysql/table_ddl'
20
18
  require 'flydata-core/fluent/config_helper'
21
19
  require 'flydata-core/mysql/ssl'
22
-
23
- #Monkey-patch fluentd class (EngineClass) to support shutdown for input plugin.
24
- #This will be called when USR1 signal is received
25
- class EngineClass
26
- #Send shutdown to all the sources
27
- def shutdown_source
28
- @sources.map {|s|
29
- Thread.new do
30
- begin
31
- s.shutdown
32
- rescue => e
33
- $log.warn "unexpected error while shutting down", :error_class=>e.class, :error=>e
34
- $log.warn_backtrace
35
- end
36
- end
37
- }.each {|t|
38
- t.join
39
- }
40
- end
41
- end
20
+ require 'flydata/fluent-plugins/flydata_plugin_ext/flydata_sync'
42
21
 
43
22
 
44
23
  class MysqlBinlogFlydataInput < MysqlBinlogInput
45
24
  include MysqlBinlogFlydataInputPreference
25
+ include FlydataSync
26
+
46
27
  Plugin.register_input('mysql_binlog_flydata', self)
47
28
 
48
- def initialize
49
- super
50
- install_custom_signal_handler
51
- end
29
+ BINLOG_POSITION_FILE_CLASS = Mysql::BinLogPositionFile
52
30
 
53
31
  config_param :database, :string
54
32
  config_param :tables, :string
@@ -77,19 +55,10 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
77
55
 
78
56
  def configure(conf)
79
57
  super
80
- @binlog_position_file = Mysql::BinLogPositionFile.new(@position_file)
81
- unless @binlog_position_file.exists?
82
- raise "No position file(#{@position_file}). Initial synchronization is required before starting."
83
- end
84
-
85
- @sync_fm = Flydata::SyncFileManager.new(nil) # Passing nil for data_entry as this class does not use methods which require data_entry
86
- @sent_position_file_path = @sync_fm.sent_source_pos_path(@position_file)
87
-
88
- load_custom_conf
89
58
 
90
59
  # SSL configuration
91
60
  unless @ssl_ca_content.to_s.strip.empty?
92
- @ssl_ca_path = @sync_fm.ssl_ca_path(@position_file)
61
+ @ssl_ca_path = @sync_fm.ssl_ca_path(@binlog_position_file.path)
93
62
  @sync_fm.save_ssl_ca(FlydataCore::Fluent::ConfigHelper.unescape_conf(@ssl_ca_content), @ssl_ca_path)
94
63
  end
95
64
 
@@ -108,18 +77,6 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
108
77
  #exit 1 # causes retry loop
109
78
  end
110
79
 
111
- @tables = @tables.split(/,\s*/)
112
- @omit_events = Hash.new
113
- @tables_append_only.split(/,\s*/).each do |table|
114
- @tables << table unless @tables.include?(table)
115
- @omit_events[table] = [:delete, :truncate_table]
116
- end
117
-
118
- # Remove tables that do not have pos files
119
- new_tables = @sync_fm.get_new_table_list(@tables, "pos")
120
- @tables -= new_tables
121
- $log.info "Not watching these tables: #{new_tables.join(", ")}"
122
-
123
80
  table_meta = Flydata::Mysql::TableMeta.new(@db_opts.merge(tables: @tables))
124
81
 
125
82
  table_revs = tables.inject({}) do |h, table_name|
@@ -135,18 +92,11 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
135
92
  )
136
93
  @record_dispatcher = Mysql::FlydataBinlogRecordDispatcher.new(@context)
137
94
  @idle_event_detector = IdleEventDetector.new(@initial_idle_interval, @continuous_idle_interval, @check_interval, @idle_timeout)
138
- @lock_file = Flydata::FLYDATA_LOCK
139
95
  end
140
96
 
141
97
  def start
142
- if File.exists?(@lock_file)
143
- $log.error "Previous process was terminated abnormally. To start, remove the lock file after checking data integrity."
144
- @abort = true
145
- Process.kill(:TERM, Process.ppid)
146
- return
147
- end
148
-
149
98
  super
99
+
150
100
  @idle_event_detector.start do |reason, timestamp|
151
101
  case reason
152
102
  when :event_not_coming
@@ -161,9 +111,6 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
161
111
  end
162
112
  end
163
113
 
164
- positions_path = @context.sync_fm.table_positions_dir_path
165
- Dir.mkdir positions_path unless File.exists? positions_path
166
-
167
114
  rescue Binlog::Error
168
115
  if (/basic_string::_M_replace_aux/ === $!.to_s)
169
116
  # TODO Fix the root cause in mysql-replication-listener
@@ -181,73 +128,67 @@ EOS
181
128
  end
182
129
 
183
130
  def run
184
- return if instance_variable_defined? :@abort
131
+ return if process_aborted?
185
132
 
186
133
  @context.table_meta.update
187
134
  Flydata::SourceMysql::TableDdl.migrate_tables(@context.tables, @db_opts,
188
- @context.sync_fm, @position_file,
135
+ @context.sync_fm, @binlog_position_file.path,
189
136
  @context) do |event|
190
137
  @record_dispatcher.dispatch(event)
191
138
  end
192
139
 
193
140
  current_ssl_cipher = @ssl_cipher
194
141
  retried = false
195
- transaction_broken = false
196
- File.open(@lock_file, "w") {|f| f.write(Process.pid)}
197
- begin
142
+
143
+ do_transaction do |transaction_context|
198
144
  begin
199
- start_kodama(mysql_url) do |c|
200
- c.binlog_position_file = @position_file
201
- if @ssl_ca_path.to_s != '' && c.respond_to?(:ssl_ca=)
202
- $log.info "SSL is enabled. (ssl_ca: #{@ssl_ca_path})"
203
- c.ssl_ca = @ssl_ca_path
204
- unless current_ssl_cipher.to_s.empty?
205
- $log.info "SSL cipher is set. (ssl_cipher: #{current_ssl_cipher})"
206
- c.ssl_cipher = current_ssl_cipher
145
+ begin
146
+ start_kodama(mysql_url) do |c|
147
+ c.binlog_position_file = @binlog_position_file.path
148
+ if @ssl_ca_path.to_s != '' && c.respond_to?(:ssl_ca=)
149
+ $log.info "SSL is enabled. (ssl_ca: #{@ssl_ca_path})"
150
+ c.ssl_ca = @ssl_ca_path
151
+ unless current_ssl_cipher.to_s.empty?
152
+ $log.info "SSL cipher is set. (ssl_cipher: #{current_ssl_cipher})"
153
+ c.ssl_cipher = current_ssl_cipher
154
+ end
207
155
  end
208
- end
209
156
 
210
- if c.respond_to?(:sent_binlog_position_file=)
211
- $log.info "Sent position feature is enabled. sent_position_file:#{@sent_position_file_path}"
212
- c.sent_binlog_position_file = @sent_position_file_path
213
- end
157
+ if c.respond_to?(:sent_binlog_position_file=)
158
+ $log.info "Sent position feature is enabled. sent_position_file:#{@sent_position_file.path}"
159
+ c.sent_binlog_position_file = @sent_position_file.path
160
+ end
214
161
 
215
- $log.info("Binlog position - resume_pos:'#{IO.read(@position_file) rescue IOError}' " +
216
- "sent_pos:'#{IO.read(@sent_position_file_path) rescue IOError}'")
162
+ $log.info("Binlog position - resume_pos:'#{@binlog_position_file.read rescue IOError}' " +
163
+ "sent_pos:'#{@sent_position_file.read rescue IOError}'")
217
164
 
218
- c.connection_retry_limit = @retry_limit
219
- c.connection_retry_wait = @retry_wait
220
- c.log_level = @log_level.to_sym
221
- @listen_events.each do |event_type|
222
- $log.trace { "registered binlog event listener '#{event_type}'" }
223
- c.send("on_#{event_type}", &method(:event_listener))
165
+ c.connection_retry_limit = @retry_limit
166
+ c.connection_retry_wait = @retry_wait
167
+ c.log_level = @log_level.to_sym
168
+ @listen_events.each do |event_type|
169
+ $log.trace { "registered binlog event listener '#{event_type}'" }
170
+ c.send("on_#{event_type}", &method(:event_listener))
171
+ end
224
172
  end
173
+ rescue Kodama::TransactionError
174
+ $log.debug "TransactionError"
175
+ transaction_context.set_transaction_broken
176
+ raise
177
+ end
178
+ rescue Binlog::Error => e
179
+ if /dh key too small/.match(e.to_s) && !retried && !@secondary_ssl_cipher.to_s.empty?
180
+ retried = true
181
+ current_ssl_cipher = @secondary_ssl_cipher
182
+ $log.warn("Retry with secondary ssl cipher list due to '#{e}' - secondary_ssl_cipher: '#{@secondary_ssl_cipher}'")
183
+ retry
184
+ elsif /binlog file.*does not exist/.match(e.to_s)
185
+ $log.error("#{e.to_s}. Sync must be reset. Terminating the agent.")
186
+ Process.kill(:TERM, Process.ppid)
187
+ else
188
+ raise e
225
189
  end
226
- rescue Kodama::TransactionError
227
- $log.debug "TransactionError"
228
- transaction_broken = true
229
- raise
230
- end
231
- rescue Binlog::Error => e
232
- if /dh key too small/.match(e.to_s) && !retried && !@secondary_ssl_cipher.to_s.empty?
233
- retried = true
234
- current_ssl_cipher = @secondary_ssl_cipher
235
- $log.warn("Retry with secondary ssl cipher list due to '#{e}' - secondary_ssl_cipher: '#{@secondary_ssl_cipher}'")
236
- retry
237
- elsif /binlog file.*does not exist/.match(e.to_s)
238
- $log.error("#{e.to_s}. Sync must be reset. Terminating the agent.")
239
- Process.kill(:TERM, Process.ppid)
240
- else
241
- raise e
242
- end
243
- ensure
244
- if !transaction_broken && # leave the lock file when a transaction is broken
245
- File.exists?(@lock_file) &&
246
- Process.pid == File.open(@lock_file, "r") {|f| f.read}.to_i
247
- File.delete(@lock_file)
248
190
  end
249
191
  end
250
-
251
192
  rescue => e
252
193
  # HACK: mysql-replication-listener has a network connection leak bug which doesn't release a connection
253
194
  # to MySQL. Rather than fixing the bug, restarting the fluentd process for now.
@@ -279,7 +220,7 @@ EOS
279
220
  end
280
221
 
281
222
  def shutdown
282
- return if instance_variable_defined? :@abort
223
+ return if process_aborted?
283
224
 
284
225
  @idle_event_detector.stop
285
226
  if @thread and @thread.alive?
@@ -296,6 +237,7 @@ EOS
296
237
  $log.warn "an error occurred during Kodama shutdown. error:'#{e.to_s}'\n#{e.backtrace.join("\n")}"
297
238
  end
298
239
  end
240
+
299
241
  @sync_fm.close
300
242
  end
301
243
 
@@ -307,28 +249,6 @@ EOS
307
249
  end
308
250
  false
309
251
  end
310
-
311
- #Hack: All that has been added here is `Fluent::Engine.shutdown_source`. This should be in
312
- #fluentd's supervisor#install_main_process_signal_handlers
313
- def install_custom_signal_handler
314
- trap :USR1 do
315
- $log.debug "fluentd main process get SIGUSR1"
316
- $log.info "force flushing buffered events"
317
- #@log.reopen!
318
-
319
- # Creating new thread due to mutex can't lock
320
- # in main thread during trap context
321
- Thread.new {
322
- begin
323
- Fluent::Engine.shutdown_source
324
- Fluent::Engine.flush!
325
- $log.debug "flushing thread: flushed"
326
- rescue Exception => e
327
- $log.warn "flushing thread error: #{e}"
328
- end
329
- }.run
330
- end
331
- end
332
252
  end
333
253
 
334
254