Skip to content

Fix race condition of out_secondary_file - #4081

Merged
ashie merged 10 commits into
fluent:masterfrom
daipom:fix-out-secondary-file-race-conditiion
Mar 9, 2023
Merged

Fix race condition of out_secondary_file#4081
ashie merged 10 commits into
fluent:masterfrom
daipom:fix-out-secondary-file-race-conditiion

Conversation

@daipom

@daipom daipom commented Mar 3, 2023

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
Fixes #4080

What this PR does / why we need it:
For solving race condition issues of out_secondary_file.

Docs Changes:
Not needed.

Release Note:
Same as the title.

@daipom

daipom commented Mar 3, 2023

Copy link
Copy Markdown
Contributor Author

I have confirmed this solves #4080.

@daipom

daipom commented Mar 3, 2023

Copy link
Copy Markdown
Contributor Author

I have one point of concern.

When confirming this solves #4080, I noticed that a large number of lock files remain during Fluentd running because the files are not deleted after exiting the block.

def acquire_worker_lock(name)
if @fluentd_lock_dir.nil?
raise InvalidLockDirectory, "can't acquire lock because FLUENTD_LOCK_DIR isn't set"
end
lock_path = get_lock_path(name)
File.open(lock_path, "w") do |f|
f.flock(File::LOCK_EX)
yield
end
# Update access time to prevent tmpwatch from deleting a lock file.
FileUtils.touch(lock_path);
end

Is this OK?

Comment thread lib/fluent/plugin/out_secondary_file.rb Outdated
@daipom
daipom marked this pull request as draft March 6, 2023 00:58
@daipom daipom changed the title Fix race condition of out_secondary_file on multiple workers Draft: Fix race condition of out_secondary_file on multiple workers Mar 6, 2023
@daipom
daipom force-pushed the fix-out-secondary-file-race-conditiion branch from fe65b4f to c95b52a Compare March 6, 2023 11:22
@daipom

daipom commented Mar 6, 2023

Copy link
Copy Markdown
Contributor Author

Test for c95b52a.

Use the same way (append false) and the same environment as

Result:

workers flush_thread_count percentage (1st) percentage (2nd)
1 16 0.0% (0/111) 0.0% (0/42)
3 1 0.0% (0/27) 0.0% (0/27)
3 8 0.0% (0/267) 0.0% (0/29)

@daipom daipom changed the title Draft: Fix race condition of out_secondary_file on multiple workers Draft: Fix race condition of out_secondary_file Mar 6, 2023
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
@daipom
daipom force-pushed the fix-out-secondary-file-race-conditiion branch from c95b52a to 6acf958 Compare March 6, 2023 11:45
@daipom daipom changed the title Draft: Fix race condition of out_secondary_file Fix race condition of out_secondary_file Mar 6, 2023
@daipom
daipom marked this pull request as ready for review March 6, 2023 12:56
@daipom
daipom requested a review from ashie March 6, 2023 12:56
Comment thread lib/fluent/plugin/out_secondary_file.rb Outdated
Comment thread lib/fluent/plugin/out_secondary_file.rb Outdated
Comment thread lib/fluent/plugin/out_secondary_file.rb Outdated
Comment thread lib/fluent/plugin/out_secondary_file.rb Outdated
Comment thread lib/fluent/plugin/out_secondary_file.rb Outdated
Comment thread test/command/test_cat.rb Outdated
daipom and others added 2 commits March 7, 2023 11:44
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>

Co-authored-by: Takuro Ashie <ashie@clear-code.com>
so that other plugins can use this feature.

Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
@daipom

daipom commented Mar 7, 2023

Copy link
Copy Markdown
Contributor Author

Test for ce32ac5.

Use the same way (append false) and the same environment as

Result:

workers flush_thread_count percentage
3 8 0.0% (0/21)

I plan to do more tests at the end of this PR.

@daipom

daipom commented Mar 7, 2023

Copy link
Copy Markdown
Contributor Author

I will add some unit tests for the lock feature, although it is hard to test race condition strictly.

@daipom

daipom commented Mar 7, 2023

Copy link
Copy Markdown
Contributor Author

@ashie Could you please check if the direction of this fix is OK?

Comment thread lib/fluent/plugin/output.rb Outdated
Comment thread lib/fluent/plugin/output.rb Outdated
Comment thread test/command/test_cat.rb Outdated
Comment thread lib/fluent/plugin/output.rb Outdated
daipom and others added 4 commits March 7, 2023 18:54
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>

Co-authored-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
to unify the existing method: `acquire_worker_lock`.

Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
Co-authored-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
@daipom
daipom force-pushed the fix-out-secondary-file-race-conditiion branch from 488896b to edcbd4b Compare March 7, 2023 10:06
@daipom

daipom commented Mar 7, 2023

Copy link
Copy Markdown
Contributor Author

I will test this issue again, and add some tests for this new lock feature.

@daipom

daipom commented Mar 7, 2023

Copy link
Copy Markdown
Contributor Author

Test for edcbd4b.

Use the same way (append false) and the same environment as

Result:

workers flush_thread_count percentage (1st) percentage (2nd)
1 16 0.0% (0/24) 0.0% (0/39)
3 1 0.0% (0/27) 0.0% (0/21)
3 8 0.0% (0/36) 0.0% (0/33)

Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
@daipom
daipom force-pushed the fix-out-secondary-file-race-conditiion branch from f55838a to f23e7e6 Compare March 8, 2023 00:30
@daipom

daipom commented Mar 8, 2023

Copy link
Copy Markdown
Contributor Author

I will test this issue again, and add some tests for this new lock feature.

Done.

Comment thread lib/fluent/plugin/output.rb Outdated
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
@daipom

daipom commented Mar 8, 2023

Copy link
Copy Markdown
Contributor Author

By the way, might Squash merge be better when merging this?

Comment thread test/plugin/test_output.rb Outdated
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>

Co-authored-by: Takuro Ashie <ashie@clear-code.com>
@ashie
ashie merged commit 59399c1 into fluent:master Mar 9, 2023
@ashie

ashie commented Mar 9, 2023

Copy link
Copy Markdown
Member

Thanks!

@daipom
daipom deleted the fix-out-secondary-file-race-conditiion branch March 9, 2023 01:23
@daipom

daipom commented Mar 9, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for your review! @ashie @kou !

@ashie ashie added this to the v1.16.0 milestone Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SecondaryFileOutput has race condition issues in multiple threads or workers

3 participants