Class: Fluent::Plugin::Buffer::Metadata
- Inherits:
-
Struct
- Object
- Struct
- Fluent::Plugin::Buffer::Metadata
- Defined in:
- lib/fluent/plugin/buffer.rb
Instance Attribute Summary collapse
-
#seq ⇒ Object
Returns the value of attribute seq.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#timekey ⇒ Object
Returns the value of attribute timekey.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #<=>(o) ⇒ Object
- #cmp_variables(v1, v2) ⇒ Object
- #dup_next ⇒ Object
- #empty? ⇒ Boolean
-
#hash ⇒ Object
This is an optimization code.
-
#initialize(timekey, tag, variables) ⇒ Metadata
constructor
A new instance of Metadata.
Constructor Details
#initialize(timekey, tag, variables) ⇒ Metadata
Returns a new instance of Metadata.
73 74 75 |
# File 'lib/fluent/plugin/buffer.rb', line 73 def initialize(timekey, tag, variables) super(timekey, tag, variables, 0) end |
Instance Attribute Details
#seq ⇒ Object
Returns the value of attribute seq
72 73 74 |
# File 'lib/fluent/plugin/buffer.rb', line 72 def seq @seq end |
#tag ⇒ Object
Returns the value of attribute tag
72 73 74 |
# File 'lib/fluent/plugin/buffer.rb', line 72 def tag @tag end |
#timekey ⇒ Object
Returns the value of attribute timekey
72 73 74 |
# File 'lib/fluent/plugin/buffer.rb', line 72 def timekey @timekey end |
#variables ⇒ Object
Returns the value of attribute variables
72 73 74 |
# File 'lib/fluent/plugin/buffer.rb', line 72 def variables @variables end |
Instance Method Details
#<=>(o) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/fluent/plugin/buffer.rb', line 123 def <=>(o) timekey2 = o.timekey tag2 = o.tag variables2 = o.variables if (!!timekey ^ !!timekey2) || (!!tag ^ !!tag2) || (!!variables ^ !!variables2) # One has value in a field, but another doesn't have value in same field # This case occurs very rarely if timekey == timekey2 # including the case of nil == nil if tag == tag2 cmp_variables(variables, variables2) elsif tag.nil? -1 elsif tag2.nil? 1 else tag <=> tag2 end elsif timekey.nil? -1 elsif timekey2.nil? 1 else timekey <=> timekey2 end else # objects have values in same field pairs (comparison with non-nil and nil doesn't occur here) (timekey <=> timekey2 || 0).nonzero? || # if `a <=> b` is nil, then both are nil (tag <=> tag2 || 0).nonzero? || cmp_variables(variables, variables2) end end |
#cmp_variables(v1, v2) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/fluent/plugin/buffer.rb', line 87 def cmp_variables(v1, v2) if v1.nil? && v2.nil? return 0 elsif v1.nil? # v2 is non-nil return -1 elsif v2.nil? # v1 is non-nil return 1 end # both of v1 and v2 are non-nil v1_sorted_keys = v1.keys.sort v2_sorted_keys = v2.keys.sort if v1_sorted_keys != v2_sorted_keys if v1_sorted_keys.size == v2_sorted_keys.size v1_sorted_keys <=> v2_sorted_keys else v1_sorted_keys.size <=> v2_sorted_keys.size end else v1_sorted_keys.each do |k| a = v1[k] b = v2[k] if a && b && a != b return a <=> b elsif a && b || (!a && !b) # same value (including both are nil) next elsif a # b is nil return 1 else # a is nil (but b is non-nil) return -1 end end 0 end end |
#dup_next ⇒ Object
77 78 79 80 81 |
# File 'lib/fluent/plugin/buffer.rb', line 77 def dup_next m = dup m.seq = seq + 1 m end |
#empty? ⇒ Boolean
83 84 85 |
# File 'lib/fluent/plugin/buffer.rb', line 83 def empty? timekey.nil? && tag.nil? && variables.nil? end |
#hash ⇒ Object
This is an optimization code. Current Struct’s implementation is comparing all data. github.com/ruby/ruby/blob/0623e2b7cc621b1733a760b72af246b06c30cf96/struct.c#L1200-L1203 Actually this overhead is very small but this class is generated *per chunk* (and used in hash object). This means that this class is one of the most called object in Fluentd. See github.com/fluent/fluentd/pull/2560
160 161 162 |
# File 'lib/fluent/plugin/buffer.rb', line 160 def hash timekey.hash end |