flydata 0.6.14 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/flydata-core/Gemfile +1 -0
- data/flydata-core/Gemfile.lock +5 -0
- data/flydata-core/lib/flydata-core/errors.rb +4 -2
- data/flydata-core/lib/flydata-core/mysql/binlog_pos.rb +4 -0
- data/flydata-core/lib/flydata-core/postgresql/compatibility_checker.rb +119 -0
- data/flydata-core/lib/flydata-core/postgresql/config.rb +58 -0
- data/flydata-core/lib/flydata-core/postgresql/pg_client.rb +170 -0
- data/flydata-core/lib/flydata-core/postgresql/snapshot.rb +49 -0
- data/flydata-core/lib/flydata-core/postgresql/source_pos.rb +71 -10
- data/flydata-core/lib/flydata-core/table_def/mysql_table_def.rb +1 -1
- data/flydata-core/lib/flydata-core/table_def/postgresql_table_def.rb +76 -17
- data/flydata-core/lib/flydata-core/table_def/redshift_table_def.rb +59 -10
- data/flydata-core/spec/mysql/binlog_pos_spec.rb +10 -2
- data/flydata-core/spec/postgresql/compatibility_checker_spec.rb +148 -0
- data/flydata-core/spec/postgresql/config_spec.rb +85 -0
- data/flydata-core/spec/postgresql/pg_client_spec.rb +195 -0
- data/flydata-core/spec/postgresql/snapshot_spec.rb +55 -0
- data/flydata-core/spec/postgresql/source_pos_spec.rb +70 -8
- data/flydata-core/spec/table_def/postgresql_table_def_spec.rb +80 -19
- data/flydata-core/spec/table_def/redshift_table_def_spec.rb +211 -14
- data/flydata.gemspec +0 -0
- data/lib/flydata.rb +1 -0
- data/lib/flydata/command/sender.rb +10 -7
- data/lib/flydata/command/sync.rb +4 -1
- data/lib/flydata/fluent-plugins/flydata_plugin_ext/base.rb +1 -0
- data/lib/flydata/fluent-plugins/flydata_plugin_ext/fluent_log_ext.rb +73 -0
- data/lib/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync.rb +35 -10
- data/lib/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_diff_based.rb +29 -0
- data/lib/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_query_based.rb +26 -0
- data/lib/flydata/fluent-plugins/flydata_plugin_ext/preference.rb +29 -13
- data/lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb +10 -18
- data/lib/flydata/fluent-plugins/in_postgresql_query_based_flydata.rb +64 -0
- data/lib/flydata/helpers.rb +1 -3
- data/lib/flydata/plugin_support/context.rb +14 -2
- data/lib/flydata/plugin_support/source_position_file.rb +35 -0
- data/lib/flydata/plugin_support/sync_record_emittable.rb +2 -1
- data/lib/flydata/query_based_sync/client.rb +101 -0
- data/lib/flydata/query_based_sync/record_size_estimator.rb +39 -0
- data/lib/flydata/query_based_sync/resource_requester.rb +70 -0
- data/lib/flydata/query_based_sync/response.rb +122 -0
- data/lib/flydata/query_based_sync/response_handler.rb +30 -0
- data/lib/flydata/source/sync_generate_table_ddl.rb +1 -1
- data/lib/flydata/source_mysql/plugin_support/binlog_record_dispatcher.rb +2 -2
- data/lib/flydata/source_mysql/plugin_support/binlog_record_handler.rb +3 -9
- data/lib/flydata/source_mysql/plugin_support/context.rb +26 -2
- data/lib/flydata/source_mysql/plugin_support/source_position_file.rb +14 -0
- data/lib/flydata/source_mysql/table_ddl.rb +3 -3
- data/lib/flydata/source_mysql/{plugin_support/table_meta.rb → table_meta.rb} +3 -10
- data/lib/flydata/source_postgresql/generate_source_dump.rb +44 -63
- data/lib/flydata/source_postgresql/parse_dump_and_send.rb +2 -0
- data/lib/flydata/source_postgresql/plugin_support/context.rb +13 -0
- data/lib/flydata/source_postgresql/plugin_support/source_position_file.rb +14 -0
- data/lib/flydata/source_postgresql/query_based_sync/client.rb +16 -0
- data/lib/flydata/source_postgresql/query_based_sync/diff_query_generator.rb +135 -0
- data/lib/flydata/source_postgresql/query_based_sync/resource_requester.rb +86 -0
- data/lib/flydata/source_postgresql/query_based_sync/response.rb +12 -0
- data/lib/flydata/source_postgresql/query_based_sync/response_handler.rb +12 -0
- data/lib/flydata/source_postgresql/sync_generate_table_ddl.rb +25 -79
- data/lib/flydata/source_postgresql/table_meta.rb +168 -0
- data/lib/flydata/sync_file_manager.rb +5 -5
- data/lib/flydata/table_meta.rb +19 -0
- data/spec/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_context.rb +85 -0
- data/spec/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_diff_based_shared_examples.rb +36 -0
- data/spec/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_query_based_shared_examples.rb +37 -0
- data/spec/flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_shared_examples.rb +67 -0
- data/spec/flydata/fluent-plugins/in_mysql_binlog_flydata_spec.rb +119 -96
- data/spec/flydata/fluent-plugins/in_postgresql_query_based_flydata_spec.rb +82 -0
- data/spec/flydata/fluent-plugins/sync_source_plugin_context.rb +29 -0
- data/spec/flydata/plugin_support/context_spec.rb +37 -3
- data/spec/flydata/query_based_sync/client_spec.rb +79 -0
- data/spec/flydata/query_based_sync/query_based_sync_context.rb +116 -0
- data/spec/flydata/query_based_sync/record_size_estimator_spec.rb +54 -0
- data/spec/flydata/query_based_sync/resource_requester_spec.rb +58 -0
- data/spec/flydata/query_based_sync/response_handler_spec.rb +36 -0
- data/spec/flydata/query_based_sync/response_spec.rb +157 -0
- data/spec/flydata/source_mysql/plugin_support/context_spec.rb +7 -1
- data/spec/flydata/source_mysql/plugin_support/dml_record_handler_spec.rb +2 -15
- data/spec/flydata/source_mysql/plugin_support/drop_database_query_handler_spec.rb +1 -1
- data/spec/flydata/source_mysql/plugin_support/shared_query_handler_context.rb +12 -11
- data/spec/flydata/source_mysql/plugin_support/source_position_file_spec.rb +53 -0
- data/spec/flydata/source_mysql/plugin_support/truncate_query_handler_spec.rb +1 -1
- data/spec/flydata/source_mysql/table_ddl_spec.rb +5 -5
- data/spec/flydata/source_mysql/{plugin_support/table_meta_spec.rb → table_meta_spec.rb} +6 -7
- data/spec/flydata/source_postgresql/generate_source_dump_spec.rb +165 -77
- data/spec/flydata/source_postgresql/query_based_sync/diff_query_generator_spec.rb +213 -0
- data/spec/flydata/source_postgresql/query_based_sync/query_based_sync_postgresql_context.rb +76 -0
- data/spec/flydata/source_postgresql/query_based_sync/resource_requester_spec.rb +70 -0
- data/spec/flydata/source_postgresql/table_meta_spec.rb +77 -0
- metadata +49 -6
- data/lib/flydata/source_mysql/plugin_support/binlog_position_file.rb +0 -23
- data/lib/flydata/source_postgresql/pg_client.rb +0 -43
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'flydata/sync_file_manager'
|
|
2
|
+
require 'flydata/source'
|
|
2
3
|
require 'flydata-core/fluent/config_helper'
|
|
3
4
|
require 'flydata/fluent-plugins/flydata_plugin_ext/flush_support'
|
|
4
5
|
require 'flydata/fluent-plugins/flydata_plugin_ext/transaction_support'
|
|
@@ -11,33 +12,35 @@ module Fluent
|
|
|
11
12
|
include FlushSupport
|
|
12
13
|
prepend TransactionSupport
|
|
13
14
|
|
|
15
|
+
config_param :data_entry_name, :string, default: nil # data entry name
|
|
16
|
+
config_param :data_entry_type, :string, default: nil # data entry type
|
|
14
17
|
config_param :tables, :string
|
|
15
18
|
config_param :tables_append_only, :string
|
|
16
|
-
|
|
17
|
-
# binlog plugin
|
|
18
19
|
config_param :tag, :string
|
|
19
|
-
config_param :position_file, :string, default: 'position.
|
|
20
|
+
config_param :position_file, :string, default: 'position.binlog.pos'
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def configure(conf)
|
|
24
25
|
super
|
|
25
26
|
|
|
26
|
-
@
|
|
27
|
-
unless @
|
|
28
|
-
raise "No position file(#{@
|
|
27
|
+
@source_position_file = self.class::SOURCE_POSITION_FILE_CLASS.new(@position_file)
|
|
28
|
+
unless @source_position_file.exists?
|
|
29
|
+
raise "No position file(#{@source_position_file.path}). Initial synchronization is required before starting."
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
load_custom_conf # preference module needs to be included
|
|
33
|
+
@data_entry = build_data_entry
|
|
34
|
+
@source = Flydata::Source.create(@data_entry)
|
|
35
|
+
|
|
36
|
+
@sync_fm = Flydata::SyncFileManager.new(@data_entry, @source)
|
|
32
37
|
sent_position_file_path = @sync_fm.sent_source_pos_path(@position_file)
|
|
33
|
-
@sent_position_file = self.class::
|
|
38
|
+
@sent_position_file = self.class::SOURCE_POSITION_FILE_CLASS.new(sent_position_file_path)
|
|
34
39
|
|
|
35
40
|
# Create positions dir
|
|
36
41
|
positions_path = @sync_fm.table_positions_dir_path
|
|
37
42
|
Dir.mkdir positions_path unless File.exists? positions_path
|
|
38
43
|
|
|
39
|
-
load_custom_conf
|
|
40
|
-
|
|
41
44
|
@tables = @tables.split(/(?:\s*,\s*|\s+)/)
|
|
42
45
|
@omit_events = Hash.new
|
|
43
46
|
@tables_append_only.split(/(?:\s*,\s*|\s+)/).each do |table|
|
|
@@ -49,6 +52,28 @@ module Fluent
|
|
|
49
52
|
new_tables = @sync_fm.get_new_table_list(@tables, "pos")
|
|
50
53
|
@tables -= new_tables
|
|
51
54
|
$log.info "Not watching these tables: #{new_tables.join(", ")}"
|
|
55
|
+
|
|
56
|
+
# Set table revisions
|
|
57
|
+
@table_revs = @tables.inject({}) do |h, table_name|
|
|
58
|
+
h[table_name] = @sync_fm.table_rev(table_name)
|
|
59
|
+
h
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
$log.info("Source position - resume_pos:'#{@source_position_file.read rescue IOError}' " +
|
|
63
|
+
"sent_pos:'#{@sent_position_file.read rescue nil}'")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def build_data_entry(base_object = {})
|
|
67
|
+
de = base_object || {}
|
|
68
|
+
de['name'] = @data_entry_name
|
|
69
|
+
de['type'] = @data_entry_type
|
|
70
|
+
de.merge!(@data_entry_preferences || {})
|
|
71
|
+
de
|
|
52
72
|
end
|
|
53
73
|
end
|
|
74
|
+
|
|
75
|
+
def shutdown
|
|
76
|
+
super
|
|
77
|
+
@sync_fm.close if @sync_fm
|
|
78
|
+
end
|
|
54
79
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'flydata/fluent-plugins/flydata_plugin_ext/flydata_sync'
|
|
2
|
+
|
|
3
|
+
module Fluent
|
|
4
|
+
|
|
5
|
+
module FlydataSyncDiffBased
|
|
6
|
+
def self.include_modules(base)
|
|
7
|
+
base.send(:include, FlydataSync)
|
|
8
|
+
base.send(:include, self)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.included(base)
|
|
12
|
+
base.class_eval do
|
|
13
|
+
config_param :fetch_interval, :time, default: 60 # 1 minute
|
|
14
|
+
config_param :retry_interval, :time, default: 30 # 30 seconds
|
|
15
|
+
config_param :emit_chunk_limit, :size, default: 64 * (1024 ** 2) # 64MB, should be equal or less than buffer_chunk_limit
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def configure(conf)
|
|
20
|
+
super
|
|
21
|
+
@table_src_pos_files = @tables.inject({}) do |ret, table_name|
|
|
22
|
+
ret[table_name.to_sym] = self.class::SOURCE_POSITION_FILE_CLASS.new(
|
|
23
|
+
@sync_fm.table_source_pos_file_path(table_name)
|
|
24
|
+
)
|
|
25
|
+
ret
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_diff_based'
|
|
2
|
+
|
|
3
|
+
module Fluent
|
|
4
|
+
|
|
5
|
+
module FlydataSyncQueryBased
|
|
6
|
+
def self.include_modules(base)
|
|
7
|
+
FlydataSyncDiffBased.include_modules(base)
|
|
8
|
+
base.send(:include, self)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.included(base)
|
|
12
|
+
base.class_eval do
|
|
13
|
+
config_param :host, :string
|
|
14
|
+
config_param :port, :integer
|
|
15
|
+
config_param :username, :string
|
|
16
|
+
config_param :password, :string
|
|
17
|
+
config_param :database, :string
|
|
18
|
+
config_param :schema, :string, default: nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def configure(conf)
|
|
23
|
+
super
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
2
|
require 'flydata/util/encryptor'
|
|
3
3
|
require 'flydata/source_mysql/data_entry'
|
|
4
|
+
require 'flydata/source_postgresql/data_entry'
|
|
4
5
|
|
|
5
6
|
module Fluent
|
|
6
7
|
module DataEntryPreferenceConfigurable
|
|
7
|
-
@@supported_custom_confs = Hash.new{|h,k| h[k] = {}}
|
|
8
8
|
|
|
9
9
|
def self.included(base)
|
|
10
|
-
base.
|
|
11
|
-
|
|
10
|
+
base.instance_eval do
|
|
11
|
+
extend ClassMethods
|
|
12
|
+
@supported_custom_confs = Hash.new{|h,k| h[k] = {}}
|
|
12
13
|
config_param :custom_conf_path, :string, default: nil
|
|
13
14
|
config_param :key, :string, default: nil
|
|
14
15
|
end
|
|
@@ -20,10 +21,10 @@ module Fluent
|
|
|
20
21
|
else
|
|
21
22
|
nil
|
|
22
23
|
end
|
|
23
|
-
|
|
24
|
+
self.class.instance_variable_get(:@supported_custom_confs).each do |type, settings|
|
|
24
25
|
settings.each do |key, option|
|
|
25
26
|
apply_custom_conf(custom_conf, key, type, option) if custom_conf
|
|
26
|
-
apply_custom_option(key, option)
|
|
27
|
+
apply_custom_option(key, option, type)
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
30
|
end
|
|
@@ -35,7 +36,7 @@ module Fluent
|
|
|
35
36
|
end
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
def apply_custom_option(key, option)
|
|
39
|
+
def apply_custom_option(key, option, type)
|
|
39
40
|
var_name = option[:var_name] || key
|
|
40
41
|
original_value = instance_variable_get(:"@#{var_name}")
|
|
41
42
|
value = original_value
|
|
@@ -46,11 +47,21 @@ module Fluent
|
|
|
46
47
|
if original_value != value
|
|
47
48
|
instance_variable_set(:"@#{var_name}", value)
|
|
48
49
|
end
|
|
50
|
+
@data_entry_preferences ||= Hash.new{|h,k| h[k] = {}}
|
|
51
|
+
@data_entry_preferences[type.to_s][var_name.to_s] = value
|
|
49
52
|
end
|
|
50
53
|
|
|
51
54
|
module ClassMethods
|
|
55
|
+
def register_config_params(config_params)
|
|
56
|
+
config_params.each do |type, custom_conf|
|
|
57
|
+
custom_conf.each do |key, option|
|
|
58
|
+
custom_config_param key, type, option
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
52
63
|
def custom_config_param(key, type, option = {})
|
|
53
|
-
conf =
|
|
64
|
+
conf = @supported_custom_confs
|
|
54
65
|
conf[type.to_sym][key.to_sym] = option
|
|
55
66
|
end
|
|
56
67
|
end
|
|
@@ -70,13 +81,18 @@ module Fluent
|
|
|
70
81
|
|
|
71
82
|
module MysqlBinlogFlydataInputPreference
|
|
72
83
|
def self.included(base)
|
|
73
|
-
base.
|
|
84
|
+
base.instance_eval do
|
|
74
85
|
include DataEntryPreferenceConfigurable
|
|
75
|
-
Flydata::SourceMysql::DataEntry::CONFIG_PARAMS
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
register_config_params Flydata::SourceMysql::DataEntry::CONFIG_PARAMS
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
module PostgresqlQueryBasedSyncPreference
|
|
92
|
+
def self.included(base)
|
|
93
|
+
base.instance_eval do
|
|
94
|
+
include DataEntryPreferenceConfigurable
|
|
95
|
+
register_config_params Flydata::SourcePostgresql::DataEntry::CONFIG_PARAMS
|
|
80
96
|
end
|
|
81
97
|
end
|
|
82
98
|
end
|
|
@@ -11,10 +11,10 @@ require 'flydata-core/mysql/command_generator'
|
|
|
11
11
|
require 'flydata/fluent-plugins/flydata_plugin_ext/preference'
|
|
12
12
|
require 'flydata/fluent-plugins/flydata_plugin_ext/idle_event_detector'
|
|
13
13
|
require 'flydata/fluent-plugins/flydata_plugin_ext/flydata_sync'
|
|
14
|
-
require 'flydata/source_mysql/plugin_support/
|
|
14
|
+
require 'flydata/source_mysql/plugin_support/source_position_file'
|
|
15
15
|
require 'flydata/source_mysql/plugin_support/binlog_record_dispatcher'
|
|
16
16
|
require 'flydata/source_mysql/plugin_support/context'
|
|
17
|
-
require 'flydata/source_mysql/
|
|
17
|
+
require 'flydata/source_mysql/table_meta'
|
|
18
18
|
require 'flydata/source_mysql/table_ddl'
|
|
19
19
|
require 'flydata-core/fluent/config_helper'
|
|
20
20
|
require 'flydata-core/mysql/ssl'
|
|
@@ -26,7 +26,7 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
|
26
26
|
|
|
27
27
|
Plugin.register_input('mysql_binlog_flydata', self)
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
SOURCE_POSITION_FILE_CLASS = Flydata::SourceMysql::PluginSupport::SourcePositionFile
|
|
30
30
|
|
|
31
31
|
config_param :database, :string
|
|
32
32
|
config_param :initial_idle_interval, :integer, :default => 30 # 30 sec
|
|
@@ -56,7 +56,7 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
|
56
56
|
|
|
57
57
|
# SSL configuration
|
|
58
58
|
unless @ssl_ca_content.to_s.strip.empty?
|
|
59
|
-
@ssl_ca_path = @sync_fm.ssl_ca_path(@
|
|
59
|
+
@ssl_ca_path = @sync_fm.ssl_ca_path(@source_position_file.path)
|
|
60
60
|
@sync_fm.save_ssl_ca(FlydataCore::Fluent::ConfigHelper.unescape_conf(@ssl_ca_content), @ssl_ca_path)
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -75,18 +75,13 @@ class MysqlBinlogFlydataInput < MysqlBinlogInput
|
|
|
75
75
|
#exit 1 # causes retry loop
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
table_meta = Flydata::SourceMysql::
|
|
79
|
-
|
|
80
|
-
table_revs = tables.inject({}) do |h, table_name|
|
|
81
|
-
h[table_name] = @sync_fm.table_rev(table_name)
|
|
82
|
-
h
|
|
83
|
-
end
|
|
78
|
+
table_meta = Flydata::SourceMysql::TableMeta.new(@db_opts.merge(tables: @tables))
|
|
84
79
|
|
|
85
80
|
# Set context
|
|
86
81
|
@context = Flydata::SourceMysql::PluginSupport::Context.new(
|
|
87
82
|
database: @database, tables: @tables,
|
|
88
83
|
tag: @tag, sync_fm: @sync_fm, omit_events: @omit_events,
|
|
89
|
-
table_meta: table_meta, table_revs: table_revs,
|
|
84
|
+
table_meta: table_meta, table_revs: @table_revs, dbconf: @db_opts
|
|
90
85
|
)
|
|
91
86
|
@record_dispatcher = Flydata::SourceMysql::PluginSupport::FlydataBinlogRecordDispatcher.new(@context)
|
|
92
87
|
@idle_event_detector = IdleEventDetector.new(@initial_idle_interval, @continuous_idle_interval, @check_interval, @idle_timeout)
|
|
@@ -128,9 +123,9 @@ EOS
|
|
|
128
123
|
def run
|
|
129
124
|
return if process_aborted?
|
|
130
125
|
|
|
131
|
-
@context.table_meta.
|
|
126
|
+
@context.table_meta.reload
|
|
132
127
|
Flydata::SourceMysql::TableDdl.migrate_tables(@context.tables, @db_opts,
|
|
133
|
-
@context.sync_fm, @
|
|
128
|
+
@context.sync_fm, @source_position_file.path,
|
|
134
129
|
@context) do |event|
|
|
135
130
|
@record_dispatcher.dispatch(event)
|
|
136
131
|
end
|
|
@@ -142,7 +137,7 @@ EOS
|
|
|
142
137
|
begin
|
|
143
138
|
begin
|
|
144
139
|
start_kodama(mysql_url) do |c|
|
|
145
|
-
c.binlog_position_file = @
|
|
140
|
+
c.binlog_position_file = @source_position_file.path
|
|
146
141
|
if @ssl_ca_path.to_s != '' && c.respond_to?(:ssl_ca=)
|
|
147
142
|
$log.info "SSL is enabled. (ssl_ca: #{@ssl_ca_path})"
|
|
148
143
|
c.ssl_ca = @ssl_ca_path
|
|
@@ -157,9 +152,6 @@ EOS
|
|
|
157
152
|
c.sent_binlog_position_file = @sent_position_file.path
|
|
158
153
|
end
|
|
159
154
|
|
|
160
|
-
$log.info("Binlog position - resume_pos:'#{@binlog_position_file.read rescue IOError}' " +
|
|
161
|
-
"sent_pos:'#{@sent_position_file.read rescue IOError}'")
|
|
162
|
-
|
|
163
155
|
c.connection_retry_limit = @retry_limit
|
|
164
156
|
c.connection_retry_wait = @retry_wait
|
|
165
157
|
c.log_level = @log_level.to_sym
|
|
@@ -215,7 +207,7 @@ EOS
|
|
|
215
207
|
@idle_event_detector.notify
|
|
216
208
|
@record_dispatcher.dispatch(event)
|
|
217
209
|
rescue Exception => e
|
|
218
|
-
position = @
|
|
210
|
+
position = @source_position_file.read
|
|
219
211
|
$log.error "error occurred while processing #{event.event_type} event at #{position}, event_class:#{event.class.to_s}\n#{e.message}\n#{$!.backtrace.join("\n")}"
|
|
220
212
|
raise
|
|
221
213
|
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require_relative 'flydata_plugin_ext/base'
|
|
2
|
+
|
|
3
|
+
require 'flydata/fluent-plugins/flydata_plugin_ext/preference'
|
|
4
|
+
require 'flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_query_based'
|
|
5
|
+
require 'flydata/source_postgresql/plugin_support/source_position_file'
|
|
6
|
+
require 'flydata/source_postgresql/plugin_support/context'
|
|
7
|
+
require 'flydata/source_postgresql/table_meta'
|
|
8
|
+
require 'flydata/source_postgresql/query_based_sync/client'
|
|
9
|
+
require 'flydata-core/postgresql/config'
|
|
10
|
+
|
|
11
|
+
module Fluent
|
|
12
|
+
|
|
13
|
+
class PostgresqlQueryBasedFlydataInput < Input
|
|
14
|
+
include PostgresqlQueryBasedSyncPreference
|
|
15
|
+
FlydataSyncQueryBased.include_modules(self)
|
|
16
|
+
|
|
17
|
+
Plugin.register_input('postgresql_query_based_sync_flydata', self)
|
|
18
|
+
|
|
19
|
+
SOURCE_POSITION_FILE_CLASS = Flydata::SourcePostgresql::PluginSupport::SourcePositionFile
|
|
20
|
+
|
|
21
|
+
def configure(conf)
|
|
22
|
+
super
|
|
23
|
+
@dbconf = FlydataCore::Postgresql::Config.opts_for_pg(@data_entry['postgresql_data_entry_preference'])
|
|
24
|
+
$log.info "postgresql host:\"#{@host}\" port:\"#{@port}\" username:\"#{@username}\" database:\"#{@database}\" tables:\"#{@tables}\" tables_append_only:\"#{@tables_append_only}\""
|
|
25
|
+
|
|
26
|
+
@table_meta = Flydata::SourcePostgresql::TableMeta.new(
|
|
27
|
+
@dbconf, @tables, @schema)
|
|
28
|
+
|
|
29
|
+
@context = Flydata::SourcePostgresql::PluginSupport::Context.new(
|
|
30
|
+
database: @database, tables: @tables,
|
|
31
|
+
tag: @tag, sync_fm: @sync_fm, omit_events: @omit_events,
|
|
32
|
+
table_revs: @table_revs, dbconf: @dbconf,
|
|
33
|
+
cur_src_pos_file: @source_position_file,
|
|
34
|
+
table_src_pos_files: @table_src_pos_files,
|
|
35
|
+
table_meta: @table_meta,
|
|
36
|
+
params: {
|
|
37
|
+
fetch_interval: @fetch_interval,
|
|
38
|
+
retry_interval: @retry_interval,
|
|
39
|
+
emit_chunk_limit: @emit_chunk_limit,
|
|
40
|
+
},
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
@client = Flydata::SourcePostgresql::QueryBasedSync::Client.new(@context)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def start
|
|
47
|
+
super
|
|
48
|
+
@thread = Thread.new(&method(:run))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def run
|
|
52
|
+
@client.start
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def shutdown
|
|
56
|
+
if @thread and @thread.alive?
|
|
57
|
+
@client.stop_request
|
|
58
|
+
@thread.join
|
|
59
|
+
end
|
|
60
|
+
super
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
data/lib/flydata/helpers.rb
CHANGED
|
@@ -14,9 +14,7 @@ Usage: flydata COMMAND
|
|
|
14
14
|
restart # restart flydata process
|
|
15
15
|
status # check flydata process
|
|
16
16
|
version # show flydata version
|
|
17
|
-
|
|
18
|
-
sync [tables] # initial sync (only for mysql database)
|
|
19
|
-
sync:generate_table_ddl [tables | -all-tables] # Generate CREATE TABLE script for Redshift
|
|
17
|
+
sync:generate_table_ddl # Generate CREATE TABLE script for Redshift
|
|
20
18
|
sync:reset [tables] # reset sync and stop flydata process
|
|
21
19
|
sync:flush # flush your current buffer and stop flydata process
|
|
22
20
|
EOM
|
|
@@ -28,8 +28,16 @@ module PluginSupport
|
|
|
28
28
|
nil
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
register_mandatory_opts :tables,
|
|
32
|
-
|
|
31
|
+
register_mandatory_opts :tables,
|
|
32
|
+
:tag,
|
|
33
|
+
:sync_fm,
|
|
34
|
+
:omit_events,
|
|
35
|
+
:table_revs,
|
|
36
|
+
:table_meta
|
|
37
|
+
|
|
38
|
+
register_optional_opts :cur_src_pos_file,
|
|
39
|
+
:table_src_pos_files,
|
|
40
|
+
:params
|
|
33
41
|
|
|
34
42
|
def initialize(opts)
|
|
35
43
|
missing_opts = self.class.mandatory_opts - opts.keys
|
|
@@ -41,6 +49,10 @@ module PluginSupport
|
|
|
41
49
|
self.instance_variable_set(:"@#{k}", v)
|
|
42
50
|
end
|
|
43
51
|
end
|
|
52
|
+
|
|
53
|
+
def source_pos_class
|
|
54
|
+
self.class::SOURCE_POS_CLASS
|
|
55
|
+
end
|
|
44
56
|
end
|
|
45
57
|
end
|
|
46
58
|
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Flydata
|
|
2
|
+
|
|
3
|
+
module PluginSupport
|
|
4
|
+
class SourcePositionFile
|
|
5
|
+
attr_accessor :path
|
|
6
|
+
|
|
7
|
+
def initialize(path)
|
|
8
|
+
@path = path
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def exists?
|
|
12
|
+
File.exists?(@path)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def read
|
|
16
|
+
File.open(@path) {|f| f.read }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def pos
|
|
20
|
+
if exists?
|
|
21
|
+
self.class::SOURCE_POS_CLASS.load(read)
|
|
22
|
+
else
|
|
23
|
+
nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def save(*args)
|
|
28
|
+
c = self.class::SOURCE_POS_CLASS.new(*args)
|
|
29
|
+
File.open(@path, 'w') {|f| f.write(c.to_s) }
|
|
30
|
+
c
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|