Skip to content

Commit d96531b

Browse files
committed
Log when skipping under recovering gzip files, temp file size is zero when recovery fails.
1 parent 8a34056 commit d96531b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/logstash/outputs/s3.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,20 @@ def restore_from_crash
404404
under_recovery_files = get_under_recovery_files(files)
405405

406406
files.each do |file_path|
407-
# if already recovering or recovered and uploading to S3, skip the files
408-
unless under_recovery_files.include?(file_path)
407+
# when encoding is GZIP, if file is already recovering or recovered and uploading to S3, log and skip
408+
if under_recovery_files.include?(file_path)
409+
unless file_path.include?(TemporaryFile.gzip_extension)
410+
@logger.warn("The #{file_path} file either under recover process or failed to recover before.")
411+
end
412+
else
409413
temp_file = TemporaryFile.create_from_existing_file(file_path, temp_folder_path)
410414
if temp_file.size > 0
411415
@logger.debug? && @logger.debug("Recovering from crash and uploading", :path => temp_file.path)
412416
@crash_uploader.upload_async(temp_file,
413417
:on_complete => method(:clean_temporary_file),
414418
:upload_options => upload_options)
415419
end
420+
# do not remove if Logstash tries to recover but fails
416421
if @encoding != GZIP_ENCODING && temp_file.size != 0
417422
clean_temporary_file(temp_file)
418423
end

lib/logstash/outputs/s3/temporary_file.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def size
4343
# so we dont have to deal with fsync
4444
# if the file is close, fd.size raises an IO exception so we use the File::size
4545
begin
46+
# fd is nil when LS tries to recover gzip file but fails
47+
return 0 unless @fd != nil
4648
@fd.size
4749
rescue IOError
4850
::File.size(path)

0 commit comments

Comments
 (0)