fluentd 0.14.22 → 0.14.23.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 216e64dfd14f91902147d2450a8ea3c10f8900fe
4
- data.tar.gz: 107c33b29d5e6a7f18d823795a8b174978b364d7
3
+ metadata.gz: 6e963518d8ad90373d793c9af9275cc45720d45e
4
+ data.tar.gz: 43875ee26f0702c7c23514d5b38ef8b163e0e6d8
5
5
  SHA512:
6
- metadata.gz: 2f34dc55b3dab852af483ae93f2d95fcfbc0dd9c9daa32f407f767c1d2c4670b4ff7508883e6e4d04d8eed54c6d73852f2c1a08973304198d243db2c6645c068
7
- data.tar.gz: e0ccbe9c85711e66da262611cbac23763d8712c4250f64e08e8b2634b8e678bc5eebb7f67df461125ee5b01632ca8e86b03a57b211d8b760f0092f8606d3be8c
6
+ metadata.gz: ec41c99be159e167051b78446a57e89d7627b7f940d10f4c5bc012224c5e7756fd4cbeccd4e4e59fc2d96204e57851f85c5e089896a4fd0acbe914bfd82e3158
7
+ data.tar.gz: 8b2f5f28e11ed7342f816f1e35e5fa9c4de984aad1cbf24c36c273ddc90f4982b06386bdebd31a8259b2dd924d965b84bc194e28cbc6bb6436a71d62109c0cb1
@@ -62,6 +62,74 @@ module Fluent
62
62
  def empty?
63
63
  timekey.nil? && tag.nil? && variables.nil?
64
64
  end
65
+
66
+ def cmp_variables(v1, v2)
67
+ if v1.nil? && v2.nil?
68
+ return 0
69
+ elsif v1.nil? # v2 is non-nil
70
+ return -1
71
+ elsif v2.nil? # v1 is non-nil
72
+ return 1
73
+ end
74
+ # both of v1 and v2 are non-nil
75
+ v1_sorted_keys = v1.keys.sort
76
+ v2_sorted_keys = v2.keys.sort
77
+ if v1_sorted_keys != v2_sorted_keys
78
+ if v1_sorted_keys.size == v2_sorted_keys.size
79
+ v1_sorted_keys <=> v2_sorted_keys
80
+ else
81
+ v1_sorted_keys.size <=> v2_sorted_keys.size
82
+ end
83
+ else
84
+ v1_sorted_keys.each do |k|
85
+ a = v1[k]
86
+ b = v2[k]
87
+ if a && b && a != b
88
+ return a <=> b
89
+ elsif a && b || (!a && !b) # same value (including both are nil)
90
+ next
91
+ elsif a # b is nil
92
+ return 1
93
+ else # a is nil (but b is non-nil)
94
+ return -1
95
+ end
96
+ end
97
+
98
+ 0
99
+ end
100
+ end
101
+
102
+ def <=>(o)
103
+ timekey2 = o.timekey
104
+ tag2 = o.tag
105
+ variables2 = o.variables
106
+ if (!!timekey ^ !!timekey2) || (!!tag ^ !!tag2) || (!!variables ^ !!variables2)
107
+ # One has value in a field, but another doesn't have value in same field
108
+ # This case occurs very rarely
109
+ if timekey == timekey2 # including the case of nil == nil
110
+ if tag == tag2
111
+ cmp_variables(variables, variables2)
112
+ elsif tag.nil?
113
+ -1
114
+ elsif tag2.nil?
115
+ 1
116
+ else
117
+ tag <=> tag2
118
+ end
119
+ elsif timekey.nil?
120
+ -1
121
+ elsif timekey2.nil?
122
+ 1
123
+ else
124
+ timekey <=> timekey2
125
+ end
126
+ else
127
+ # objects have values in same field pairs (comparison with non-nil and nil doesn't occur here)
128
+ (timekey <=> timekey2 || 0).nonzero? || # if `a <=> b` is nil, then both are nil
129
+ (tag <=> tag2 || 0).nonzero? ||
130
+ cmp_variables(variables, variables2)
131
+ end
132
+ end
65
133
  end
66
134
 
67
135
  # for tests
@@ -203,7 +271,9 @@ module Fluent
203
271
  chunks_to_enqueue = []
204
272
 
205
273
  begin
206
- metadata_and_data.each do |metadata, data|
274
+ # sort metadata to get lock of chunks in same order with other threads
275
+ metadata_and_data.keys.sort.each do |metadata|
276
+ data = metadata_and_data[metadata]
207
277
  write_once(metadata, data, format: format, size: size) do |chunk, adding_bytesize|
208
278
  chunk.mon_enter # add lock to prevent to be committed/rollbacked from other threads
209
279
  operated_chunks << chunk
@@ -55,13 +55,12 @@ module Fluent::Plugin
55
55
  def start
