Skip to content

Commit

Permalink
Move some logic to parent buffer class
Browse files Browse the repository at this point in the history
Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
daipom committed Feb 13, 2023
1 parent 2fd9752 commit 6152b8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 1 addition & 4 deletions lib/fluent/plugin/buf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ def generate_chunk(metadata)
def handle_broken_files(path, mode, e)
log.error "found broken chunk file during resume.", :path => path, :mode => mode, :err_msg => e.message
unique_id = Fluent::Plugin::Buffer::FileChunk.unique_id_from_path(path)
if @disable_chunk_backup
log.warn "disable_chunk_backup is true. #{dump_unique_id_hex(unique_id)} chunk is thrown away"
return
end
backup(unique_id) { |f|
File.open(path, 'rb') { |chunk|
chunk.set_encoding(Encoding::ASCII_8BIT)
Expand All @@ -212,6 +208,7 @@ def handle_broken_files(path, mode, e)
rescue => error
log.error "backup failed. Delete corresponding files.", :err_msg => error.message
ensure
log.warn "disable_chunk_backup is true. #{dump_unique_id_hex(unique_id)} chunk is thrown away." if @disable_chunk_backup
File.unlink(path, path + '.meta') rescue nil
end

Expand Down
5 changes: 1 addition & 4 deletions lib/fluent/plugin/buf_file_single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ def generate_chunk(metadata)
def handle_broken_files(path, mode, e)
log.error "found broken chunk file during resume.", :path => path, :mode => mode, :err_msg => e.message
unique_id, _ = Fluent::Plugin::Buffer::FileSingleChunk.unique_id_and_key_from_path(path)
if @disable_chunk_backup
log.warn "disable_chunk_backup is true. #{dump_unique_id_hex(unique_id)} chunk is thrown away"
return
end
backup(unique_id) { |f|
File.open(path, 'rb') { |chunk|
chunk.set_encoding(Encoding::ASCII_8BIT)
Expand All @@ -224,6 +220,7 @@ def handle_broken_files(path, mode, e)
rescue => error
log.error "backup failed. Delete corresponding files.", :err_msg => error.message
ensure
log.warn "disable_chunk_backup is true. #{dump_unique_id_hex(unique_id)} chunk is thrown away." if @disable_chunk_backup
File.unlink(path) rescue nil
end

Expand Down
6 changes: 6 additions & 0 deletions lib/fluent/plugin/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,12 @@ def statistics

def backup(chunk_unique_id)
unique_id = dump_unique_id_hex(chunk_unique_id)

if @disable_chunk_backup
log.warn "disable_chunk_backup is true. #{unique_id} chunk is not backed up."
return
end

safe_owner_id = owner.plugin_id.gsub(/[ "\/\\:;|*<>?]/, '_')
backup_base_dir = system_config.root_dir || DEFAULT_BACKUP_DIR
backup_file = File.join(backup_base_dir, 'backup', "worker#{fluentd_worker_id}", safe_owner_id, "#{unique_id}.log")
Expand Down

0 comments on commit 6152b8f

Please sign in to comment.