fluent-plugin-mysql-replicator 0.5.0 → 0.5.1
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.
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # -*- encoding: utf-8 -*-
         
     | 
| 
       2 
2 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       3 
3 
     | 
    
         
             
              s.name        = "fluent-plugin-mysql-replicator"
         
     | 
| 
       4 
     | 
    
         
            -
              s.version     = "0.5. 
     | 
| 
      
 4 
     | 
    
         
            +
              s.version     = "0.5.1"
         
     | 
| 
       5 
5 
     | 
    
         
             
              s.authors     = ["Kentaro Yoshida"]
         
     | 
| 
       6 
6 
     | 
    
         
             
              s.email       = ["y.ken.studio@gmail.com"]
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.homepage    = "https://github.com/y-ken/fluent-plugin-mysql-replicator"
         
     | 
| 
         @@ -58,27 +58,31 @@ module Fluent 
     | 
|
| 
       58 
58 
     | 
    
         
             
                def poll
         
     | 
| 
       59 
59 
     | 
    
         
             
                  table_hash = Hash.new
         
     | 
| 
       60 
60 
     | 
    
         
             
                  ids = Array.new
         
     | 
| 
      
 61 
     | 
    
         
            +
                  con = get_connection()
         
     | 
| 
      
 62 
     | 
    
         
            +
                  prepared_con = get_connection()
         
     | 
| 
       61 
63 
     | 
    
         
             
                  loop do
         
     | 
| 
       62 
64 
     | 
    
         
             
                    rows_count = 0
         
     | 
| 
       63 
65 
     | 
    
         
             
                    start_time = Time.now
         
     | 
| 
       64 
66 
     | 
    
         
             
                    previous_ids = ids
         
     | 
| 
       65 
67 
     | 
    
         
             
                    current_ids = Array.new
         
     | 
| 
       66 
     | 
    
         
            -
                    prepared_con = get_connection()
         
     | 
| 
       67 
68 
     | 
    
         
             
                    if !@prepared_query.nil?
         
     | 
| 
       68 
69 
     | 
    
         
             
                      @prepared_query.split(/;/).each do |query|
         
     | 
| 
       69 
70 
     | 
    
         
             
                        prepared_con.query(query)
         
     | 
| 
       70 
71 
     | 
    
         
             
                      end
         
     | 
| 
       71 
72 
     | 
    
         
             
                    end
         
     | 
| 
       72 
     | 
    
         
            -
                    query(@query) 
     | 
| 
      
 73 
     | 
    
         
            +
                    rows, con = query(@query, con)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    rows.each do |row|
         
     | 
| 
       73 
75 
     | 
    
         
             
                      current_ids << row[@primary_key]
         
     | 
| 
       74 
76 
     | 
    
         
             
                      current_hash = Digest::SHA1.hexdigest(row.flatten.join)
         
     | 
| 
       75 
77 
     | 
    
         
             
                      row.each {|k, v| row[k] = v.to_s if v.is_a?(Time) || v.is_a?(Date) || v.is_a?(BigDecimal)}
         
     | 
| 
       76 
78 
     | 
    
         
             
                      row.select {|k, v| v.to_s.strip.match(/^SELECT/i) }.each do |k, v|
         
     | 
| 
       77 
79 
     | 
    
         
             
                        row[k] = [] unless row[k].is_a?(Array)
         
     | 
| 
       78 
     | 
    
         
            -
                        prepared_con 
     | 
| 
      
 80 
     | 
    
         
            +
                        nest_rows, prepared_con = query(v.gsub(/\$\{([^\}]+)\}/, row[$1].to_s), prepared_con)
         
     | 
| 
      
 81 
     | 
    
         
            +
                        nest_rows.each do |nest_row|
         
     | 
| 
       79 
82 
     | 
    
         
             
                          nest_row.each {|k, v| nest_row[k] = v.to_s if v.is_a?(Time) || v.is_a?(Date) || v.is_a?(BigDecimal)}
         
     | 
| 
       80 
83 
     | 
    
         
             
                          row[k] << nest_row
         
     | 
| 
       81 
84 
     | 
    
         
             
                        end
         
     | 
| 
      
 85 
     | 
    
         
            +
                        prepared_con.close
         
     | 
| 
       82 
86 
     | 
    
         
             
                      end
         
     | 
| 
       83 
87 
     | 
    
         
             
                      if row[@primary_key].nil?
         
     | 
| 
       84 
88 
     | 
    
         
             
                        $log.error "mysql_replicator: missing primary_key. :tag=>#{tag} :primary_key=>#{primary_key}"
         
     | 
| 
         @@ -94,6 +98,7 @@ module Fluent 
     | 
|
| 
       94 
98 
     | 
    
         
             
                      table_hash[row[@primary_key]] = current_hash
         
     | 
| 
       95 
99 
     | 
    
         
             
                      rows_count += 1
         
     | 
| 
       96 
100 
     | 
    
         
             
                    end
         
     | 
| 
      
 101 
     | 
    
         
            +
                    con.close
         
     | 
| 
       97 
102 
     | 
    
         
             
                    ids = current_ids
         
     | 
| 
       98 
103 
     | 
    
         
             
                    if @enable_delete
         
     | 
| 
       99 
104 
     | 
    
         
             
                      if previous_ids.empty?
         
     | 
| 
         @@ -133,8 +138,9 @@ module Fluent 
     | 
|
| 
       133 
138 
     | 
    
         | 
| 
       134 
139 
     | 
    
         
             
                def query(query, con = nil)
         
     | 
| 
       135 
140 
     | 
    
         
             
                  begin
         
     | 
| 
       136 
     | 
    
         
            -
                     
     | 
| 
       137 
     | 
    
         
            -
                     
     | 
| 
      
 141 
     | 
    
         
            +
                    con = con.nil? ? get_connection : con
         
     | 
| 
      
 142 
     | 
    
         
            +
                    con = con.ping ? con : get_connection
         
     | 
| 
      
 143 
     | 
    
         
            +
                    return con.query(query), con
         
     | 
| 
       138 
144 
     | 
    
         
             
                  rescue Exception => e
         
     | 
| 
       139 
145 
     | 
    
         
             
                    $log.warn "mysql_replicator: #{e}"
         
     | 
| 
       140 
146 
     | 
    
         
             
                    sleep @interval
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: fluent-plugin-mysql-replicator
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.5. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.5.1
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2015-09 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2015-11-09 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rake
         
     |