mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
As pointed out in this post merge review comment, there is a window
where we could miss a pipeline transitioning from 'loading' to 'running'
in the original fix, as separate calls are made to the pipeline registry.
This commit fixes that by making a single call to the pipeline registry which
allows for also returning pipelines in the `loading` state.
Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
(cherry picked from commit 1291b5edcc
)
Co-authored-by: Rob Bavey <rob.bavey@elastic.co>
This commit is contained in:
parent
8079f0a434
commit
788c72b67e
2 changed files with 12 additions and 6 deletions
|
@ -321,7 +321,7 @@ class LogStash::Agent
|
||||||
end
|
end
|
||||||
|
|
||||||
def no_pipeline?
|
def no_pipeline?
|
||||||
@pipelines_registry.running_pipelines.empty? && @pipelines_registry.loading_pipelines.empty?
|
@pipelines_registry.running_pipelines(include_loading: true).empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -24,8 +24,8 @@ module LogStash
|
||||||
@pipeline = pipeline
|
@pipeline = pipeline
|
||||||
@loading = Concurrent::AtomicBoolean.new(false)
|
@loading = Concurrent::AtomicBoolean.new(false)
|
||||||
|
|
||||||
# this class uses a lock to ensure thread safe visibility.
|
# this class uses a reentrant lock to ensure thread safe visibility.
|
||||||
@lock = Mutex.new
|
@lock = Monitor.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def terminated?
|
def terminated?
|
||||||
|
@ -61,6 +61,12 @@ module LogStash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def synchronize
|
||||||
|
@lock.synchronize do
|
||||||
|
yield self
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def pipeline
|
def pipeline
|
||||||
@lock.synchronize { @pipeline }
|
@lock.synchronize { @pipeline }
|
||||||
end
|
end
|
||||||
|
@ -265,8 +271,8 @@ module LogStash
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Hash{String=>Pipeline}]
|
# @return [Hash{String=>Pipeline}]
|
||||||
def running_pipelines
|
def running_pipelines(include_loading: false)
|
||||||
select_pipelines { |state| state.running? }
|
select_pipelines { |state| state.running? || (include_loading && state.loading?) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def loading_pipelines
|
def loading_pipelines
|
||||||
|
@ -296,7 +302,7 @@ module LogStash
|
||||||
# @return [Hash{String=>Pipeline}]
|
# @return [Hash{String=>Pipeline}]
|
||||||
def select_pipelines(&optional_state_filter)
|
def select_pipelines(&optional_state_filter)
|
||||||
@states.each_with_object({}) do |(id, state), memo|
|
@states.each_with_object({}) do |(id, state), memo|
|
||||||
if state && (!block_given? || yield(state))
|
if state && (!block_given? || state.synchronize(&optional_state_filter))
|
||||||
memo[id] = state.pipeline
|
memo[id] = state.pipeline
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue