Skip to content

Commit

Permalink
Use isolated connection configurations in the output plugin
Browse files Browse the repository at this point in the history
Modify to use isolated connection configurations for each plugin instance.
The previous implementation had an issue where incorrect connections were used
due to ActiveRecord's connection pooling mechanism when the output plugin
was used multiple times.
  • Loading branch information
h6ah4i committed Sep 26, 2024
1 parent 66e411b commit aba0c65
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/plugin/out_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def start
end

SQLOutput.const_set("BaseModel_#{rand(1 << 31)}", @base_model)
ActiveRecord::Base.establish_connection(config)
@base_model.establish_connection(config)

# ignore tables if TableElement#init failed
@tables.reject! do |te|
Expand All @@ -224,7 +224,7 @@ def formatted_to_msgpack_binary
end

def write(chunk)
ActiveRecord::Base.connection_pool.with_connection do
@base_model.connection_pool.with_connection do

@tables.each { |table|
tag = format_tag(chunk.metadata.tag)
Expand Down

0 comments on commit aba0c65

Please sign in to comment.