Skip to content

Commit

Permalink
Merge pull request #2564 from ganmacs/opt-queue
Browse files Browse the repository at this point in the history
Add option to check queued? loosely
  • Loading branch information
repeatedly authored Aug 17, 2019
2 parents c27339d + ecf52c0 commit 41fb79b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions lib/fluent/plugin/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,12 @@ def queued_records
synchronize { @queue.reduce(0){|r, chunk| r + chunk.size } }
end

def queued?(metadata=nil)
synchronize do
if metadata
n = @queued_num[metadata]
n && n.nonzero?
else
!@queue.empty?
def queued?(metadata = nil, optimistic: false)
if optimistic
optimistic_queued?(metadata)
else
synchronize do
optimistic_queued?(metadata)
end
end
end
Expand Down Expand Up @@ -739,6 +738,15 @@ def statistics

private

def optimistic_queued?(metadata = nil)
if metadata
n = @queued_num[metadata]
n && n.nonzero?
else
!@queue.empty?
end
end

def add_timekey(t)
@mutex.synchronize do
@timekeys[t] += 1
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def emit_buffered(tag, es)
@counter_mutex.synchronize{ @emit_count += 1 }
begin
execute_chunking(tag, es, enqueue: (@flush_mode == :immediate))
if !@retry && @buffer.queued?
if !@retry && @buffer.queued?(nil, optimistic: true)
submit_flush_once
end
rescue
Expand Down

0 comments on commit 41fb79b

Please sign in to comment.