flydata 0.6.11 → 0.6.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +4 -4
- data/VERSION +1 -1
- data/flydata-core/lib/flydata-core/postgresql/source_pos.rb +34 -0
- data/flydata-core/lib/flydata-core/table_def/base.rb +10 -0
- data/flydata-core/lib/flydata-core/table_def/postgresql_table_def.rb +20 -4
- data/flydata-core/spec/postgresql/source_pos_spec.rb +43 -0
- data/flydata-core/spec/table_def/base_spec.rb +51 -0
- data/flydata.gemspec +0 -0
- data/lib/flydata/command/sender.rb +9 -6
- data/lib/flydata/command/setup.rb +6 -12
- data/lib/flydata/command/sync.rb +31 -17
- data/lib/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync.rb +2 -3
- data/lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb +15 -14
- data/lib/flydata/parser/source_table.rb +4 -3
- data/lib/flydata/plugin_support/context.rb +46 -0
- data/lib/flydata/plugin_support/sync_record_emittable.rb +69 -0
- data/lib/flydata/source/component.rb +1 -1
- data/lib/flydata/source/generate_source_dump.rb +3 -2
- data/lib/flydata/source_mysql/mysql_compatibility_check.rb +12 -11
- data/lib/flydata/source_mysql/parser/dump_parser.rb +0 -4
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/alter_table_query_handler.rb +8 -2
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/binlog_position_file.rb +7 -1
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/binlog_query_dispatcher.rb +10 -4
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/binlog_query_handler.rb +8 -2
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/binlog_record_dispatcher.rb +9 -3
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/binlog_record_handler.rb +16 -34
- data/lib/flydata/source_mysql/plugin_support/context.rb +7 -0
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/ddl_query_handler.rb +11 -19
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/dml_record_handler.rb +8 -2
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/drop_database_query_handler.rb +8 -2
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/table_meta.rb +5 -1
- data/lib/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/truncate_table_query_handler.rb +8 -2
- data/lib/flydata/source_postgresql/generate_source_dump.rb +175 -0
- data/lib/flydata/source_postgresql/parse_dump_and_send.rb +126 -0
- data/lib/flydata/source_postgresql/pg_client.rb +43 -0
- data/lib/flydata/source_postgresql/postgresql_component.rb +12 -0
- data/lib/flydata/source_postgresql/setup.rb +24 -0
- data/lib/flydata/source_postgresql/source_pos.rb +18 -0
- data/lib/flydata/source_postgresql/sync_generate_table_ddl.rb +7 -15
- data/lib/flydata/sync_file_manager.rb +39 -28
- data/spec/flydata/command/setup_spec.rb +0 -1
- data/spec/flydata/command/sync_spec.rb +2 -2
- data/spec/flydata/fluent-plugins/in_mysql_binlog_flydata_spec.rb +5 -6
- data/spec/flydata/plugin_support/context_spec.rb +27 -0
- data/spec/flydata/source_mysql/parser/dump_parser_spec.rb +4 -4
- data/spec/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/alter_table_query_handler_spec.rb +3 -3
- data/spec/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/binlog_query_dispatcher_spec.rb +5 -5
- data/spec/flydata/source_mysql/plugin_support/context_spec.rb +26 -0
- data/spec/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/ddl_query_handler_spec.rb +3 -3
- data/spec/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/dml_record_handler_spec.rb +2 -2
- data/spec/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/drop_database_query_handler_spec.rb +3 -3
- data/spec/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/shared_query_handler_context.rb +3 -1
- data/spec/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/table_meta_spec.rb +3 -3
- data/spec/flydata/{fluent-plugins/mysql → source_mysql/plugin_support}/truncate_query_handler_spec.rb +7 -4
- data/spec/flydata/source_postgresql/generate_source_dump_spec.rb +144 -0
- data/spec/flydata/sync_file_manager_spec.rb +1 -1
- metadata +38 -24
- data/lib/flydata/fluent-plugins/mysql/context.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 181cbcfe32036e4e5e580f5208c183c2aeede5d5
|
4
|
+
data.tar.gz: d74e286636bafd5a3ade8482cd808c69597ff723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d01fd1622e3573ed4b2989af7ad77a1fd9f8c945bc6d8f959e65818a4733c161e32793c908c51ce71974066bc86db80d69aabff904d18a4336ddc60f95bd40bf
|
7
|
+
data.tar.gz: f829d5633875735e6fef04eec4fadd7778b9e35eedbc7decbcbea150ebb4a2bf64d91bfcc50550f14f4a59ff8aecc2599cae93bb249e8ec775d2b58a71927f43
|
data/Gemfile
CHANGED
@@ -14,7 +14,7 @@ gem "slop", '~> 3.4', '>= 3.4.6'
|
|
14
14
|
gem "treetop", '~> 1.5', '>= 1.5.3'
|
15
15
|
gem "sys-filesystem", '~> 1.1', '>= 1.1.3'
|
16
16
|
gem "io-console", '~> 0.4.2', '>= 0.4.2'
|
17
|
-
gem "kodama", '~> 0.1', '>= 0.1.
|
17
|
+
gem "kodama", '~> 0.1', '>= 0.1.11'
|
18
18
|
gem "serverengine", '~> 1.5'
|
19
19
|
|
20
20
|
group :development do
|
data/Gemfile.lock
CHANGED
@@ -61,8 +61,8 @@ GEM
|
|
61
61
|
rdoc
|
62
62
|
json (1.8.1)
|
63
63
|
jwt (1.0.0)
|
64
|
-
kodama (0.1.
|
65
|
-
ruby-binlog (~> 1.0, >= 1.0.
|
64
|
+
kodama (0.1.11)
|
65
|
+
ruby-binlog (~> 1.0, >= 1.0.9)
|
66
66
|
method_source (0.8.2)
|
67
67
|
mime-types (2.3)
|
68
68
|
minitest (4.7.5)
|
@@ -108,7 +108,7 @@ GEM
|
|
108
108
|
rspec-mocks (3.0.3)
|
109
109
|
rspec-support (~> 3.0.0)
|
110
110
|
rspec-support (3.0.3)
|
111
|
-
ruby-binlog (1.0.
|
111
|
+
ruby-binlog (1.0.9)
|
112
112
|
ruby-prof (0.15.1)
|
113
113
|
serverengine (1.5.10)
|
114
114
|
sigdump (~> 0.2.2)
|
@@ -138,7 +138,7 @@ DEPENDENCIES
|
|
138
138
|
io-console (~> 0.4.2, >= 0.4.2)
|
139
139
|
jeweler (~> 1.8, >= 1.8.8)
|
140
140
|
json (~> 1.8, >= 1.8.0)
|
141
|
-
kodama (~> 0.1, >= 0.1.
|
141
|
+
kodama (~> 0.1, >= 0.1.11)
|
142
142
|
mysql2 (~> 0.3, >= 0.3.17)
|
143
143
|
pg (~> 0.18.4)
|
144
144
|
protected_attributes (~> 1.0, >= 1.0.8)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.12
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module FlydataCore
|
4
|
+
module Postgresql
|
5
|
+
|
6
|
+
class SourcePos
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
def initialize(snapshot_id, pk_values = nil)
|
10
|
+
@snapshot_id = snapshot_id
|
11
|
+
@pk_values = pk_values
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :snapshot_id
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
pk_values = @pk_values ? @pk_values.to_json : ''
|
18
|
+
"#{@snapshot_id}\t#{pk_values}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
# TODO take pk_values into account
|
23
|
+
@snapshot_id <=> other.snapshot_id
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.load(str)
|
27
|
+
snapshot_id, pk_valules = str.split("\t")
|
28
|
+
pk_values = JSON.parse(pk_values) if pk_values
|
29
|
+
self.new(snapshot_id, pk_values)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -25,6 +25,16 @@ class Base
|
|
25
25
|
|
26
26
|
tabledef
|
27
27
|
end
|
28
|
+
|
29
|
+
def column_names
|
30
|
+
@columns.collect{|col| col[:column]}
|
31
|
+
end
|
32
|
+
|
33
|
+
def pk_columns
|
34
|
+
@columns.select{|col| col.has_key?(:primary_key) }.
|
35
|
+
sort{|a,b| a[:primary_key] <=> b[:primary_key]}.
|
36
|
+
collect{|col| col[:column]}
|
37
|
+
end
|
28
38
|
end
|
29
39
|
|
30
40
|
end
|
@@ -9,16 +9,32 @@ class PostgresqlTableDef < Base
|
|
9
9
|
|
10
10
|
TYPE_MAP_P2F = {
|
11
11
|
'bigint' => {type: 'int8'},
|
12
|
+
'bigserial' => {type: 'int8'},
|
13
|
+
'boolean' => {type: 'int1', def_width: '1'}, # TODO introduce bool type
|
14
|
+
'bytea' => {type: 'varbinary'}, # TODO need value conversion
|
15
|
+
'character' => {type: 'varchar', def_width: '1'},
|
12
16
|
'character varying' => {type: 'varchar',
|
13
|
-
width_attrs:["character_octet_length"]
|
17
|
+
width_attrs:["character_octet_length"],
|
18
|
+
def_width:[1]},
|
19
|
+
'date' => {type: 'date'},
|
20
|
+
'decimal' => {type: 'numeric',
|
21
|
+
width_attrs:["numeric_precision", "numeric_scale"],
|
22
|
+
def_width:[nil, 0] },
|
23
|
+
'double precision' => {type: 'float8'},
|
14
24
|
'integer' => {type: 'int4'},
|
15
|
-
'
|
16
|
-
'timestamp without time zone' => {type: 'datetime'}, # TODO may need override?
|
17
|
-
'bytea' => {type: 'varbinary'}, # TODO need value conversion
|
25
|
+
'money' => {type: 'money'},
|
18
26
|
'numeric' => {type: 'numeric',
|
19
27
|
width_attrs:["numeric_precision", "numeric_scale"],
|
20
28
|
def_width:[nil, 0],
|
21
29
|
},
|
30
|
+
'real' => {type: 'float4'},
|
31
|
+
'serial' => {type: 'int4'},
|
32
|
+
'smallint' => {type: 'int2'},
|
33
|
+
'text' => {type: 'text'},
|
34
|
+
'time with time zone' => {type: 'time'},
|
35
|
+
'time without time zone' => {type: 'time'},
|
36
|
+
'timestamp with time zone' => {type: 'datetime'},
|
37
|
+
'timestamp without time zone' => {type: 'datetime'},
|
22
38
|
# TODO add more types
|
23
39
|
}
|
24
40
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'flydata-core/postgresql/source_pos'
|
2
|
+
|
3
|
+
module FlydataCore
|
4
|
+
module Postgresql
|
5
|
+
|
6
|
+
describe SourcePos do
|
7
|
+
let(:subject_object) { described_class.new(snapshot_id, pk_values) }
|
8
|
+
|
9
|
+
let(:snapshot_id) { "1234:1234:" }
|
10
|
+
let(:pk_values) { nil }
|
11
|
+
|
12
|
+
describe '#to_s' do
|
13
|
+
subject { subject_object.to_s }
|
14
|
+
|
15
|
+
context 'when pk_values is nil' do
|
16
|
+
let(:pk_values) { nil }
|
17
|
+
it { is_expected.to eq %Q|#{snapshot_id}\t| }
|
18
|
+
end
|
19
|
+
context 'when pk_values is not nil' do
|
20
|
+
let(:pk_values) { { "user_id" => 1, "address_id" => 3 } }
|
21
|
+
it { is_expected.to eq %Q|#{snapshot_id}\t{"user_id":1,"address_id":3}| }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.load' do
|
26
|
+
subject { described_class.load(str) }
|
27
|
+
|
28
|
+
context 'without pk_values' do
|
29
|
+
let(:str) { %Q|#{snapshot_id}\t| }
|
30
|
+
it { is_expected.to eq described_class.new(snapshot_id) }
|
31
|
+
end
|
32
|
+
context 'with pk_values' do
|
33
|
+
let(:str) { %Q|#{snapshot_id}\t{"user_id":1,"address_id":3}| }
|
34
|
+
it do
|
35
|
+
is_expected.to eq described_class.new(snapshot_id,
|
36
|
+
"user_id" => 1, "address_id" => 3)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'flydata-core/table_def/base'
|
2
|
+
|
3
|
+
module FlydataCore
|
4
|
+
module TableDef
|
5
|
+
|
6
|
+
describe Base do
|
7
|
+
let(:subject_object) { described_class.new(table_def, table_name, columns,
|
8
|
+
column_def, default_charset,
|
9
|
+
default_source_charset, comment) }
|
10
|
+
|
11
|
+
let(:table_def) { double('table_def') }
|
12
|
+
let(:table_name) { double('table_name') }
|
13
|
+
let(:columns) { double('columns') }
|
14
|
+
let(:column_def) { double('column_def') }
|
15
|
+
let(:default_charset) { double('default_charset') }
|
16
|
+
let(:default_source_charset) { double('default_source_charset') }
|
17
|
+
let(:comment) { double('comment') }
|
18
|
+
|
19
|
+
describe '#pk_columns' do
|
20
|
+
subject { subject_object.pk_columns }
|
21
|
+
|
22
|
+
let(:columns) do
|
23
|
+
[ {column: "name"},
|
24
|
+
{column: "address_id", primary_key: pk1_value},
|
25
|
+
{column: "zip"},
|
26
|
+
{column: "user_id", primary_key: pk2_value},
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
context 'with unordered primary keys' do
|
32
|
+
let(:pk1_value) { 't' }
|
33
|
+
let(:pk2_value) { 't' }
|
34
|
+
|
35
|
+
it "returns primary keys in the column order" do
|
36
|
+
is_expected.to eq %w(address_id user_id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
context 'with ordered primary keys' do
|
40
|
+
let(:pk1_value) { 2 }
|
41
|
+
let(:pk2_value) { 1 }
|
42
|
+
|
43
|
+
it "returns primary keys in the pk order" do
|
44
|
+
is_expected.to eq %w(user_id address_id)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/flydata.gemspec
CHANGED
Binary file
|
@@ -110,8 +110,8 @@ EOF
|
|
110
110
|
log_info_stdout('Restarting sender process.') unless options[:quiet]
|
111
111
|
begin
|
112
112
|
stop(options)
|
113
|
-
rescue
|
114
|
-
log_warn_stderr
|
113
|
+
rescue => e
|
114
|
+
log_warn_stderr "Something has gone wrong. Force stopping the FlyData process. error:#{e.to_s}"
|
115
115
|
kill_all(options)
|
116
116
|
end
|
117
117
|
else
|
@@ -132,7 +132,7 @@ EOF
|
|
132
132
|
`[ -f #{pid_file} ] && pgrep -P \`cat #{pid_file}\``.to_i > 0
|
133
133
|
end
|
134
134
|
def kill_all(options = {})
|
135
|
-
if Kernel.system("ps
|
135
|
+
if Kernel.system("ps x | grep 'flydata' | grep -v grep | grep fluentd | awk '{print \"kill -9 \" $1}' | sh")
|
136
136
|
log_info_stdout("Done.") unless options[:quiet]
|
137
137
|
return true
|
138
138
|
else
|
@@ -192,11 +192,14 @@ EOF
|
|
192
192
|
raise "Somthing has gone wrong... Please try setup command again."
|
193
193
|
end
|
194
194
|
def wait_until_client_stop(options = {})
|
195
|
-
retry_count =
|
195
|
+
retry_count = 120
|
196
|
+
show_message_at_retry = 4
|
196
197
|
1.upto(retry_count) do |i|
|
197
198
|
return true unless process_exist?
|
198
|
-
|
199
|
-
|
199
|
+
Kernel.sleep 5
|
200
|
+
if i % show_message_at_retry == 0
|
201
|
+
log_info_stdout("Waiting for the client to stop...") unless options[:quiet]
|
202
|
+
end
|
200
203
|
end
|
201
204
|
false
|
202
205
|
end
|
@@ -76,18 +76,12 @@ What's next?
|
|
76
76
|
Flydata::Command::Conf.new.copy_templates
|
77
77
|
puts
|
78
78
|
de_exists = !!retrieve_data_entries.first
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
false
|
86
|
-
end
|
87
|
-
else
|
88
|
-
false
|
89
|
-
end
|
90
|
-
Flydata::Command::Sender.new.restart(quiet: true) if ret
|
79
|
+
if de_exists && source.setup.initial_run_need_restart?
|
80
|
+
sender = Flydata::Command::Sender.new
|
81
|
+
if sender.process_exist?
|
82
|
+
Flydata::Command::Sender.new.restart(quiet: true)
|
83
|
+
end
|
84
|
+
end
|
91
85
|
last_message = de_exists ? source.setup.initial_run_complete_message
|
92
86
|
: :no_de_cancel
|
93
87
|
msgs = standard_messages
|
data/lib/flydata/command/sync.rb
CHANGED
@@ -34,6 +34,7 @@ module Flydata
|
|
34
34
|
SERVER_DATA_PROCESSING_TIMEOUT = 3600 # seconds
|
35
35
|
|
36
36
|
# for dump.pos file
|
37
|
+
STATUS_START = 'START' # only :source_pos is available at the begining of parse
|
37
38
|
STATUS_PARSING = 'PARSING'
|
38
39
|
STATUS_PARSED = 'WAITING' # the value is different from the constant name on purpose for backward compatibility.
|
39
40
|
STATUS_COMPLETE = 'COMPLETE'
|
@@ -783,24 +784,27 @@ EOM
|
|
783
784
|
def parse_dump_and_send(dump_io, dp, de, sync_fm, source_pos)
|
784
785
|
|
785
786
|
context = source.parse_dump_and_send
|
786
|
-
# Prepare forwarder
|
787
|
-
de_tag_name = de["tag_name#{env_suffix}"]
|
788
|
-
server_port = dp['server_port']
|
789
|
-
data_servers = source.sync.data_servers
|
790
|
-
servers = data_servers ? data_servers.split(',') :
|
791
|
-
dp["servers#{env_suffix}"].collect{|s| "#{s}:#{server_port}"}
|
792
|
-
forwarder_type = source.sync.forwarder ||
|
793
|
-
(dp['ssl_enabled'] ? 'sslforwarder' : 'tcpforwarder')
|
794
|
-
forwarder = Flydata::Output::ForwarderFactory.create(forwarder_type, de_tag_name, servers)
|
795
787
|
|
796
788
|
# Load dump.pos file for resume
|
797
789
|
dump_pos_info = sync_fm.load_dump_pos
|
798
|
-
dump_pos_info
|
790
|
+
if dump_pos_info.empty?
|
791
|
+
# First time to parse. No dump pos file available.
|
792
|
+
# Re-initialize dump_pos_info hash with new dump pos file.
|
793
|
+
if source_pos.nil?
|
794
|
+
raise "Cannot parse dump because source position is not available. Reset unfinished initial sync by command: flydata sync:reset --init"
|
795
|
+
end
|
796
|
+
sync_fm.save_dump_pos(STATUS_START, nil, nil, source_pos)
|
797
|
+
dump_pos_info = sync_fm.load_dump_pos
|
798
|
+
end
|
799
|
+
|
800
|
+
source_pos = dump_pos_info[:source_pos]
|
801
|
+
if source_pos.nil?
|
802
|
+
# this should never happen but just in case...
|
803
|
+
raise "Source position is not available. Parse dump failed. Reset unfinished initial sync by command: flydata sync:reset --init"
|
804
|
+
end
|
805
|
+
|
799
806
|
if dump_pos_info[:table_name] && dump_pos_info[:last_pos].to_i != -1
|
800
|
-
source_pos = dump_pos_info[:source_pos]
|
801
807
|
log_info_stdout("Resuming... Last processed table: #{dump_pos_info[:table_name]}")
|
802
|
-
else
|
803
|
-
dump_pos_info[:source_pos] = source_pos
|
804
808
|
end
|
805
809
|
if dump_pos_info[:source_table] && dump_pos_info[:source_table].value_converters.nil?
|
806
810
|
# Old marshal dumped source_table object may not have value_converters
|
@@ -810,6 +814,17 @@ EOM
|
|
810
814
|
# Old marshal dumped source_table object may not have column_names
|
811
815
|
dump_pos_info[:source_table].set_column_names
|
812
816
|
end
|
817
|
+
|
818
|
+
# Prepare forwarder
|
819
|
+
de_tag_name = de["tag_name#{env_suffix}"]
|
820
|
+
server_port = dp['server_port']
|
821
|
+
data_servers = source.sync.data_servers
|
822
|
+
servers = data_servers ? data_servers.split(',') :
|
823
|
+
dp["servers#{env_suffix}"].collect{|s| "#{s}:#{server_port}"}
|
824
|
+
forwarder_type = source.sync.forwarder ||
|
825
|
+
(dp['ssl_enabled'] ? 'sslforwarder' : 'tcpforwarder')
|
826
|
+
forwarder = Flydata::Output::ForwarderFactory.create(forwarder_type, de_tag_name, servers)
|
827
|
+
|
813
828
|
log_info_stdout("Sending data to FlyData Server...")
|
814
829
|
|
815
830
|
# initialize stats
|
@@ -884,6 +899,8 @@ EOM
|
|
884
899
|
if tmp_num_inserted_record > 0 && forwarder.buffer_record_count > 0
|
885
900
|
ret = forwarder.flush # send buffer data to the server before checkpoint
|
886
901
|
sync_fm.save_record_count_stat(table_name, ret[:record_count]) if ret
|
902
|
+
# save check point
|
903
|
+
sync_fm.save_dump_pos(STATUS_PARSING, table_name, last_pos, source_pos, state, substate)
|
887
904
|
end
|
888
905
|
|
889
906
|
# show the current progress
|
@@ -893,9 +910,6 @@ EOM
|
|
893
910
|
log_info_stdout(" -> #{(last_pos.to_f/dump_file_size * 100).round(1)}% (#{last_pos}/#{dump_file_size}) completed...")
|
894
911
|
end
|
895
912
|
|
896
|
-
# save check point
|
897
|
-
sync_fm.save_dump_pos(STATUS_PARSING, table_name, last_pos, source_pos, state, substate)
|
898
|
-
|
899
913
|
# send record count for the table
|
900
914
|
if table_name.to_s != '' &&
|
901
915
|
state == Flydata::Parser::State::CREATE_TABLE
|
@@ -925,10 +939,10 @@ EOM
|
|
925
939
|
send_record_counts_threads.each{|t| t.join}
|
926
940
|
output_thread.join
|
927
941
|
forwarder.close
|
942
|
+
sync_fm.save_dump_pos(STATUS_PARSED, '', dump_file_size, source_pos)
|
928
943
|
log_info_stdout(" -> Done")
|
929
944
|
#log_info_stdout(" -> Records sent to the server")
|
930
945
|
#log_info_stdout(" -> #{sync_fm.load_stats}")
|
931
|
-
sync_fm.save_dump_pos(STATUS_PARSED, '', dump_file_size, source_pos)
|
932
946
|
|
933
947
|
if ENV['FLYDATA_BENCHMARK']
|
934
948
|
bench_end_time = Time.now
|
@@ -15,9 +15,8 @@ module Fluent
|
|
15
15
|
config_param :tables_append_only, :string
|
16
16
|
|
17
17
|
# binlog plugin
|
18
|
-
|
19
|
-
|
20
|
-
#config_param :position_file, :string, :default => 'position.log'
|
18
|
+
config_param :tag, :string
|
19
|
+
config_param :position_file, :string, default: 'position.log'
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
@@ -9,15 +9,15 @@ require 'kodama'
|
|
9
9
|
require 'flydata/sync_file_manager'
|
10
10
|
require 'flydata-core/mysql/command_generator'
|
11
11
|
require 'flydata/fluent-plugins/flydata_plugin_ext/preference'
|
12
|
-
require 'flydata/fluent-plugins/mysql/binlog_position_file'
|
13
|
-
require 'flydata/fluent-plugins/mysql/binlog_record_dispatcher'
|
14
|
-
require 'flydata/fluent-plugins/mysql/context'
|
15
12
|
require 'flydata/fluent-plugins/flydata_plugin_ext/idle_event_detector'
|
16
|
-
require 'flydata/fluent-plugins/
|
13
|
+
require 'flydata/fluent-plugins/flydata_plugin_ext/flydata_sync'
|
14
|
+
require 'flydata/source_mysql/plugin_support/binlog_position_file'
|
15
|
+
require 'flydata/source_mysql/plugin_support/binlog_record_dispatcher'
|
16
|
+
require 'flydata/source_mysql/plugin_support/context'
|
17
|
+
require 'flydata/source_mysql/plugin_support/table_meta'
|
17
18
|
require 'flydata/source_mysql/table_ddl'
|
18
19
|
require 'flydata-core/fluent/config_helper'
|
19
20
|
require 'flydata-core/mysql/ssl'
|
20
|
-
require 'flydata/fluent-plugins/flydata_plugin_ext/flydata_sync'
|
21
21
|
|
22
22
|
|
23
23
|
class MysqlBinlogFlydataInput < MysqlBinlogInput
|
@@ -26,11 +26,9 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
26
26
|
|
27
27
|
Plugin.register_input('mysql_binlog_flydata', self)
|
28
28
|
|
29
|
-
BINLOG_POSITION_FILE_CLASS =
|
29
|
+
BINLOG_POSITION_FILE_CLASS = Flydata::SourceMysql::PluginSupport::BinLogPositionFile
|
30
30
|
|
31
31
|
config_param :database, :string
|
32
|
-
config_param :tables, :string
|
33
|
-
config_param :tables_append_only, :string
|
34
32
|
config_param :initial_idle_interval, :integer, :default => 30 # 30 sec
|
35
33
|
config_param :continuous_idle_interval, :integer, :default => 600 # 10 min
|
36
34
|
config_param :idle_timeout, :time, :default => 1800 # 30 min
|
@@ -51,7 +49,7 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
51
49
|
# Supported ssl cipher list for mysql(openssl)
|
52
50
|
# https://dev.mysql.com/doc/refman/5.6/en/ssl-options.html
|
53
51
|
|
54
|
-
config_param :secondary_ssl_cipher, :string, :
|
52
|
+
config_param :secondary_ssl_cipher, :string, default: FlydataCore::Mysql::Ssl::NON_DH_SSL_CIPHER
|
55
53
|
|
56
54
|
def configure(conf)
|
57
55
|
super
|
@@ -77,7 +75,7 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
77
75
|
#exit 1 # causes retry loop
|
78
76
|
end
|
79
77
|
|
80
|
-
table_meta = Flydata::
|
78
|
+
table_meta = Flydata::SourceMysql::PluginSupport::TableMeta.new(@db_opts.merge(tables: @tables))
|
81
79
|
|
82
80
|
table_revs = tables.inject({}) do |h, table_name|
|
83
81
|
h[table_name] = @sync_fm.table_rev(table_name)
|
@@ -85,12 +83,12 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
85
83
|
end
|
86
84
|
|
87
85
|
# Set context
|
88
|
-
@context =
|
86
|
+
@context = Flydata::SourceMysql::PluginSupport::Context.new(
|
89
87
|
database: @database, tables: @tables,
|
90
88
|
tag: @tag, sync_fm: @sync_fm, omit_events: @omit_events,
|
91
89
|
table_meta: table_meta, table_revs: table_revs,
|
92
90
|
)
|
93
|
-
@record_dispatcher =
|
91
|
+
@record_dispatcher = Flydata::SourceMysql::PluginSupport::FlydataBinlogRecordDispatcher.new(@context)
|
94
92
|
@idle_event_detector = IdleEventDetector.new(@initial_idle_interval, @continuous_idle_interval, @check_interval, @idle_timeout)
|
95
93
|
end
|
96
94
|
|
@@ -184,6 +182,9 @@ EOS
|
|
184
182
|
elsif /binlog file.*does not exist/.match(e.to_s)
|
185
183
|
$log.error("#{e.to_s}. Sync must be reset. Terminating the agent.")
|
186
184
|
Process.kill(:TERM, Process.ppid)
|
185
|
+
elsif e.kind_of?(Kodama::ConnectionEstablishError)
|
186
|
+
$log.error("#{e.to_s}. Connection to MySQL server could not be established. Terminating the agent.")
|
187
|
+
Process.kill(:TERM, Process.ppid)
|
187
188
|
else
|
188
189
|
raise e
|
189
190
|
end
|
@@ -228,8 +229,8 @@ EOS
|
|
228
229
|
begin
|
229
230
|
@kodama_client.stop_request
|
230
231
|
if wait_till_safe_to_stop
|
231
|
-
|
232
|
-
|
232
|
+
@thread.join
|
233
|
+
$log.info "Kodama has stopped successfully"
|
233
234
|
else
|
234
235
|
$log.error "Unable to stop Kodama"
|
235
236
|
end
|