Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure to remove metadata if #write_metadata raise an error because of disk full #2598

Merged
merged 1 commit into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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