flydata 0.2.25 → 0.2.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 950ac222e77c45b7dfb9a65f2921d612d78d0a56
4
- data.tar.gz: 50e414cced803f9a3ebf279ebef5c5b0409607b6
3
+ metadata.gz: e9ac346de420a785776ae309674640dd0afe3ff3
4
+ data.tar.gz: b9dcd9d82316b6906517ab008cc02e1024e8851e
5
5
  SHA512:
6
- metadata.gz: c9ead00fb45d5f022632e7e59d9b128e9c44b7878e85c6a9796aae0b77e9f5d41bcb83812ef5c32058a1372d5c87be5dc6e9febe4d6416d7e81e2ba8564c2dc3
7
- data.tar.gz: f1f36e0bb8354c5580e8be6df19f7f2bf4c23714420b28d9a0a74cd84d9d83dbc692c371503db66376dd42825d9ddab9ff505490f63169d11af818cb59f3b613
6
+ metadata.gz: f2c936dab2a85f0b2b575900218b03472874be5061c2dc72f89753f37ef7f166f31bfd4e4ffb1f47f367b12b1aac3367cc6d10f766a219a45831787456c512c8
7
+ data.tar.gz: 138786e380f022dd2ad70a3a96e20a88a379a36fb4ba1ed4636605d81a98c4f65ae86f4f143c87cc0ae09758c5a5a00487d2d60ff78327ceb1e8cfd58a6d8eb8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.25
1
+ 0.2.26
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.0.0-p481
@@ -40,6 +40,7 @@ class RedshiftTableDef
40
40
 
41
41
  begin
42
42
  tabledef = ""
43
+ tabledef += create_schema_sql(schema_name) if options[:flydata_ctl_table] && !schema_name.to_s.empty?
43
44
  tabledef += create_flydata_ctl_table_sql(schema_name) if options[:flydata_ctl_table]
44
45
  tabledef += create_table_sql(flydata_tabledef, schema_name) unless options[:ctl_only]
45
46
  tabledef += comment_sql(flydata_tabledef, schema_name) unless options[:ctl_only]
@@ -51,6 +52,9 @@ class RedshiftTableDef
51
52
  end
52
53
 
53
54
  FLYDATA_CTL_COLUMNS_TABLE = "flydata_ctl_columns"
55
+ CREATE_SCHEMA_SQL = <<EOS
56
+ CREATE SCHEMA "%s";
57
+ EOS
54
58
  CREATE_FLYDATA_CTL_TABLE_SQL = <<EOS
