Skip to content

Commit

Permalink
Merge pull request #1628 from fluent/truncate-after-write-on-file-met…
Browse files Browse the repository at this point in the history
…adata

Write buffer metadata into file ASAP
  • Loading branch information
repeatedly authored Jul 21, 2017
2 parents c8c4ff7 + ea86fc0 commit 3492a75
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/fluent/plugin/buffer/file_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ def write_metadata(update: true)
c: @created_at.to_i,
m: (update ? Time.now : @modified_at).to_i,
})
bin = msgpack_packer.pack(data).to_s
@meta.seek(0, IO::SEEK_SET)
@meta.truncate(0)
@meta.write(msgpack_packer.pack(data))
@meta.write(bin)
@meta.truncate(bin.bytesize)
end

def file_rename(file, old_path, new_path, callback=nil)
Expand Down Expand Up @@ -284,6 +285,7 @@ def create_new_chunk(path, perm)
@meta.set_encoding(Encoding::ASCII_8BIT)
@meta.sync = true
@meta.binmode
write_metadata(update: false)
rescue => e
# This case is easier than enqueued!. Just removing pre-create buffer file
@chunk.close rescue nil
Expand Down

0 comments on commit 3492a75

Please sign in to comment.