flydata 0.4.0 → 0.4.1
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 +2 -2
- data/VERSION +1 -1
- data/flydata-core/lib/flydata-core/errors.rb +12 -0
- data/{lib/flydata/mysql/mysql_util.rb → flydata-core/lib/flydata-core/mysql/command_generator.rb} +39 -6
- data/flydata-core/lib/flydata-core/mysql/compatibility_checker.rb +222 -0
- data/flydata-core/lib/flydata-core/query_job.rb +7 -0
- data/flydata-core/lib/flydata-core/query_job/redshift.rb +27 -0
- data/{spec/flydata/mysql/mysql_util_spec.rb → flydata-core/spec/mysql/command_generator_spec.rb} +22 -3
- data/flydata-core/spec/mysql/compatibility_checker.rb +9 -0
- data/flydata-core/spec/query_job/redshift_spec.rb +34 -0
- data/flydata.gemspec +14 -9
- data/lib/flydata/api/data_entry.rb +9 -0
- data/lib/flydata/command/mysql.rb +2 -1
- data/lib/flydata/command/sync.rb +62 -31
- data/lib/flydata/compatibility_check.rb +33 -152
- data/lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb +4 -4
- data/lib/flydata/mysql/table_ddl.rb +2 -2
- data/lib/flydata/parser/mysql/dump_parser.rb +2 -2
- data/spec/flydata/command/sync_spec.rb +17 -15
- data/spec/flydata/compatibility_check_spec.rb +13 -12
- data/spec/flydata/mysql/table_ddl_spec.rb +1 -1
- metadata +12 -7
@@ -9,7 +9,7 @@ lib = File.expand_path(File.join(File.dirname(__FILE__), '../../'))
|
|
9
9
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
10
10
|
require 'flydata'
|
11
11
|
require 'flydata/sync_file_manager'
|
12
|
-
require 'flydata/mysql/
|
12
|
+
require 'flydata-core/mysql/command_generator'
|
13
13
|
require 'flydata/fluent-plugins/preference'
|
14
14
|
require 'flydata/fluent-plugins/mysql/binlog_position_file'
|
15
15
|
require 'flydata/fluent-plugins/mysql/binlog_record_dispatcher'
|
@@ -53,8 +53,8 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
53
53
|
config_param :tables, :string
|
54
54
|
config_param :tables_append_only, :string
|
55
55
|
config_param :initial_idle_interval, :integer, :default => 30 # 30 sec
|
56
|
-
config_param :continuous_idle_interval, :integer, :default => 600 #
|
57
|
-
config_param :idle_timeout, :time, :default =>
|
56
|
+
config_param :continuous_idle_interval, :integer, :default => 600 # 10 min
|
57
|
+
config_param :idle_timeout, :time, :default => 1800 # 30 min
|
58
58
|
config_param :check_interval, :integer, :default => 5 # 5 sec
|
59
59
|
config_param :ssl_ca_content, :string, :default => ''
|
60
60
|
|
@@ -81,7 +81,7 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
81
81
|
|
82
82
|
$log.info "mysql host:\"#{@host}\" port:\"#{@port}\" username:\"#{@username}\" database:\"#{@database}\" tables:\"#{@tables}\" tables_append_only:\"#{tables_append_only}\""
|
83
83
|
$log.info "mysql client version: #{`mysql -V`}"
|
84
|
-
server_msg = `echo 'select version();' | #{
|
84
|
+
server_msg = `echo 'select version();' | #{FlydataCore::Mysql::CommandGenerator.generate_mysql_cmd(@db_opts)} 2>&1`
|
85
85
|
server_msg = server_msg.each_line.select{|l| l.start_with?('ERROR ')}.join("\n")
|
86
86
|
if ($?.exitstatus == 0)
|
87
87
|
$log.info "mysql server version: #{server_msg.strip}"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'flydata/mysql/binlog_position'
|
2
|
-
require 'flydata/mysql/
|
2
|
+
require 'flydata-core/mysql/command_generator'
|
3
3
|
|
4
4
|
module Flydata
|
5
5
|
module Mysql
|
@@ -50,7 +50,7 @@ EOS
|
|
50
50
|
next if version >= V2_TARGET_VERSION
|
51
51
|
|
52
52
|
if mysql_tabledefs.nil?
|
53
|
-
|
53
|
+
FlydataCore::Mysql::CommandGenerator.each_mysql_tabledef(tables, mysql_opts) do |mysql_tabledef, error|
|
54
54
|
raise error if error
|
55
55
|
|
56
56
|
mysql_tabledefs ||= {}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'fiber'
|
2
2
|
require 'io/wait'
|
3
|
-
require 'flydata/mysql/
|
3
|
+
require 'flydata-core/mysql/command_generator'
|
4
4
|
|
5
5
|
module Flydata
|
6
6
|
module Parser
|
@@ -141,7 +141,7 @@ module Flydata
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def generate_dump_cmd(conf, file_path = nil)
|
144
|
-
|
144
|
+
FlydataCore::Mysql::CommandGenerator.generate_mysqldump_without_master_data_cmd(conf.merge(result_file: file_path))
|
145
145
|
end
|
146
146
|
|
147
147
|
private
|
@@ -33,7 +33,8 @@ module Flydata
|
|
33
33
|
"data_port_key"=>"a458c641",
|
34
34
|
"mysql_data_entry_preference" =>
|
35
35
|
{ "host"=>"localhost", "port"=>3306, "username"=>"masashi",
|
36
|
-
"password"=>"welcome", "database"=>"sync_test", "tables"=>["table1", "
|
36
|
+
"password"=>"welcome", "database"=>"sync_test", "tables"=>["table1", "table2"],
|
37
|
+
"invalid_tables"=>["table3"],
|
37
38
|
"mysqldump_dir"=>default_mysqldump_dir, "forwarder" => "tcpforwarder",
|
38
39
|
"data_servers"=>"localhost:9905" }
|
39
40
|
}
|
@@ -136,7 +137,8 @@ module Flydata
|
|
136
137
|
describe '#do_generate_table_ddl' do
|
137
138
|
before do
|
138
139
|
allow(subject).to receive(:data_entry).and_return(default_data_entry)
|
139
|
-
|
140
|
+
allow_any_instance_of(Flydata::Api::DataEntry).to receive(:update_table_validity).and_return(true)
|
141
|
+
subject.send(:set_current_tables, nil, include_invalid_tables: true)
|
140
142
|
end
|
141
143
|
shared_examples 'throws an error' do
|
142
144
|
it "throws an error" do
|
@@ -148,7 +150,7 @@ module Flydata
|
|
148
150
|
context 'with full options' do
|
149
151
|
it 'issues mysqldump command with expected parameters' do
|
150
152
|
expect(Open3).to receive(:popen3).with(
|
151
|
-
'mysqldump -h localhost -P 3306 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1
|
153
|
+
'mysqldump -h localhost -P 3306 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3')
|
152
154
|
subject.send(:do_generate_table_ddl, default_data_entry)
|
153
155
|
end
|
154
156
|
end
|
@@ -170,7 +172,7 @@ module Flydata
|
|
170
172
|
end
|
171
173
|
it "uses the default port" do
|
172
174
|
expect(Open3).to receive(:popen3).with(
|
173
|
-
'mysqldump -h localhost -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1
|
175
|
+
'mysqldump -h localhost -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3')
|
174
176
|
subject.send(:do_generate_table_ddl, default_data_entry)
|
175
177
|
end
|
176
178
|
end
|
@@ -180,7 +182,7 @@ module Flydata
|
|
180
182
|
end
|
181
183
|
it "uses the specified port" do
|
182
184
|
expect(Open3).to receive(:popen3).with(
|
183
|
-
'mysqldump -h localhost -P 1234 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1
|
185
|
+
'mysqldump -h localhost -P 1234 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3')
|
184
186
|
subject.send(:do_generate_table_ddl, default_data_entry)
|
185
187
|
end
|
186
188
|
end
|
@@ -202,7 +204,7 @@ module Flydata
|
|
202
204
|
end
|
203
205
|
it "call mysqldump without MYSQL_PW set" do
|
204
206
|
expect(Open3).to receive(:popen3).with(
|
205
|
-
'mysqldump -h localhost -P 3306 -umasashi --default-character-set=utf8 --protocol=tcp -d sync_test table1
|
207
|
+
'mysqldump -h localhost -P 3306 -umasashi --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3')
|
206
208
|
subject.send(:do_generate_table_ddl, default_data_entry)
|
207
209
|
end
|
208
210
|
end
|
@@ -213,7 +215,7 @@ module Flydata
|
|
213
215
|
end
|
214
216
|
it "call mysqldump with MYSQL_PW set with correct symbols" do
|
215
217
|
expect(Open3).to receive(:popen3).with(
|
216
|
-
'mysqldump -h localhost -P 3306 -umasashi -p"welcome&!@^@#^" --default-character-set=utf8 --protocol=tcp -d sync_test table1
|
218
|
+
'mysqldump -h localhost -P 3306 -umasashi -p"welcome&!@^@#^" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3')
|
217
219
|
subject.send(:do_generate_table_ddl, default_data_entry)
|
218
220
|
end
|
219
221
|
end
|
@@ -229,17 +231,17 @@ module Flydata
|
|
229
231
|
end
|
230
232
|
include_examples 'throws an error'
|
231
233
|
end
|
232
|
-
context 'without_tables' do
|
233
|
-
before do
|
234
|
-
default_data_entry['mysql_data_entry_preference'].delete('tables')
|
235
|
-
end
|
236
|
-
include_examples 'throws an error'
|
237
|
-
end
|
238
234
|
context 'with empty tables' do
|
235
|
+
let(:sync_cmd) { described_class.new }
|
239
236
|
before do
|
240
|
-
default_data_entry['mysql_data_entry_preference']['tables'] =
|
237
|
+
default_data_entry['mysql_data_entry_preference']['tables'] = []
|
238
|
+
default_data_entry['mysql_data_entry_preference']['invalid_tables'] = []
|
239
|
+
allow(sync_cmd).to receive(:data_entry).and_return(default_data_entry)
|
240
|
+
sync_cmd.send(:set_current_tables, nil, include_invalid_tables: true)
|
241
|
+
end
|
242
|
+
it 'should raise error' do
|
243
|
+
expect{sync_cmd.send(:do_generate_table_ddl, default_data_entry)}.to raise_error
|
241
244
|
end
|
242
|
-
include_examples 'throws an error'
|
243
245
|
end
|
244
246
|
end
|
245
247
|
describe '#convert_to_flydata_values' do
|
@@ -27,7 +27,7 @@ module Flydata
|
|
27
27
|
allow(TCPSocket).to receive(:new).and_raise(Errno::ETIMEDOUT)
|
28
28
|
end
|
29
29
|
it do
|
30
|
-
expect{subject.check_outgoing_ports}.to raise_error(
|
30
|
+
expect{subject.check_outgoing_ports}.to raise_error(FlydataCore::AgentCompatibilityError, /ports/)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -73,7 +73,7 @@ module Flydata
|
|
73
73
|
{"Grants for test"=>"GRANT SELECT, RELOAD, REPLICATION CLIENT ON `test_db`.* TO 'test'@'host"}])
|
74
74
|
end
|
75
75
|
it do
|
76
|
-
expect{subject.check_mysql_user_compat}.to raise_error(
|
76
|
+
expect{subject.check_mysql_user_compat}.to raise_error(FlydataCore::MysqlCompatibilityError, /test_db': LOCK TABLES, REPLICATION SLAVE/)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
context "with all required privileges in between all and specific databases" do
|
@@ -93,7 +93,7 @@ module Flydata
|
|
93
93
|
{"Grants for test"=>"GRANT SELECT, LOCK TABLES ON `mysql`.* TO 'test'@'host"}])
|
94
94
|
end
|
95
95
|
it do
|
96
|
-
expect{subject.check_mysql_user_compat}.to raise_error(
|
96
|
+
expect{subject.check_mysql_user_compat}.to raise_error(FlydataCore::MysqlCompatibilityError, /mysql': RELOAD\n.*test_db': RELOAD/)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
context "with all required privileges in all databases" do
|
@@ -109,7 +109,7 @@ module Flydata
|
|
109
109
|
allow(client).to receive(:query).and_return([{"Grants for test"=>"GRANT RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'host"}])
|
110
110
|
end
|
111
111
|
it do
|
112
|
-
expect{subject.check_mysql_user_compat}.to raise_error(
|
112
|
+
expect{subject.check_mysql_user_compat}.to raise_error(FlydataCore::MysqlCompatibilityError, /mysql': SELECT, LOCK TABLES\n.*test_db': SELECT, LOCK TABLES/)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
context "with privileges for other databases only" do
|
@@ -119,7 +119,7 @@ module Flydata
|
|
119
119
|
{"Grants for test"=>"GRANT SELECT ON `text_db_03`.* TO 'test'@'host"}])
|
120
120
|
end
|
121
121
|
it do
|
122
|
-
expect{subject.check_mysql_user_compat}.to raise_error(
|
122
|
+
expect{subject.check_mysql_user_compat}.to raise_error(FlydataCore::MysqlCompatibilityError, /mysql': SELECT, RELOAD, LOCK TABLES, REPLICATION SLAVE, REPLICATION CLIENT\n.*test_db': SELECT, RELOAD, LOCK TABLES, REPLICATION SLAVE, REPLICATION CLIENT/)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -132,19 +132,19 @@ module Flydata
|
|
132
132
|
let(:client) { double('client') }
|
133
133
|
before do
|
134
134
|
allow(Mysql2::Client).to receive(:new).and_return(client)
|
135
|
-
allow(client).to receive(:query).and_return([{"
|
135
|
+
allow(client).to receive(:query).and_return([{"Variable_name" => "expire_logs_days", "Value" => 1}])
|
136
136
|
allow(client).to receive(:close)
|
137
137
|
allow(subject).to receive(:is_rds?).and_return(false)
|
138
138
|
end
|
139
139
|
it do
|
140
|
-
expect{subject.check_mysql_binlog_retention}.to raise_error(
|
140
|
+
expect{subject.check_mysql_binlog_retention}.to raise_error(FlydataCore::MysqlCompatibilityError, /expire_logs_days/)
|
141
141
|
end
|
142
142
|
end
|
143
143
|
context "where retention is 0" do
|
144
144
|
let(:client) { double('client') }
|
145
145
|
before do
|
146
146
|
allow(Mysql2::Client).to receive(:new).and_return(client)
|
147
|
-
allow(client).to receive(:query).and_return([{"
|
147
|
+
allow(client).to receive(:query).and_return([{"Variable_name" => "expire_logs_days", "Value" => 0}])
|
148
148
|
allow(client).to receive(:close)
|
149
149
|
allow(subject).to receive(:is_rds?).and_return(false)
|
150
150
|
end
|
@@ -156,7 +156,8 @@ module Flydata
|
|
156
156
|
let(:client) { double('client') }
|
157
157
|
before do
|
158
158
|
allow(Mysql2::Client).to receive(:new).and_return(client)
|
159
|
-
allow(client).to receive(:query).and_return([{"
|
159
|
+
allow(client).to receive(:query).and_return([{"expire_logs_days"=>11}])
|
160
|
+
allow(client).to receive(:query).and_return([{"Variable_name" => "expire_logs_days", "Value" => 11}])
|
160
161
|
allow(client).to receive(:close)
|
161
162
|
allow(subject).to receive(:is_rds?).and_return(false)
|
162
163
|
end
|
@@ -177,7 +178,7 @@ module Flydata
|
|
177
178
|
allow(subject).to receive(:is_rds?).and_return(true)
|
178
179
|
end
|
179
180
|
it do
|
180
|
-
expect{subject.check_mysql_binlog_retention}.to raise_error(
|
181
|
+
expect{subject.check_mysql_binlog_retention}.to raise_error(FlydataCore::MysqlCompatibilityError, /rds_set_config/)
|
181
182
|
end
|
182
183
|
end
|
183
184
|
context "where retention period is too low" do
|
@@ -190,7 +191,7 @@ module Flydata
|
|
190
191
|
allow(subject).to receive(:is_rds?).and_return(true)
|
191
192
|
end
|
192
193
|
it do
|
193
|
-
expect{subject.check_mysql_binlog_retention}.to raise_error(
|
194
|
+
expect{subject.check_mysql_binlog_retention}.to raise_error(FlydataCore::MysqlCompatibilityError, /rds_set_config/)
|
194
195
|
end
|
195
196
|
end
|
196
197
|
context "where retention period is over recommended limit" do
|
@@ -236,7 +237,7 @@ module Flydata
|
|
236
237
|
let(:view) { {"table_name"=>"view_table", "table_type"=>"VIEW", "engine"=>nil} }
|
237
238
|
let(:client) { double('client') }
|
238
239
|
let(:subject_object) { MysqlCompatibilityCheck.new(default_data_port,test_data_entry, {}) }
|
239
|
-
let(:error) {
|
240
|
+
let(:error) { FlydataCore::MysqlCompatibilityError }
|
240
241
|
let(:base_error_msg) { "FlyData does not support VIEW and MEMORY ENGINE table. Remove following tables from data entry: %s" }
|
241
242
|
subject { subject_object.check_mysql_table_types }
|
242
243
|
before do
|
@@ -80,7 +80,7 @@ describe TableDdl do
|
|
80
80
|
it do
|
81
81
|
matcher = receive(:each_mysql_tabledef).with(table_names, mysql_opts)
|
82
82
|
matcher = table_names.inject(matcher) {|m, tn| m.and_yield(mysql_tabledef[tn], nil) }
|
83
|
-
expect(
|
83
|
+
expect(FlydataCore::Mysql::CommandGenerator).to matcher
|
84
84
|
expect(File).to receive(:open).with(position_file).and_return(master_binlog_position)
|
85
85
|
expect(context).to receive(:current_binlog_file).and_return(original_current_binlog_file)
|
86
86
|
expect(context).to receive(:current_binlog_file=).with(binlog_file)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flydata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi Fujikawa
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2015-06-
|
15
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rest-client
|
@@ -248,7 +248,7 @@ dependencies:
|
|
248
248
|
requirements:
|
249
249
|
- - '>='
|
250
250
|
- !ruby/object:Gem::Version
|
251
|
-
version: 0.1.
|
251
|
+
version: 0.1.6
|
252
252
|
- - ~>
|
253
253
|
- !ruby/object:Gem::Version
|
254
254
|
version: 0.1.2
|
@@ -258,7 +258,7 @@ dependencies:
|
|
258
258
|
requirements:
|
259
259
|
- - '>='
|
260
260
|
- !ruby/object:Gem::Version
|
261
|
-
version: 0.1.
|
261
|
+
version: 0.1.6
|
262
262
|
- - ~>
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: 0.1.2
|
@@ -484,6 +484,10 @@ files:
|
|
484
484
|
- flydata-core/lib/flydata-core/fluent-plugins/multi_buffer.rb
|
485
485
|
- flydata-core/lib/flydata-core/fluent/config_helper.rb
|
486
486
|
- flydata-core/lib/flydata-core/logger.rb
|
487
|
+
- flydata-core/lib/flydata-core/mysql/command_generator.rb
|
488
|
+
- flydata-core/lib/flydata-core/mysql/compatibility_checker.rb
|
489
|
+
- flydata-core/lib/flydata-core/query_job.rb
|
490
|
+
- flydata-core/lib/flydata-core/query_job/redshift.rb
|
487
491
|
- flydata-core/lib/flydata-core/record/record.rb
|
488
492
|
- flydata-core/lib/flydata-core/redshift/string.rb
|
489
493
|
- flydata-core/lib/flydata-core/table_def.rb
|
@@ -495,6 +499,9 @@ files:
|
|
495
499
|
- flydata-core/spec/config/user_maintenance_spec.rb
|
496
500
|
- flydata-core/spec/fluent/config_helper_spec.rb
|
497
501
|
- flydata-core/spec/logger_spec.rb
|
502
|
+
- flydata-core/spec/mysql/command_generator_spec.rb
|
503
|
+
- flydata-core/spec/mysql/compatibility_checker.rb
|
504
|
+
- flydata-core/spec/query_job/redshift_spec.rb
|
498
505
|
- flydata-core/spec/redshift/string_spec.rb
|
499
506
|
- flydata-core/spec/spec_helper.rb
|
500
507
|
- flydata-core/spec/table_def/autoload_redshift_table_def_spec.rb
|
@@ -582,7 +589,6 @@ files:
|
|
582
589
|
- lib/flydata/heroku/instance_methods.rb
|
583
590
|
- lib/flydata/log_monitor.rb
|
584
591
|
- lib/flydata/mysql/binlog_position.rb
|
585
|
-
- lib/flydata/mysql/mysql_util.rb
|
586
592
|
- lib/flydata/mysql/table_ddl.rb
|
587
593
|
- lib/flydata/output/forwarder.rb
|
588
594
|
- lib/flydata/parser/mysql/dump_parser.rb
|
@@ -638,7 +644,6 @@ files:
|
|
638
644
|
- spec/flydata/helper/worker_spec.rb
|
639
645
|
- spec/flydata/heroku_spec.rb
|
640
646
|
- spec/flydata/mysql/binlog_position_spec.rb
|
641
|
-
- spec/flydata/mysql/mysql_util_spec.rb
|
642
647
|
- spec/flydata/mysql/table_ddl_spec.rb
|
643
648
|
- spec/flydata/output/forwarder_spec.rb
|
644
649
|
- spec/flydata/parser/mysql/alter_table_parser_spec.rb
|
@@ -670,7 +675,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
670
675
|
version: '0'
|
671
676
|
requirements: []
|
672
677
|
rubyforge_project:
|
673
|
-
rubygems_version: 2.4.
|
678
|
+
rubygems_version: 2.4.6
|
674
679
|
signing_key:
|
675
680
|
specification_version: 4
|
676
681
|
summary: FlyData Agent
|