Class: Flydata::SourceMysql::PluginSupport::AlterTableQueryHandler

Inherits:
TableDdlQueryHandler show all
Defined in:
lib/flydata/source_mysql/plugin_support/alter_table_query_handler.rb

Constant Summary collapse

PATTERN =
/^ALTER TABLE/i

Constants inherited from DdlQueryHandler

DdlQueryHandler::DDL_TABLE_QUERY

Constants included from PluginSupport::SyncRecordEmittable

PluginSupport::SyncRecordEmittable::RESPECT_ORDER, PluginSupport::SyncRecordEmittable::SEQ, PluginSupport::SyncRecordEmittable::SRC_POS, PluginSupport::SyncRecordEmittable::TABLE_NAME, PluginSupport::SyncRecordEmittable::TABLE_REV, PluginSupport::SyncRecordEmittable::TYPE, PluginSupport::SyncRecordEmittable::V

Instance Attribute Summary

Attributes included from PluginSupport::SyncRecordEmittable

#context

Instance Method Summary collapse

Methods inherited from DdlQueryHandler

#acceptable_db?, #emit_record, #table_info

Methods included from PluginSupport::SyncRecordEmittable

#emit_sync_records

Constructor Details

#initialize(context) ⇒ AlterTableQueryHandler

Returns a new instance of AlterTableQueryHandler.


11
12
13
# File 'lib/flydata/source_mysql/plugin_support/alter_table_query_handler.rb', line 11

def initialize(context)
  super
end

Instance Method Details

#patternObject


15
16
17
# File 'lib/flydata/source_mysql/plugin_support/alter_table_query_handler.rb', line 15

def pattern
  PATTERN
end

#process(record) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/flydata/source_mysql/plugin_support/alter_table_query_handler.rb', line 19

def process(record)
  emit_record(:alter_table, record) do |opt|
    ret = nil
    begin
      result = Flydata::Parser::ParserProvider.parser(:mysql, :mysql_alter_table).new.parse(record["normalized_query"])
      if result.nil?
        $log.error("Received unsupported alter table query. normalized query:'#{record['normalized_query']}', raw query: '#{record['query']}'")
      else
        ret = result.tree
        breaking_query = ret[:actions].any?{|action| !action.has_key?(:support_level) || action[:support_level] != :nonbreaking}
        opt[:increment_table_rev] = true if breaking_query
      end
    rescue => e
      msg = <<EOS
Received unsupported alter table query. normalized query:'#{record['normalized_query']}', raw query: '#{record['query']}' Caused by error '#{e.to_s}'
  Stacktrace :
#{e.backtrace.join("\n")}
EOS
      $log.error(msg)
    end
    $log.info(ret.to_s + " at \"#{binlog_pos(record)}\"") # log all alter table events even if the table is not subject to sync.  This is for troubleshooting purpose.
    ret
  end
end