55
59
  CREATE TABLE %s(
56
60
  id integer NOT NULL IDENTITY(1,1),
@@ -71,6 +75,10 @@ EOS
71
75
  table_name_for_ddl(FLYDATA_CTL_COLUMNS_TABLE, schema_name)
72
76
  end
73
77
 
78
+ def self.create_schema_sql(schema_name)
79
+ CREATE_SCHEMA_SQL % schema_name
80
+ end
81
+
74
82
  def self.create_flydata_ctl_table_sql(schema_name)
75
83
  # No drop table here intentionally because losing the data is fatal.
76
84
  tbl = flydata_ctl_table_for_ddl(schema_name)
@@ -111,6 +111,7 @@ EOT
111
111
 
112
112
  it 'should preappend schema name to table name' do
113
113
  expect(subject).to eq( <<EOT.strip )
114
+ CREATE SCHEMA "test_schema";
114
115
  CREATE TABLE "test_schema"."flydata_ctl_columns"(
115
116
  id integer NOT NULL IDENTITY(1,1),
116
117
  table_name varchar(128) NOT NULL,
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.25 ruby lib
5
+ # stub: flydata 0.2.26 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "flydata"
9
- s.version = "0.2.25"
9
+ s.version = "0.2.26"
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 = "2014-12-21"
14
+ s.date = "2014-12-31"
15
15
  s.description = "FlyData Agent"
16
16
  s.email = "sysadmin@flydata.com"
17
17
  s.executables = ["fdmysqldump", "flydata", "serverinfo"]
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "flydata-core/.travis.yml",
36
36
  "flydata-core/Gemfile",
37
37
  "flydata-core/Gemfile.lock",
38
+ "flydata-core/circle.yml",
38
39
  "flydata-core/lib/flydata-core.rb",
39
40
  "flydata-core/lib/flydata-core/core_ext.rb",
40
41
  "flydata-core/lib/flydata-core/core_ext/module.rb",
data/lib/flydata/cli.rb CHANGED
@@ -29,7 +29,10 @@ module Flydata
29
29
  cmd, sub_cmd = parse_command(first_arg)
30
30
  begin
31
31
  cmd_cls = "Flydata::Command::#{cmd.capitalize}".constantize
32
- rescue
32
+ rescue NameError
33
+ # NameError is raised when the constant is not defined in its target
34
+ # file, that is, command not found.
35
+ # Other exceptions mean that some other error happended.
33
36
  raise "Command not found: #{cmd}"
34
37
  end
35
38
  # Command class can define options for each subcommand by defining method "slop_subcommandname"
@@ -78,10 +78,15 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
78
78
  mysql_url: mysql_url, database: @database, tables: @tables)
79
79
  table_meta.update
80
80
 
81
+ table_revs = tables.inject({}) do |h, table_name|
82
+ h[table_name] = @sync_fm.table_rev(table_name)
83
+ h
84
+ end
85
+
81
86
  @context = Mysql::Context.new(
82
87
  database: @database, tables: @tables,
83
88
  tag: @tag, sync_fm: @sync_fm, omit_events: @omit_events,
84
- table_meta: table_meta,
89
+ table_meta: table_meta, table_revs: table_revs,
85
90
  )
86
91
  @record_dispatcher = Mysql::FlydataBinlogRecordDispatcher.new(@context)
87
92
  @idle_event_detector = IdleEventDetector.new(@initial_idle_interval, @continuous_idle_interval, @check_interval)
@@ -70,13 +70,14 @@ module Mysql
70
70
  raise "Missing table name. #{record}" if table.to_s.empty?
71
71
  return unless acceptable_table?(record, table) && acceptable_event?(type, table)
72
72
 
73
- table_rev = @context.sync_fm.table_rev(table)
73
+ table_rev = @context.table_revs[table]
74
74
  position = record['next_position'] - record['event_length']
75
75
 
76
76
  # Add common information to each record
77
77
  records.each do |r|
78
78
  if opt[:increment_table_rev]
79
79
  table_rev = @context.sync_fm.increment_table_rev(table, table_rev)
80
+ @context.table_revs[table] = table_rev
80
81
  end
81
82
  r[TYPE] = type
82
83
  r[RESPECT_ORDER] = true
@@ -1,7 +1,7 @@
1
1
  module Mysql
2
2
  class Context
3
3
  MANDATORY_OPTS = [
4
- :database, :tables, :tag, :sync_fm, :omit_events, :table_meta
4
+ :database, :tables, :tag, :sync_fm, :omit_events, :table_meta, :table_revs,
5
5
  ]
6
6
  OPTIONAL_OPTS = [
7
7
  :current_binlog_file
@@ -98,8 +98,14 @@ module Flydata
98
98
  f = @table_position_files[table_name]
99
99
  seq = f.read
100
100
  seq = seq.to_i + 1
101
- yield(seq)
102
- f.rewind
101
+ begin
102
+ yield(seq)
103
+ ensure
104
+ # when an error happened in yield, the sequence number should remain
105
+ # as is. For the next call to read the value correctly, the position
106
+ # must be rewound.
107
+ f.rewind
108
+ end
103
109
  f.truncate(0)
104
110
  f.write(seq)
105
111
  f.flush
@@ -156,6 +156,37 @@ module Flydata
156
156
  describe '#binlog_path' do
157
157
  it { expect(default_sfm.binlog_path).to eq("#{FLYDATA_HOME}/flydata_sync_mysql.binlog.pos") }
158
158
  end
159
+
160
+ describe '#increment_and_save_table_position' do
161
+ let(:test_table) { 'test_table' }
162
+ before do
163
+ table_pos_dir = SyncFileManager::TABLE_POSITIONS_DIR
164
+ FileUtils.mkdir_p table_pos_dir
165
+ table_pos_file = "#{table_pos_dir}/#{test_table}.pos"
166
+ FileUtils.rm(table_pos_file) if File.exist?(table_pos_file)
167
+ end
168
+ subject { default_sfm }
169
+ context 'when an exception happens in the block' do
170
+ let(:first_pos) { 1 }
171
+ let(:last_pos) { first_pos + 1 }
172
+ before do
173
+ subject.increment_and_save_table_position(test_table) do |seq|
174
+ expect(seq).to eq first_pos
175
+ end
176
+ begin
177
+ subject.increment_and_save_table_position(test_table) do |seq|
178
+ expect(seq).to eq last_pos
179
+ raise "error"
180
+ end
181
+ rescue
182
+ # intentionally left blank
183
+ end
184
+ end
185
+ it 'yields with the previous value' do
186
+ expect{|b| subject.increment_and_save_table_position(test_table, &b)}.to yield_with_args(last_pos)
187
+ end
188
+ end
189
+ end
159
190
  end
160
191
  end
161
192
  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.2.25
4
+ version: 0.2.26
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: 2014-12-21 00:00:00.000000000 Z
15
+ date: 2014-12-31 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rest-client
@@ -438,6 +438,7 @@ files:
438
438
  - flydata-core/.travis.yml
439
439
  - flydata-core/Gemfile
440
440
  - flydata-core/Gemfile.lock
441
+ - flydata-core/circle.yml
441
442
  - flydata-core/lib/flydata-core.rb
442
443
  - flydata-core/lib/flydata-core/core_ext.rb
443
444
  - flydata-core/lib/flydata-core/core_ext/module.rb