Class: Mysql::FlydataJsonHandlerFactory::TableFlydataJsonHandler

Inherits:
FlydataJsonHandler show all
Defined in:
lib/flydata/fluent-plugins/mysql/binlog_record_handler.rb

Constant Summary

Constants inherited from FlydataJsonHandler

FlydataJsonHandler::DB_NAME, FlydataJsonHandler::RESPECT_ORDER, FlydataJsonHandler::SEQ, FlydataJsonHandler::SRC_POS, FlydataJsonHandler::TABLE_NAME, FlydataJsonHandler::TABLE_REV, FlydataJsonHandler::TYPE, FlydataJsonHandler::V

Instance Method Summary collapse

Constructor Details

#initialize(records, record, context, type, increment_table_rev = nil) ⇒ TableFlydataJsonHandler

Returns a new instance of TableFlydataJsonHandler.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/flydata/fluent-plugins/mysql/binlog_record_handler.rb', line 113

def initialize(records, record, context, type, increment_table_rev=nil)
  super
  table = records.first[TABLE_NAME] || record['table_name']
  raise "Missing table name. #{record}" if table.to_s.empty?

  return unless acceptable_event?(type, table)

  table_rev = @context.table_revs[table]
  position = record['next_position'] - record['event_length']

  # Add common information to each record
  records.each do |r|
    if increment_table_rev
      table_rev = @context.sync_fm.increment_table_rev(table, table_rev)
      @context.table_revs[table] = table_rev
    end
    r[TYPE] = type
    r[RESPECT_ORDER] = true
    r[TABLE_NAME] = table
    r[SRC_POS] = "#{@context.current_binlog_file}\t#{position}"
    r[TABLE_REV] = table_rev
    r[V] = FlydataCore::Record::V2
  end

  # Use binlog's timestamp
  timestamp = record["timestamp"].to_i
  records.each do |row|
    emit(timestamp, row)
  end
end

Instance Method Details

#emit(timestamp, row) ⇒ Object



144
145
146
147
148
149
# File 'lib/flydata/fluent-plugins/mysql/binlog_record_handler.rb', line 144

def emit(timestamp, row)
  @context.sync_fm.increment_and_save_table_position(row[TABLE_NAME]) do |seq|
    row[SEQ] = seq
    Fluent::Engine.emit(@context.tag, timestamp, row)
  end
end