lib/fluent/plugin/in_cat_sweep.rb in fluent-plugin-cat-sweep-0.1.4 vs lib/fluent/plugin/in_cat_sweep.rb in fluent-plugin-cat-sweep-0.1.5
- old
+ new
@@ -20,10 +20,11 @@
config_param :oneline_max_bytes, :integer, :default => 536870912 # 512MB
config_param :move_to, :string, :default => '/tmp'
config_param :remove_after_processing, :bool, :default => false
config_param :run_interval, :time, :default => 5
config_param :file_event_stream, :bool, :default => false
+ config_param :flock_with_rw_mode, :bool, :default => false
# To support log_level option implemented by Fluentd v0.10.43
unless method_defined?(:log)
define_method("log") { $log }
end
@@ -286,11 +287,16 @@
end
log.debug { %[in_cat_sweep: process: {filename:"#{original_filename}",size:#{tfile.size}}] }
end
end
+ def open_mode_for_flock
+ # When doing flock files on NFS, these files must be opend with writable mode.
+ @open_mode_for_flock ||= @flock_with_rw_mode ? "r+" : "r"
+ end
+
def lock_with_renaming(filename_from, filename_to)
- file = File.open(filename_from)
+ file = File.open(filename_from, open_mode_for_flock)
begin
if file.flock(File::LOCK_EX | File::LOCK_NB)
File.rename(filename_from, filename_to)
yield if block_given?
else