From ba7c20176aa6f7ced1d4c39727609a310d9f0c05 Mon Sep 17 00:00:00 2001 From: Masahiro Nakagawa Date: Fri, 10 May 2019 10:07:44 +0900 Subject: [PATCH 1/2] storage_local: Don't stop fluentd start when existing file is empty. ref #2373 Signed-off-by: Masahiro Nakagawa --- lib/fluent/plugin/storage_local.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/storage_local.rb b/lib/fluent/plugin/storage_local.rb index 7ccad620db..d6107efbb1 100644 --- a/lib/fluent/plugin/storage_local.rb +++ b/lib/fluent/plugin/storage_local.rb @@ -87,7 +87,12 @@ def configure(conf) if File.exist?(@path) raise Fluent::ConfigError, "Plugin storage path '#{@path}' is not readable/writable" unless File.readable?(@path) && File.writable?(@path) begin - data = Yajl::Parser.parse(open(@path, 'r:utf-8'){ |io| io.read }) + data = open(@path, 'r:utf-8') { |io| io.read } + if data.empty? + log.warn "detect empty plugin storage file during startup. Ignored: #{@path}" + return + end + data = Yajl::Parser.parse(data) raise Fluent::ConfigError, "Invalid contents (not object) in plugin storage file: '#{@path}'" unless data.is_a?(Hash) rescue => e log.error "failed to read data from plugin storage file", path: @path, error: e From a9a8586ebfddf15dbca699cf862385e2038ececa Mon Sep 17 00:00:00 2001 From: Masahiro Nakagawa Date: Fri, 10 May 2019 10:10:57 +0900 Subject: [PATCH 2/2] storage_local: Call fsync for XFS. ref #2373 Signed-off-by: Masahiro Nakagawa --- lib/fluent/plugin/storage_local.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fluent/plugin/storage_local.rb b/lib/fluent/plugin/storage_local.rb index d6107efbb1..9fa88dfcb7 100644 --- a/lib/fluent/plugin/storage_local.rb +++ b/lib/fluent/plugin/storage_local.rb @@ -133,7 +133,7 @@ def save tmp_path = @path + '.tmp' begin json_string = Yajl::Encoder.encode(@store, pretty: @pretty_print) - open(tmp_path, 'w:utf-8', @mode){ |io| io.write json_string } + open(tmp_path, 'w:utf-8', @mode) { |io| io.write json_string; io.fsync } File.rename(tmp_path, @path) rescue => e log.error "failed to save data for plugin storage to file", path: @path, tmp: tmp_path, error: e