fluent-plugin-buffer-event_limited 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de3aaaafca6b7e849146aa11137d8925c79621ad
4
- data.tar.gz: 3089551096e1a8b3f203492d37e275c6167d52bb
3
+ metadata.gz: d9837aeb9ac272dabafad51da6d4e94209894cb2
4
+ data.tar.gz: ccc9d6a9d68ae52e67679c8d0a23ad2907bb47c4
5
5
  SHA512:
6
- metadata.gz: e9db61d4d7cf99dfce50fd88edf289e8ce5d617c744099e3ba72c8e91a47b679869726c087205bb695836b1651b6546b2439116df02872224e42160f61b1f5a1
7
- data.tar.gz: db5259ef0fedd5d6a1d77fc4d2f35364c210ce398443d441098b54baa14f805bedef1148ded0c94e6ce655ec6b68f2370c65d49b78c97dc46606789ccd428a4b
6
+ metadata.gz: 22ddeaedff64fd9c1bea85e4f54e2c3ad44f24f1b4d844e9d2413103abb506322420d326b8efb20c260b8935f567d70d5cd53be0796cc75b82ea2c4a8a315317
7
+ data.tar.gz: 2e7ff811aeb6f0397bcd2d62d8dd373fa034939ee7c8513c2a3e181165cce725fc6a3ab3d98f16727b46022c3ae835717452196b4a7eea68db9b7cef6c6340df
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "fluent-plugin-buffer-event_limited"
5
- spec.version = "0.1.3"
5
+ spec.version = "0.1.4"
6
6
  spec.authors = ["TAGOMORI Satoshi", 'Gergo Sulymosi']
7
7
  spec.email = ["tagomoris@gmail.com", 'gergo.sulymosi@gmail.com']
8
8
  spec.description = %q{Fluentd memory buffer plugin with many types of chunk limits}
@@ -6,7 +6,7 @@ module Fluent
6
6
 
7
7
  def initialize(key, path, unique_id, separator, mode = "a+", symlink_path = nil)
8
8
  super(key, path, unique_id, mode = "a+", symlink_path = nil)
9
- init_counter(path, separator)
9
+ init_counter(separator)
10
10
  end
11
11
 
12
12
  def <<(data)
@@ -18,18 +18,22 @@ module Fluent
18
18
 
19
19
  private
20
20
 
21
- def init_counter(path, separator)
22
- @record_counter = \
21
+ def init_counter(separator)
22
+ old_pos = @file.pos
23
+ @file.rewind
24
+
25
+ @record_counter = (
23
26
  case separator
24
- when 'msgpack'
25
- MessagePack::Unpacker.new(File.open(path)).each.inject(0) { |c, _| c + 1 }
26
- when 'newline'
27
- File.foreach(path, $/).inject(0) { |c, _| c + 1 }
28
- when 'tab'
29
- File.foreach(path, "\t").inject(0) { |c, _| c + 1 }
27
+ when 'msgpack' then MessagePack::Unpacker.new(@file).each
28
+ when 'newline' then @file.each($/)
29
+ when 'tab' then @file.each("\t")
30
30
  else
31
31
  raise ArgumentError, "Separator #{separator.inspect} is not supported"
32
32
  end
33
+ ).inject(0) { |c, _| c + 1 }
34
+
35
+ @file.pos = old_pos
36
+ $log.trace("#init_counter(#{[path, separator].join(', ')}) => #{@record_counter}")
33
37
  end
34
38
  end
35
39
 
@@ -39,6 +43,11 @@ module Fluent
39
43
  config_param :buffer_chunk_records_limit, :integer, :default => Float::INFINITY
40
44
  config_param :buffer_chunk_message_separator, :string, :default => 'msgpack'
41
45
 
46
+ def storable?(chunk, data)
47
+ (chunk.record_counter < @buffer_chunk_records_limit) &&
48
+ ((chunk.size + data.bytesize) <= @buffer_chunk_limit)
49
+ end
50
+
42
51
  def new_chunk(key)
43
52
  encoded_key = encode_key(key)
44
53
  path, tsuffix = make_path(encoded_key, 'b')
@@ -53,24 +62,25 @@ module Fluent
53
62
  maps = []
54
63
  queues = []
55
64
 
56
- Dir.glob("#{@buffer_path_prefix}*#{@buffer_path_suffix}") {|path|
65
+ Dir.glob("#{@buffer_path_prefix}*#{@buffer_path_suffix}") do |path|
57
66
  identifier_part = chunk_identifier_in_path(path)
58
- if m = PATH_MATCH.match(identifier_part)
59
- key = decode_key(m[1])
60
- bq = m[2]
61
- tsuffix = m[3]
62
- timestamp = m[3].to_i(16)
63
- unique_id = tsuffix_to_unique_id(tsuffix)
64
-
65
- if bq == 'b'
66
- chunk = EventLimitedBufferChunk.new(key, path, unique_id, @buffer_chunk_message_separator, "a+")
67
- maps << [timestamp, chunk]
68
- elsif bq == 'q'
69
- chunk = EventLimitedBufferChunk.new(key, path, unique_id, @buffer_chunk_message_separator, "r")
70
- queues << [timestamp, chunk]
71
- end
67
+ next unless (m = PATH_MATCH.match(identifier_part))
68
+
69
+ key = decode_key(m[1])
70
+ bq = m[2]
71
+ tsuffix = m[3]
72
+ timestamp = m[3].to_i(16)
73
+ unique_id = tsuffix_to_unique_id(tsuffix)
74
+
75
+ case bq
76
+ when 'b'
77
+ chunk = EventLimitedBufferChunk.new(key, path, unique_id, @buffer_chunk_message_separator, "a+")
78
+ maps << [timestamp, chunk]
79
+ when 'q'
80
+ chunk = EventLimitedBufferChunk.new(key, path, unique_id, @buffer_chunk_message_separator, "r")
81
+ queues << [timestamp, chunk]
72
82
  end
73
- }
83
+ end
74
84
 
75
85
  map = {}
76
86
  maps
@@ -83,10 +93,5 @@ module Fluent
83
93
 
84
94
  return queue, map
85
95
  end
86
-
87
- def storable?(chunk, data)
88
- chunk.record_counter < @buffer_chunk_records_limit &&
89
- (chunk.size + data.bytesize) <= @buffer_chunk_limit
90
- end
91
96
  end
92
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-buffer-event_limited
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-24 00:00:00.000000000 Z
12
+ date: 2015-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler