Skip to content

Commit

Permalink
Tweak the new inter-worker lock support
Browse files Browse the repository at this point in the history
 * Ensure to update atime to prevent tmpwatch from cleaning
   active lock files.
 * Fix instance/class variable access.
 * Unify the terminology from "lockdir" to "lock_dir".

Signed-off-by: Fujimoto Seiji <[email protected]>
  • Loading branch information
fujimotos committed Jul 3, 2022
1 parent 49970e4 commit caec5b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/fluent/plugin/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ def get_lock_path(name)

def acquire_worker_lock(name)
if @fluentd_lock_dir.nil?
raise InvalidLockDirectory, "can't acquire lock because FLUENTD_LOCKDIR isn't set"
raise InvalidLockDirectory, "can't acquire lock because FLUENTD_LOCK_DIR isn't set"
end
File.open(get_lock_path(name), "w") do |f|
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

def string_safe_encoding(str)
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/plugin/out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def configure(conf)
@need_ruby_on_macos_workaround = true if condition.match?('', RUBY_VERSION)
end

if @need_lock && @append && fluentd_lockdir.nil?
raise InvalidLockDirectory, "must set FLUENTD_LOCKDIR on multi-worker append mode"
if @need_lock && @append && @fluentd_lock_dir.nil?
raise Fluent::InvalidLockDirectory, "must set FLUENTD_LOCK_DIR on multi-worker append mode"
end
end

Expand Down

0 comments on commit caec5b7

Please sign in to comment.