56
56
  super
57
57
 
58
- @buffer = ''
59
58
  server_create(:in_tcp_server, @port, bind: @bind) do |data, conn|
60
- @buffer << data
59
+ conn.buffer << data
61
60
  begin
62
61
  pos = 0
63
- while i = @buffer.index(@delimiter, pos)
64
- msg = @buffer[pos...i]
62
+ while i = conn.buffer.index(@delimiter, pos)
63
+ msg = conn.buffer[pos...i]
65
64
  pos = i + @delimiter.length
66
65
 
67
66
  @parser.parse(msg) do |time, record|
@@ -77,7 +76,7 @@ module Fluent::Plugin
77
76
  router.emit(tag, time, record)
78
77
  end
79
78
  end
80
- @buffer.slice!(0, pos) if pos > 0
79
+ conn.buffer.slice!(0, pos) if pos > 0
81
80
  end
82
81
  end
83
82
  end
@@ -425,9 +425,12 @@ module Fluent
425
425
  end
426
426
 
427
427
  class TCPCallbackSocket < CallbackSocket
428
+ attr_accessor :buffer
429
+
428
430
  def initialize(sock)
429
431
  super("tcp", sock, [:data, :write_complete, :close])
430
432
  @peeraddr = @sock.peeraddr
433
+ @buffer = ''
431
434
  end
432
435
 
433
436
  def write(data)
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Fluent
18
18
 
19
- VERSION = '0.14.22'
19
+ VERSION = '0.14.23.rc1'
20
20
 
21
21
  end
@@ -851,7 +851,8 @@ class BufferTest < Test::Unit::TestCase
851
851
  assert{ @p.stage[@dm1].size == 2 }
852
852
  assert !@p.stage[@dm1].rollbacked
853
853
 
854
- @p.stage[@dm1].failing = true
854
+ meta_list = [@dm0, @dm1, @dm2, @dm3].sort
855
+ @p.stage[meta_list.last].failing = true
855
856
 
856
857
  assert_raise(FluentPluginBufferTest::DummyMemoryChunkError) do
857
858
  @p.write({ @dm2 => [row], @dm3 => [row], @dm0 => [row, row, row], @dm1 => [row, row] })
