Bring fix from v2.x branch for exception retry handling NameError exception

This commit is contained in:
Karl Southern 2016-06-29 13:52:29 +01:00
parent 542003e4e5
commit 7d699e400c

View File

@ -185,7 +185,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
begin begin
connection = @pool.getConnection connection = @pool.getConnection
rescue => e rescue => e
log_jdbc_exception(e) log_jdbc_exception(e, true)
# If a connection is not available, then the server has gone away # If a connection is not available, then the server has gone away
# We're not counting that towards our retry count. # We're not counting that towards our retry count.
return events, false return events, false
@ -200,10 +200,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
statement.execute statement.execute
rescue => e rescue => e
if retry_exception?(e) if retry_exception?(e)
log_jdbc_exception(e)
events_to_retry.push(event) events_to_retry.push(event)
else
@logger.error('JDBC - Non-retryable exception. Dropping event. If you think this is in error please log an issue with the details from this exception.', exception: e, event: event)
end end
ensure ensure
statement.close unless statement.nil? statement.close unless statement.nil?
@ -283,16 +280,20 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
end end
def retry_exception?(exception) def retry_exception?(exception)
return (exception.class != java.sql.SQLException or ( retrying = (exception.respond_to? 'getSQLState' and (RETRYABLE_SQLSTATE_CLASSES.include?(exception.getSQLState[0,2]) or @retry_sql_states.include?(exception.getSQLState)))
RETRYABLE_SQLSTATE_CLASSES.include?(e.getSQLState[0,2]) or log_jdbc_exception(exception, retrying)
@retry_sql_states.include?(e.getSQLState)
)) retrying
end end
def log_jdbc_exception(exception) def log_jdbc_exception(exception, retrying)
current_exception = exception current_exception = exception
loop do loop do
@logger.warn('JDBC Exception encountered: Will automatically retry.', exception: current_exception) if retrying
@logger.warn('JDBC Exception. Retrying.', exception: current_exception)
else
@logger.warn('JDBC Exception. Not retrying. Dropping event.', exception: current_exception)
end
current_exception = current_exception.getNextException current_exception = current_exception.getNextException
break if current_exception.nil? break if current_exception.nil?
end end