Skip to content

Commit

Permalink
Merge pull request #2598 from ganmacs/ensure-to-remove-metadata
Browse files Browse the repository at this point in the history
Ensure to remove metadata if #write_metadata raise an error because of disk full
  • Loading branch information
ganmacs authored Sep 4, 2019
2 parents 33b94e6 + 3027c18 commit 4a4b1cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/fluent/plugin/buffer/file_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ def create_new_chunk(path, perm)
# This case is easier than enqueued!. Just removing pre-create buffer file
@chunk.close rescue nil
File.unlink(@path) rescue nil

if @meta
# ensure to unlink when #write_metadata fails
@meta.close rescue nil
File.unlink(@meta_path) rescue nil
end

# Same as @chunk case. See above
raise BufferOverflowError, "can't create buffer metadata for #{path}. Stop creating buffer files: error = #{e}"
end
Expand Down
18 changes: 18 additions & 0 deletions test/plugin/test_buffer_file_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,24 @@ def gen_chunk_path(prefix, unique_id)
end
end

test 'ensure to remove metadata file if #write_metadata raise an error becuase of disk full' do
chunk_path = File.join(@chunkdir, 'test.*.log')
stub(Fluent::UniqueId).hex(anything) { 'id' } # to fix chunk id

any_instance_of(Fluent::Plugin::Buffer::FileChunk) do |klass|
stub(klass).write_metadata(anything) do |v|
raise 'disk full'
end
end

err = assert_raise(Fluent::Plugin::Buffer::BufferOverflowError) do
Fluent::Plugin::Buffer::FileChunk.new(gen_metadata, chunk_path, :create)
end

assert_false File.exist?(File.join(@chunkdir, 'test.bid.log.meta'))
assert_match(/create buffer metadata/, err.message)
end

sub_test_case 'chunk with file for staged chunk' do
setup do
@chunk_id = gen_test_chunk_id
Expand Down

0 comments on commit 4a4b1cc

Please sign in to comment.