@@ -0,0 +1,89 @@
1
+ require_relative '../helper'
2
+ require 'fluent/plugin/buffer'
3
+
4
+ class BufferMetadataTest < Test::Unit::TestCase
5
+
6
+ def meta(timekey=nil, tag=nil, variables=nil)
7
+ Fluent::Plugin::Buffer::Metadata.new(timekey, tag, variables)
8
+ end
9
+
10
+ setup do
11
+ Fluent::Test.setup
12
+ end
13
+
14
+ sub_test_case 'about metadata' do
15
+ test 'comparison of variables should be stable' do
16
+ m = meta(nil, nil, nil)
17
+ # different sets of keys
18
+ assert_equal(-1, m.cmp_variables({}, {a: 1}))
19
+ assert_equal(1, m.cmp_variables({a: 1}, {}))
20
+ assert_equal(1, m.cmp_variables({c: 1}, {a: 1}))
21
+ assert_equal(-1, m.cmp_variables({a: 1}, {a: 1, b: 2}))
22
+ assert_equal(1, m.cmp_variables({a: 1, c: 1}, {a: 1, b: 2}))
23
+ assert_equal(1, m.cmp_variables({a: 1, b: 0, c: 1}, {a: 1, b: 2}))
24
+ # same set of keys
25
+ assert_equal(-1, m.cmp_variables({a: 1}, {a: 2}))
26
+ assert_equal(-1, m.cmp_variables({a: 1, b: 0}, {a: 1, b: 1}))
27
+ assert_equal(-1, m.cmp_variables({a: 1, b: 1, c: 100}, {a: 1, b: 1, c: 200}))
28
+ assert_equal(-1, m.cmp_variables({b: 1, c: 100, a: 1}, {a: 1, b: 1, c: 200})) # comparison sorts keys
29
+ assert_equal(-1, m.cmp_variables({a: nil}, {a: 1}))
30
+ assert_equal(-1, m.cmp_variables({a: 1, b: nil}, {a: 1, b: 1}))
31
+ end
32
+
33
+ test 'comparison of metadata should be stable' do
34
+ n = Time.now.to_i
35
+
36
+ assert_equal(0, meta(nil, nil, nil) <=> meta(nil, nil, nil))
37
+ assert_equal(0, meta(n, nil, nil) <=> meta(n, nil, nil))
38
+ assert_equal(0, meta(nil, "t1", nil) <=> meta(nil, "t1", nil))
39
+ assert_equal(0, meta(nil, nil, {}) <=> meta(nil, nil, {}))
40
+ assert_equal(0, meta(nil, nil, {a: "1"}) <=> meta(nil, nil, {a: "1"}))
41
+ assert_equal(0, meta(n, nil, {}) <=> meta(n, nil, {}))
42
+ assert_equal(0, meta(n, "t1", {}) <=> meta(n, "t1", {}))
43
+ assert_equal(0, meta(n, "t1", {a: "x", b: 10}) <=> meta(n, "t1", {a: "x", b: 10}))
44
+
45
+ # timekey is 1st comparison key
46
+ assert_equal(-1, meta(n - 300, nil, nil) <=> meta(n - 270, nil, nil))
47
+ assert_equal(1, meta(n + 1, "a", nil) <=> meta(n - 1, "b", nil))
48
+ assert_equal(-1, meta(n - 1, nil, {a: 100}) <=> meta(n + 1, nil, {}))
49
+
50
+ # tag is 2nd
51
+ assert_equal(-1, meta(nil, "a", {}) <=> meta(nil, "b", {}))
52
+ assert_equal(-1, meta(n, "a", {}) <=> meta(n, "b", {}))
53
+ assert_equal(1, meta(nil, "x", {a: 1}) <=> meta(nil, "t", {}))
54
+ assert_equal(1, meta(n, "x", {a: 1}) <=> meta(n, "t", {}))
55
+ assert_equal(1, meta(nil, "x", {a: 1}) <=> meta(nil, "t", {a: 1}))
56
+ assert_equal(1, meta(n, "x", {a: 1}) <=> meta(n, "t", {a: 2}))
57
+ assert_equal(1, meta(n, "x", {a: 1}) <=> meta(n, "t", {a: 10, b: 1}))
58
+
59
+ # variables is the last
60
+ assert_equal(-1, meta(nil, nil, {}) <=> meta(nil, nil, {a: 1}))
61
+ assert_equal(-1, meta(n, "t", {}) <=> meta(n, "t", {a: 1}))
62
+ assert_equal(1, meta(n, "t", {a: 1}) <=> meta(n, "t", {}))
63
+ assert_equal(-1, meta(n, "t", {a: 1}) <=> meta(n, "t", {a: 2}))
64
+ assert_equal(-1, meta(n, "t", {a: 1}) <=> meta(n, "t", {a: 1, b: 1}))
65
+ assert_equal(1, meta(nil, nil, {b: 1}) <=> meta(nil, nil, {a: 1}))
66
+ assert_equal(1, meta(n, "t", {b: 1}) <=> meta(n, "t", {a: 1}))
67
+ end
68
+
69
+ test 'metadata can be sorted' do
70
+ n = Time.now.to_i
71
+ m0 = meta(nil, nil, nil)
72
+ m1 = meta(n - 1, nil, nil)
73
+ m2 = meta(n - 1, "a", nil)
74
+ m3 = meta(n - 1, "a", {a: 1})
75
+ m4 = meta(n - 1, "a", {a: 100})
76
+ m5 = meta(n - 1, "a", {a: 100, b: 1})
77
+ m6 = meta(n - 1, "aa", nil)
78
+ m7 = meta(n - 1, "aa", {a: 1})
79
+ m8 = meta(n - 1, "b", nil)
80
+ m9 = meta(n, nil, nil)
81
+ m10 = meta(n + 1, nil, {a: 1})
82
+ expected = [m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10].freeze
83
+ ary = expected.dup
84
+ 100.times do
85
+ assert_equal expected, ary.shuffle.sort
86
+ end
87
+ end
88
+ end
89
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluentd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.22
4
+ version: 0.14.23.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-02 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -639,6 +639,7 @@ files:
639
639
  - test/plugin/test_in_udp.rb
640
640
  - test/plugin/test_in_unix.rb
641
641
  - test/plugin/test_input.rb
642
+ - test/plugin/test_metadata.rb
642
643
  - test/plugin/test_multi_output.rb
643
644
  - test/plugin/test_out_copy.rb
644
645
  - test/plugin/test_out_exec.rb
@@ -735,9 +736,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
735
736
  version: '2.1'
736
737
  required_rubygems_version: !ruby/object:Gem::Requirement
737
738
  requirements:
738
- - - ">="
739
+ - - ">"
739
740
  - !ruby/object:Gem::Version
740
- version: '0'
741
+ version: 1.3.1
741
742
  requirements: []
742
743
  rubyforge_project:
743
744
  rubygems_version: 2.6.13
@@ -806,6 +807,7 @@ test_files:
806
807
  - test/plugin/test_in_udp.rb
807
808
  - test/plugin/test_in_unix.rb
808
809
  - test/plugin/test_input.rb
810
+ - test/plugin/test_metadata.rb
809
811
  - test/plugin/test_multi_output.rb
810
812
  - test/plugin/test_out_copy.rb
811
813
  - test/plugin/test_out_exec.rb