Skip to content

Commit

Permalink
Fix jdbc_fetch_size usage with postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
bmax committed Jan 11, 2020
1 parent ae2523b commit ba1405a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/logstash/plugin_mixins/jdbc/jdbc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def open_jdbc_connection
require "java"
require "sequel"
require "sequel/adapters/jdbc"
require "sequel/adapters/jdbc/transactions"

Sequel.application_timezone = @plugin_timezone.to_sym
if @drivers_loaded.false?
Expand All @@ -183,6 +184,7 @@ def open_jdbc_connection
end
@database = jdbc_connect()
@database.extension(:pagination)
@database.extend(Sequel::JDBC::Transactions)
if @jdbc_default_timezone
@database.extension(:named_timezones)
@database.timezone = @jdbc_default_timezone
Expand Down
18 changes: 11 additions & 7 deletions lib/logstash/plugin_mixins/jdbc/statement_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ class NormalStatementHandler < StatementHandler
# @yieldparam row [Hash{Symbol=>Object}]
def perform_query(db, sql_last_value, jdbc_paging_enabled, jdbc_page_size)
query = build_query(db, sql_last_value)
if jdbc_paging_enabled
query.each_page(jdbc_page_size) do |paged_dataset|
paged_dataset.each do |row|
# Execute query in transaction cause PG driver require autocommit off for set fetch count
# See: https://jdbc.postgresql.org/documentation/head/query.html
db.transaction(rollback: :always) do
if jdbc_paging_enabled
query.each_page(jdbc_page_size) do |paged_dataset|
paged_dataset.each do |row|
yield row
end
end
else
query.each do |row|
yield row
end
end
else
query.each do |row|
yield row
end
end
end

Expand Down

0 comments on commit ba1405a

Please sign in to comment.