flydata 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/serverinfo +4 -0
- data/flydata.gemspec +4 -3
- data/lib/flydata/cli.rb +5 -1
- data/lib/flydata/command/setup.rb +11 -0
- data/lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb +17 -6
- data/lib/flydata/helpers.rb +15 -10
- data/lib/flydata/parser/mysql/mysql_alter_table.treetop +1 -1
- data/spec/flydata/fluent-plugins/mysql/alter_table_query_handler_spec.rb +79 -0
- data/spec/flydata/parser/mysql/alter_table_parser_spec.rb +16 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0c1397fca1de7c4cb3382fcf4278e03de645693
|
4
|
+
data.tar.gz: 533850a6c296ca0df8ba934ec277e99b5b155bd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15180ce5c9fd332023fbaefb28dc290a144885d23e8e1bc1d12a542dadece366da16c8f6c2078f3c3b405db25010c67b2ad372ba8a4f8cc97ee59703828f351f
|
7
|
+
data.tar.gz: 4a1c28339d84a87d19304ca7a4e85239dbadbbdda4009a08a1d14add1af58c38238626042996524310a2f994891cacf195aaed06edc59c7ac6b38a80d336f143
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/bin/serverinfo
CHANGED
data/flydata.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: flydata 0.2.
|
5
|
+
# stub: flydata 0.2.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "flydata"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Koichi Fujikawa"]
|
14
|
-
s.date = "2014-09-
|
14
|
+
s.date = "2014-09-16"
|
15
15
|
s.description = "FlyData Command Line Interface"
|
16
16
|
s.email = "sysadmin@flydata.co"
|
17
17
|
s.executables = ["fdmysqldump", "flydata", "serverinfo"]
|
@@ -87,6 +87,7 @@ Gem::Specification.new do |s|
|
|
87
87
|
"spec/flydata/command/sender_spec.rb",
|
88
88
|
"spec/flydata/command/sync_spec.rb",
|
89
89
|
"spec/flydata/fluent-plugins/in_mysql_binlog_flydata_spec.rb",
|
90
|
+
"spec/flydata/fluent-plugins/mysql/alter_table_query_handler_spec.rb",
|
90
91
|
"spec/flydata/fluent-plugins/mysql/binlog_position_spec.rb",
|
91
92
|
"spec/flydata/heroku_spec.rb",
|
92
93
|
"spec/flydata/parser/mysql/alter_table_parser_spec.rb",
|
data/lib/flydata/cli.rb
CHANGED
@@ -16,7 +16,11 @@ module Flydata
|
|
16
16
|
if @args.size > 0
|
17
17
|
first_arg = @args.shift
|
18
18
|
cmd, sub_cmd = parse_command(first_arg)
|
19
|
-
|
19
|
+
begin
|
20
|
+
cmd_cls = "Flydata::Command::#{cmd.capitalize}".constantize
|
21
|
+
rescue
|
22
|
+
raise "Command not found: #{cmd}"
|
23
|
+
end
|
20
24
|
# Command class can define options for each subcommand by defining method "slop_subcommandname"
|
21
25
|
slop_method = sub_cmd ? "slop_#{sub_cmd}".to_sym : :slop
|
22
26
|
options = cmd_cls.respond_to?(slop_method) ? cmd_cls.send(slop_method) : Slop.new(strict: true)
|
@@ -27,6 +27,7 @@ following from the command line.
|
|
27
27
|
|
28
28
|
$ source ~/.bashrc
|
29
29
|
|
30
|
+
|
30
31
|
What's next?
|
31
32
|
|
32
33
|
- Check data on Redshift (%s)
|
@@ -43,6 +44,11 @@ Thank you for using FlyData!
|
|
43
44
|
INITIAL_SYNC_MESSAGE_TEMPLATE = <<-EOM
|
44
45
|
FlyData Agent has been installed on your server successfully.
|
45
46
|
|
47
|
+
To complete your installation and to add the `flydata` command, please run the
|
48
|
+
following from the command line.
|
49
|
+
|
50
|
+
$ source ~/.bashrc
|
51
|
+
|
46
52
|
|
47
53
|
What's next?
|
48
54
|
|
@@ -63,6 +69,11 @@ What's next?
|
|
63
69
|
NO_DE_SYNC_CANCEL_MESSAGE_TEMPLATE = <<-EOM
|
64
70
|
FlyData Agent has been installed on your server successfully.
|
65
71
|
|
72
|
+
To complete your installation and to add the `flydata` command, please run the
|
73
|
+
following from the command line.
|
74
|
+
|
75
|
+
$ source ~/.bashrc
|
76
|
+
|
66
77
|
|
67
78
|
What's next?
|
68
79
|
|
@@ -15,13 +15,24 @@ module Mysql
|
|
15
15
|
|
16
16
|
def process(record, normalized_query)
|
17
17
|
emit_record(:alter_table, record, increment_table_rev: true) do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
nil
|
22
|
-
|
23
|
-
|
18
|
+
ret = nil
|
19
|
+
begin
|
20
|
+
result = ParserProvider.parser(:mysql, :mysql_alter_table).new.parse(record['query'])
|
21
|
+
if result.nil?
|
22
|
+
$log.warn("Received unsupported alter table query. query:'#{record['query']}'")
|
23
|
+
else
|
24
|
+
ret = result.tree
|
25
|
+
end
|
26
|
+
rescue => e
|
27
|
+
msg = <<EOS
|
28
|
+
Received unsupported alter table query. query:'#{record['query']}'
|
29
|
+
Caused by error '#{e.to_s}'
|
30
|
+
Stacktrace :
|
31
|
+
#{e.backtrace.join("\n")}
|
32
|
+
EOS
|
33
|
+
$log.error(msg)
|
24
34
|
end
|
35
|
+
ret
|
25
36
|
end
|
26
37
|
end
|
27
38
|
end
|
data/lib/flydata/helpers.rb
CHANGED
@@ -18,25 +18,30 @@ module Flydata
|
|
18
18
|
|
19
19
|
def usage_text
|
20
20
|
text = ""
|
21
|
+
text += <<-EOM
|
22
|
+
Fix the issue and try again. If the problem continues, please contact support@flydata.com
|
23
|
+
|
24
|
+
EOM
|
25
|
+
flydata_log = File.join(FLYDATA_HOME, 'flydata.log')
|
26
|
+
if File.exists?(flydata_log)
|
27
|
+
text += <<-EOM
|
28
|
+
Also check the Agent log.
|
29
|
+
Log path: #{flydata_log}
|
30
|
+
EOM
|
31
|
+
end
|
32
|
+
text += ""
|
21
33
|
text += '-' * 64
|
22
34
|
text += "\n"
|
23
35
|
text += <<-EOM
|
24
36
|
Usage: flydata COMMAND
|
25
|
-
setup # setup initially
|
26
37
|
start # start flydata process
|
27
38
|
stop # stop flydata process
|
28
39
|
restart # restart flydata process
|
29
40
|
status # check flydata process
|
30
41
|
conf # show configuration
|
31
|
-
sync
|
32
|
-
|
33
|
-
|
34
|
-
please setup flydata again by following commands.
|
35
|
-
source ~/.bashrc
|
36
|
-
flydata setup
|
37
|
-
|
38
|
-
You can check the logs of sender(flydata) process.
|
39
|
-
Log path: #{File.join(FLYDATA_HOME, 'flydata.log')}
|
42
|
+
sync [tables] # initial sync (only for mysql database)
|
43
|
+
sync:generate_table_ddl [tables] # Generate CREATE TABLE script for Redshift
|
44
|
+
sync:reset [tables] # reset sync
|
40
45
|
EOM
|
41
46
|
text += "\n"
|
42
47
|
text += '-' * 64
|
@@ -196,7 +196,7 @@ grammar MysqlAlterTable
|
|
196
196
|
|
197
197
|
rule null_opt
|
198
198
|
'not'i sp 'null'i { def null_opt_option; { not_null: true }; end }
|
199
|
-
/
|
199
|
+
/ 'null'i { def null_opt_option; { }; end }
|
200
200
|
end
|
201
201
|
rule default_opt
|
202
202
|
'default'i sp default_value { def default_opt_option; { default: default_value.default_value }; end }
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'flydata/fluent-plugins/mysql/alter_table_query_handler'
|
3
|
+
|
4
|
+
module Mysql
|
5
|
+
describe AlterTableQueryHandler do
|
6
|
+
let(:sync_fm) do
|
7
|
+
r = double('sync_fm')
|
8
|
+
allow(r).to receive(:get_table_binlog_pos).and_return("mysql-bin.000065\t120")
|
9
|
+
r
|
10
|
+
end
|
11
|
+
let(:database) { "testdb" }
|
12
|
+
let(:table) { "foo" }
|
13
|
+
let(:context) do
|
14
|
+
r = double('context')
|
15
|
+
allow(r).to receive(:sync_fm).and_return(sync_fm)
|
16
|
+
allow(r).to receive(:database).and_return([database])
|
17
|
+
allow(r).to receive(:tables).and_return([table])
|
18
|
+
r
|
19
|
+
end
|
20
|
+
subject { described_class.new(context) }
|
21
|
+
describe '#process' do
|
22
|
+
let(:query) { "a_query" }
|
23
|
+
let(:record) do
|
24
|
+
r = double('record')
|
25
|
+
allow(r).to receive(:[]).with("db_name").and_return(database)
|
26
|
+
allow(r).to receive(:[]).with("query").and_return(query)
|
27
|
+
allow(r).to receive(:[]).with("table_name").and_return(table)
|
28
|
+
r
|
29
|
+
end
|
30
|
+
let(:normalized_query) { double('normalized_query') }
|
31
|
+
let(:parse_result) do
|
32
|
+
r = double('parse_result')
|
33
|
+
r
|
34
|
+
end
|
35
|
+
let(:parser) do
|
36
|
+
r = double('parser')
|
37
|
+
allow(r).to receive(:parse).and_return(parse_result)
|
38
|
+
r
|
39
|
+
end
|
40
|
+
before do
|
41
|
+
allow(MysqlAlterTableParser).to receive(:new).and_return(parser)
|
42
|
+
allow(subject).to receive(:acceptable_table?).and_return(true)
|
43
|
+
allow(subject).to receive(:acceptable_db?).and_return(true)
|
44
|
+
allow(subject).to receive(:check_empty_binlog)
|
45
|
+
end
|
46
|
+
shared_examples "a process method receiving an exception" do
|
47
|
+
let(:an_error) { "an error" }
|
48
|
+
it "returns nil with an error log" do
|
49
|
+
expect($log).to receive(:error).with(/Received unsupported alter table query.*Caused by error '#{an_error}'/m)
|
50
|
+
|
51
|
+
expect(subject.process(record, normalized_query)).to eq(nil)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the parser#parse throws an exception" do
|
56
|
+
before do
|
57
|
+
expect(parser).to receive(:parse).and_raise(RuntimeError.new(an_error))
|
58
|
+
end
|
59
|
+
it_behaves_like "a process method receiving an exception"
|
60
|
+
end
|
61
|
+
context "when the parse result throws an exception" do
|
62
|
+
before do
|
63
|
+
expect(parse_result).to receive(:tree).and_raise(RuntimeError.new(an_error))
|
64
|
+
end
|
65
|
+
it_behaves_like "a process method receiving an exception"
|
66
|
+
end
|
67
|
+
context "when the parse result is nil" do
|
68
|
+
before do
|
69
|
+
expect(parser).to receive(:parse).and_return(nil)
|
70
|
+
end
|
71
|
+
it "returns nil with a warn log" do
|
72
|
+
expect($log).to receive(:warn).with(/Received unsupported alter table query\. query:'#{query}'/)
|
73
|
+
|
74
|
+
expect(subject.process(record, normalized_query)).to eq(nil)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -225,8 +225,23 @@ describe 'MysqlAlterTableParser' do
|
|
225
225
|
})
|
226
226
|
end
|
227
227
|
end
|
228
|
-
end
|
229
228
|
|
229
|
+
context 'with null option' do
|
230
|
+
let(:length) { 45 }
|
231
|
+
let(:query) { "alter table test_table add column extra varchar(#{length}) null" }
|
232
|
+
it do
|
233
|
+
expect(subject).to eq({
|
234
|
+
type: :alter_table,
|
235
|
+
table_name: "test_table",
|
236
|
+
actions: [{
|
237
|
+
action: :add_column,
|
238
|
+
column: "extra",
|
239
|
+
type: "varchar(#{length * 3})",
|
240
|
+
}]
|
241
|
+
})
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
230
245
|
|
231
246
|
context 'with alter table drop column syntax' do
|
232
247
|
let(:query) { "alter table test_table drop column value" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flydata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi Fujikawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -452,6 +452,7 @@ files:
|
|
452
452
|
- spec/flydata/command/sender_spec.rb
|
453
453
|
- spec/flydata/command/sync_spec.rb
|
454
454
|
- spec/flydata/fluent-plugins/in_mysql_binlog_flydata_spec.rb
|
455
|
+
- spec/flydata/fluent-plugins/mysql/alter_table_query_handler_spec.rb
|
455
456
|
- spec/flydata/fluent-plugins/mysql/binlog_position_spec.rb
|
456
457
|
- spec/flydata/heroku_spec.rb
|
457
458
|
- spec/flydata/parser/mysql/alter_table_parser_spec.rb
|