Skip to content

Commit

Permalink
Refactor method name
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
daipom and ashie committed Mar 7, 2023
1 parent 60829a9 commit 8f95c34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/plugin/out_secondary_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def has_time_format?(str)
def generate_path(path_without_suffix)
if @append
path = "#{path_without_suffix}#{@suffix}"
lock_if_need(path) do
acquire_lock_if_need(path) do
yield path
end
return path
Expand All @@ -129,7 +129,7 @@ def generate_path(path_without_suffix)
break unless File.exist?(path)
i += 1
end
lock_if_need(path) do
acquire_lock_if_need(path) do
# If multiple processes or threads select the same path and another
# one entered this locking block first, the file should already
# exist and this one should retry to find new path.
Expand Down
10 changes: 5 additions & 5 deletions lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ def actual_flush_thread_count
# (For multiple workers, the lock is shared if `worker_lock_name` is the same value).
# For multiple threads, `worker_lock_name` is not used, and the lock is shared by all
# threads in the same process.
def lock_if_need(worker_lock_name)
get_worker_lock_if_need(worker_lock_name) do
get_flush_thread_lock_if_need do
def acquire_lock_if_need(worker_lock_name)
acquire_worker_lock_if_need(worker_lock_name) do
acquire_flush_thread_lock_if_need do
yield
end
end
end

def get_worker_lock_if_need(name)
def acquire_worker_lock_if_need(name)
need_worker_lock = system_config.workers > 1
if need_worker_lock
acquire_worker_lock(name) { yield }
Expand All @@ -626,7 +626,7 @@ def get_worker_lock_if_need(name)
end
end

def get_flush_thread_lock_if_need
def acquire_flush_thread_lock_if_need
need_thread_lock = actual_flush_thread_count > 1
if need_thread_lock
@flush_thread_mutex.synchronize { yield }
Expand Down

0 comments on commit 8f95c34

Please sign in to comment.