flydata 0.4.1 → 0.4.2
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/flydata.gemspec +3 -3
- data/lib/flydata/fluent-plugins/mysql/truncate_table_query_handler.rb +1 -1
- data/spec/flydata/fluent-plugins/mysql/binlog_query_dispatcher_spec.rb +34 -22
- data/spec/flydata/fluent-plugins/mysql/ddl_query_handler_spec.rb +24 -14
- data/spec/flydata/fluent-plugins/mysql/truncate_query_handler_spec.rb +57 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 281fa8038b28cccba7e12b76d72a5bab7af9d10b
|
4
|
+
data.tar.gz: 78895abe8bc0f92c7835ec9b0f7093e727a8b71f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d87649be6f3f5480fd1529e71a879c8b556f8a9d01aba06117d4a305883ae2734ca94e26d586d281af4aeda8bc2ac14e34e9064c1093bcae4a634559ddceebaf
|
7
|
+
data.tar.gz: bdba9b5af4a27d8129d2b8a7ff454de83daa2f6c09219a6a2d8bca09766fc86f473cd773a8575b2a52f65d3a23f6b27cbec057cb59ad3b454f5037c106be7ce4
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
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.4.
|
5
|
+
# stub: flydata 0.4.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "flydata"
|
9
|
-
s.version = "0.4.
|
9
|
+
s.version = "0.4.2"
|
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", "Masashi Miyazaki", "Matthew Luu", "Mak Inada", "Sriram NS"]
|
14
|
-
s.date = "2015-06-
|
14
|
+
s.date = "2015-06-23"
|
15
15
|
s.description = "FlyData Agent"
|
16
16
|
s.email = "sysadmin@flydata.com"
|
17
17
|
s.executables = ["fdmysqldump", "flydata", "serverinfo"]
|
@@ -51,12 +51,12 @@ EOT
|
|
51
51
|
end
|
52
52
|
let(:alter_query_handler) do
|
53
53
|
r = double('alter_query_handler')
|
54
|
-
allow(r).to receive(:pattern).and_return(
|
54
|
+
allow(r).to receive(:pattern).and_return(Mysql::AlterTableQueryHandler::PATTERN)
|
55
55
|
r
|
56
56
|
end
|
57
57
|
let(:truncate_query_handler) do
|
58
58
|
r = double('truncate_query_handler')
|
59
|
-
allow(r).to receive(:pattern).and_return(
|
59
|
+
allow(r).to receive(:pattern).and_return(Mysql::TruncateTableQueryHandler::PATTERN)
|
60
60
|
r
|
61
61
|
end
|
62
62
|
let(:context) { double('context') }
|
@@ -201,36 +201,48 @@ EOS
|
|
201
201
|
context "truncate table queries" do
|
202
202
|
let(:correct_query_handler) { truncate_query_handler }
|
203
203
|
|
204
|
-
|
205
|
-
|
206
|
-
|
204
|
+
shared_examples "truncate table tests" do
|
205
|
+
context "simple truncate query" do
|
206
|
+
let(:query) { <<EOS.gsub(/\n$/, '') }
|
207
|
+
TRUNCATE#{opt_table} users;
|
207
208
|
EOS
|
208
|
-
|
209
|
-
TRUNCATE
|
209
|
+
let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
|
210
|
+
TRUNCATE#{opt_table} users;
|
210
211
|
EOS
|
211
212
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
213
|
+
it_behaves_like "a dispatcher that calls query handler with correct query"
|
214
|
+
end
|
215
|
+
context "truncate query with dbname and table name and a comment in the beginning" do
|
216
|
+
let(:query) { <<EOS.gsub(/\n$/, '') }
|
216
217
|
# I am going to truncate this table
|
217
|
-
truncate
|
218
|
+
truncate#{opt_table} flydata_sync.users;
|
218
219
|
EOS
|
219
|
-
|
220
|
-
truncate
|
220
|
+
let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
|
221
|
+
truncate#{opt_table} flydata_sync.users;
|
221
222
|
EOS
|
222
223
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
truncate
|
224
|
+
it_behaves_like "a dispatcher that calls query handler with correct query"
|
225
|
+
end
|
226
|
+
context "truncate query with quoted dbname and table name with comments on the same line" do
|
227
|
+
let(:query) { <<EOS.gsub(/\n$/, '') }
|
228
|
+
truncate#{opt_table} `flydata_sync`.`users`; /* 無国籍 */ -- 'SJIS is トラブルメーカー'
|
228
229
|
EOS
|
229
|
-
|
230
|
-
truncate
|
230
|
+
let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
|
231
|
+
truncate#{opt_table} `flydata_sync`.`users`;
|
231
232
|
EOS
|
232
233
|
|
233
|
-
|
234
|
+
it_behaves_like "a dispatcher that calls query handler with correct query"
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context "with table key word" do
|
239
|
+
let(:opt_table) { " table" }
|
240
|
+
include_examples "truncate table tests"
|
241
|
+
end
|
242
|
+
|
243
|
+
context "without table key word" do
|
244
|
+
let(:opt_table) { "" }
|
245
|
+
include_examples "truncate table tests"
|
234
246
|
end
|
235
247
|
end
|
236
248
|
end
|
@@ -27,24 +27,34 @@ EOS
|
|
27
27
|
expect(subject.table_info(record)).to eq({db_name: "testdb2", table_name: "testtable2"})
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
shared_examples "truncate table queries" do
|
31
|
+
context "truncate table query with no db name" do
|
32
|
+
let(:normalized_query) { "TRUNCATE#{opt_table} apps ;" }
|
33
|
+
it do
|
34
|
+
expect(subject.table_info(record)).to eq({db_name: "testdb", table_name: "apps"})
|
35
|
+
end
|
34
36
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
context "truncate table query with db name" do
|
38
|
+
let(:normalized_query) { "truncate#{opt_table} `testdb1`.`apps1`;" }
|
39
|
+
it do
|
40
|
+
expect(subject.table_info(record)).to eq({db_name: "testdb1", table_name: "apps1"})
|
41
|
+
end
|
40
42
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
context "truncate table query with quoted db name" do
|
44
|
+
let(:normalized_query) { "truncate#{opt_table} testdb2.apps2;" }
|
45
|
+
it do
|
46
|
+
expect(subject.table_info(record)).to eq({db_name: "testdb2", table_name: "apps2"})
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
50
|
+
context "truncate table query with table key word" do
|
51
|
+
let(:opt_table) { " TABLE" }
|
52
|
+
include_examples "truncate table queries"
|
53
|
+
end
|
54
|
+
context "truncate table query without table key word" do
|
55
|
+
let(:opt_table) { "" }
|
56
|
+
include_examples "truncate table queries"
|
57
|
+
end
|
48
58
|
context "query does not match DDL_TABLE_QUERY" do #This should not happen, ideally
|
49
59
|
let(:normalized_query) { "CREATE TRIGGER mytrigger BEFORE INSERT ON TABLE_1 FOR EACH ROW SET NEW.MY_DATETIME_COLUMN = NOW();" }
|
50
60
|
it do
|
@@ -7,36 +7,71 @@ module Mysql
|
|
7
7
|
include_context "query handler context"
|
8
8
|
|
9
9
|
describe '#process' do
|
10
|
-
let(:truncate_query) { "TRUNCATE
|
11
|
-
|
12
|
-
{
|
13
|
-
table_name: table,
|
14
|
-
query: truncate_query,
|
15
|
-
type: :truncate_table,
|
16
|
-
respect_order: true,
|
17
|
-
src_pos: "#{current_binlog_file}\t#{next_position - event_length}",
|
18
|
-
table_rev: table_rev,
|
19
|
-
seq: seq,
|
20
|
-
v: flydata_record_version
|
21
|
-
}
|
22
|
-
end
|
10
|
+
let(:truncate_query) { "TRUNCATE table foo" }
|
11
|
+
|
23
12
|
before do
|
24
13
|
allow(record).to receive(:[]).with("query").and_return(truncate_query)
|
25
14
|
allow(record).to receive(:[]).with("normalized_query").and_return(truncate_query)
|
26
15
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
16
|
+
|
17
|
+
shared_examples "process truncate queries correctly" do
|
18
|
+
let(:expected_record) do
|
19
|
+
{
|
20
|
+
table_name: table,
|
21
|
+
query: truncate_query,
|
22
|
+
type: :truncate_table,
|
23
|
+
respect_order: true,
|
24
|
+
src_pos: "#{current_binlog_file}\t#{next_position - event_length}",
|
25
|
+
table_rev: table_rev,
|
26
|
+
seq: seq,
|
27
|
+
v: flydata_record_version
|
28
|
+
}
|
31
29
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
|
31
|
+
context "for a non append only table" do
|
32
|
+
it "should call Fluent's emit with appropriate params" do
|
33
|
+
expect(Fluent::Engine).to receive(:emit).with(tag, timestamp, expected_record)
|
34
|
+
expect(subject.process(record))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context "for an append only table" do
|
38
|
+
before do
|
39
|
+
allow(context).to receive(:omit_events).and_return({ table => [:delete, :truncate_table] })
|
40
|
+
end
|
41
|
+
it "should not call Fluent's emit" do
|
42
|
+
expect(Fluent::Engine).to receive(:emit).never
|
43
|
+
expect(subject.process(record))
|
44
|
+
end
|
36
45
|
end
|
46
|
+
end
|
47
|
+
|
48
|
+
shared_examples "skip processing queries" do
|
37
49
|
it "should not call Fluent's emit" do
|
38
50
|
expect(Fluent::Engine).to receive(:emit).never
|
39
|
-
|
51
|
+
subject.process(record)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "truncate queries with table keyword" do
|
56
|
+
let(:truncate_query) { "TRUNCATE table foo" }
|
57
|
+
include_examples "process truncate queries correctly"
|
58
|
+
end
|
59
|
+
context "truncate queries without table keyword" do
|
60
|
+
let(:truncate_query) { "TRUNCATE foo" }
|
61
|
+
include_examples "process truncate queries correctly"
|
62
|
+
end
|
63
|
+
context "truncate queries with db name" do
|
64
|
+
let(:table) { "var" }
|
65
|
+
let(:database) { "testdb" }
|
66
|
+
|
67
|
+
context 'when db exists' do
|
68
|
+
let(:truncate_query) { "TRUNCATE #{database}.#{table}" }
|
69
|
+
include_examples "process truncate queries correctly"
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when db doesn not exists' do
|
73
|
+
let(:truncate_query) { "TRUNCATE dummydb.#{table}" }
|
74
|
+
include_examples "skip processing queries"
|
40
75
|
end
|
41
76
|
end
|
42
77
|
end
|
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.2
|
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-23 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rest-client
|