logstash-input-jdbc 4.3.1 → 4.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6e3311aea8fc892c6630483444ee3c03c5ee1b02d55dca8db4ddb648cfecc89
4
- data.tar.gz: 69ad000d130f1336961c816800925fc227ed53c0abecbb89d4c01ea918b9541d
3
+ metadata.gz: dbcee49388bb159c11488cba2030c74f0d51f6e52615c1190a7f0bc9d2d84dda
4
+ data.tar.gz: 615585ac894d3a2bbb8677848b9d518d68594d53477dbc6c71413044373ffa51
5
5
  SHA512:
6
- metadata.gz: 1a1a9572a873e8b51e2700d51d70e76f56c7b77e4546d8a5bc17c21db7d0bf318291dc149c213f6088fb6c49f5d671e0036d22cad19ceb1f18eab92def13767a
7
- data.tar.gz: 728fc81b1034c9d21a4d6c9a4e27930c6d64b421a6c36ee896b78f6391c848826cdbb6dbc6235d7a17abc0270f93efca211cd216590db999144996e7ac8e1975
6
+ metadata.gz: 816c79b9ac881b3fe8b2524323e8b67321d21dfda0c82efa638a8b2a3bccaa7e9aeebe920385cb33b4ba01e19f60cb368fbcdca9fe43aba6dc84df4e891ef46b
7
+ data.tar.gz: 6c2f68235f963c58bbbaf523b09cdfb7dae004fee7a6973de860761b394579f6aae4efab07259f4ed923d3f78c9d04cb1cde39ead37c6376e882151c2065dad0
@@ -1,3 +1,6 @@
1
+ ## 4.3.2
2
+ - [#251](https://github.com/logstash-plugins/logstash-input-jdbc/issues/251) Fix connection and memory leak.
3
+
1
4
  ## 4.3.1
2
5
  - Update gemspec summary
3
6
 
@@ -259,9 +259,8 @@ class LogStash::Inputs::Jdbc < LogStash::Inputs::Base
259
259
  end # def run
260
260
 
261
261
  def stop
262
- @scheduler.stop if @scheduler
263
-
264
262
  close_jdbc_connection
263
+ @scheduler.stop if @scheduler
265
264
  end
266
265
 
267
266
  private
@@ -4,6 +4,8 @@ require "logstash/config/mixin"
4
4
  require "time"
5
5
  require "date"
6
6
 
7
+ java_import java.util.concurrent.locks.ReentrantLock
8
+
7
9
  # Tentative of abstracting JDBC logic to a mixin
8
10
  # for potential reuse in other plugins (input/output)
9
11
  module LogStash::PluginMixins::Jdbc
@@ -191,6 +193,7 @@ module LogStash::PluginMixins::Jdbc
191
193
 
192
194
  public
193
195
  def prepare_jdbc_connection
196
+ @connection_lock = ReentrantLock.new
194
197
  if @use_column_value
195
198
  case @tracking_column_type
196
199
  when "numeric"
@@ -206,26 +209,41 @@ module LogStash::PluginMixins::Jdbc
206
209
  public
207
210
  def close_jdbc_connection
208
211
  begin
212
+ # pipeline restarts can also close the jdbc connection, block until the current executing statement is finished to avoid leaking connections
213
+ # connections in use won't really get closed
214
+ @connection_lock.lock
209
215
  @database.disconnect if @database
210
216
  rescue => e
211
217
  @logger.warn("Failed to close connection", :exception => e)
218
+ ensure
219
+ @connection_lock.unlock
212
220
  end
213
221
  end
214
222
 
215
223
  public
216
224
  def execute_statement(statement, parameters)
217
- success = false
218
- open_jdbc_connection
219
- begin
220
- parameters = symbolized_params(parameters)
221
- query = @database[statement, parameters]
222
- sql_last_value = @use_column_value ? @sql_last_value : Time.now.utc
223
- @tracking_column_warning_sent = false
224
- @logger.debug? and @logger.debug("Executing JDBC query", :statement => statement, :parameters => parameters, :count => query.count)
225
-
226
- if @jdbc_paging_enabled
227
- query.each_page(@jdbc_page_size) do |paged_dataset|
228
- paged_dataset.each do |row|
225
+ success = false
226
+ @connection_lock.lock
227
+ open_jdbc_connection
228
+ begin
229
+ parameters = symbolized_params(parameters)
230
+ query = @database[statement, parameters]
231
+ sql_last_value = @use_column_value ? @sql_last_value : Time.now.utc
232
+ @tracking_column_warning_sent = false
233
+ @logger.debug? and @logger.debug("Executing JDBC query", :statement => statement, :parameters => parameters, :count => query.count)
234
+
235
+ if @jdbc_paging_enabled
236
+ query.each_page(@jdbc_page_size) do |paged_dataset|
237
+ paged_dataset.each do |row|
238
+ sql_last_value = get_column_value(row) if @use_column_value
239
+ if @tracking_column_type=="timestamp" and @use_column_value and sql_last_value.is_a?(DateTime)
240
+ sql_last_value=Time.parse(sql_last_value.to_s) # Coerce the timestamp to a `Time`
241
+ end
242
+ yield extract_values_from(row)
243
+ end
244
+ end
245
+ else
246
+ query.each do |row|
229
247
  sql_last_value = get_column_value(row) if @use_column_value
230
248
  if @tracking_column_type=="timestamp" and @use_column_value and sql_last_value.is_a?(DateTime)
231
249
  sql_last_value=Time.parse(sql_last_value.to_s) # Coerce the timestamp to a `Time`
@@ -233,23 +251,16 @@ module LogStash::PluginMixins::Jdbc
233
251
  yield extract_values_from(row)
234
252
  end
235
253
  end
254
+ success = true
255
+ rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError => e
256
+ @logger.warn("Exception when executing JDBC query", :exception => e)
236
257
  else
237
- query.each do |row|
238
- sql_last_value = get_column_value(row) if @use_column_value
239
- if @tracking_column_type=="timestamp" and @use_column_value and sql_last_value.is_a?(DateTime)
240
- sql_last_value=Time.parse(sql_last_value.to_s) # Coerce the timestamp to a `Time`
241
- end
242
- yield extract_values_from(row)
243
- end
258
+ @sql_last_value = sql_last_value
259
+ ensure
260
+ close_jdbc_connection
261
+ @connection_lock.unlock
244
262
  end
245
- success = true
246
- rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError => e
247
- @logger.warn("Exception when executing JDBC query", :exception => e)
248
- else
249
- @sql_last_value = sql_last_value
250
- end
251
- close_jdbc_connection
252
- return success
263
+ return success
253
264
  end
254
265
 
255
266
  public
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-jdbc'
3
- s.version = '4.3.1'
3
+ s.version = '4.3.2'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Creates events from JDBC data"
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.1
4
+ version: 4.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.6.11
199
+ rubygems_version: 2.6.13
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: Creates events from JDBC data