Skip to content

Commit

Permalink
Apply feedback from kou on GitHub#3808
Browse files Browse the repository at this point in the history
Signed-off-by: Fujimoto Seiji <[email protected]>
  • Loading branch information
fujimotos committed Jul 1, 2022
1 parent 6a18e4d commit a538b9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/fluent/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def to_s
class InvalidRootDirectory < UnrecoverableError
end

class InvalidLockDirectory < UnrecoverableError
end

# For internal use
class UncatchableError < Exception
end
Expand Down
8 changes: 3 additions & 5 deletions lib/fluent/plugin/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def fluentd_worker_id
end

def fluentd_lockdir
return @_fluentd_lockdir if @_fluentd_lockdir
@_fluentd_lockdir = ENV['FLUENTD_LOCKDIR']
@_fluentd_lockdir
@_fluentd_lockdir ||= ENV['FLUENTD_LOCKDIR']
end

def configure(conf)
Expand All @@ -78,14 +76,14 @@ def multi_workers_ready?

def acquire_worker_lock(name, &block)
if fluentd_lockdir.nil?
raise RuntimeError, "fail to create lockfile on '#{fluentd_lockdir}'"
raise InvalidLockDirectory, "can't acquire lock because FLUENTD_LOCKDIR isn't set"
end

name = name.gsub(/[^a-zA-Z0-9]/, "_")
lockfile = "fluentd-#{name}.lock"
File.open(File.join(fluentd_lockdir, lockfile), "w") do |f|
f.flock(File::LOCK_EX)
block.call()
yield
end
end

Expand Down

0 comments on commit a538b9b

Please sign in to comment.