Class: Mysql::AlterTableQueryHandler

Inherits:
DdlQueryHandler show all
Defined in:
lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb

Constant Summary collapse

PATTERN =
/^ALTER TABLE/i

Constants inherited from DdlQueryHandler

DdlQueryHandler::DDL_TABLE_QUERY

Constants inherited from BinlogRecordHandler

BinlogRecordHandler::RESPECT_ORDER, BinlogRecordHandler::SEQ, BinlogRecordHandler::SRC_POS, BinlogRecordHandler::TABLE_NAME, BinlogRecordHandler::TABLE_REV, BinlogRecordHandler::TYPE, BinlogRecordHandler::V

Instance Method Summary collapse

Methods inherited from DdlQueryHandler

#acceptable_db?, #table_info

Constructor Details

#initialize(context) ⇒ AlterTableQueryHandler

Returns a new instance of AlterTableQueryHandler.



8
9
10
# File 'lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb', line 8

def initialize(context)
  super
end

Instance Method Details

#patternObject



12
13
14
# File 'lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb', line 12

def pattern
  PATTERN
end

#process(record) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb', line 16

def process(record)
  emit_record(:alter_table, record) do |opt|
    ret = nil
    begin
      result = 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) # log all alter table events even if the table is not subject to sync.  This is for troubleshooting purpose.
    ret
  end
end