-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
delete pipeline in registry #12414
delete pipeline in registry #12414
Changes from 4 commits
413556d
f62525e
be9b413
fcc310c
ba7d49a
00c63a8
23ca57c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
require "logstash/pipeline_action/base" | ||
|
||
module LogStash module PipelineAction | ||
class Delete < Base | ||
attr_reader :pipeline_id | ||
|
||
def initialize(pipeline_id) | ||
@pipeline_id = pipeline_id | ||
end | ||
|
||
def execute(agent, pipelines_registry) | ||
success = pipelines_registry.delete_pipeline(@pipeline_id) | ||
|
||
LogStash::ConvergeResult::ActionResult.create(self, success) | ||
end | ||
|
||
def to_s | ||
"PipelineAction::Delete<#{pipeline_id}>" | ||
end | ||
end | ||
end end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,14 +41,20 @@ def resolve(pipelines_registry, pipeline_configs) | |
end | ||
end | ||
|
||
configured_pipelines = pipeline_configs.map { |config| config.pipeline_id.to_sym } | ||
configured_pipelines = pipeline_configs.map { |config| config.pipeline_id.to_sym }.to_set | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am assuming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, ok. But TBH given the small number of pipelines we are dealing with this extra To push that micro optimization further I would try to avoid the Array -> Array -> Set and directly produce a Something like? configured_pipelines = pipeline_configs.each_with_object(Set.new) { |config, set| set.add(config.pipeline_id.to_sym) } |
||
|
||
# If one of the running pipeline is not in the pipeline_configs, we assume that we need to | ||
# stop it. | ||
pipelines_registry.running_pipelines.keys | ||
.select { |pipeline_id| !configured_pipelines.include?(pipeline_id) } | ||
.each { |pipeline_id| actions << LogStash::PipelineAction::Stop.new(pipeline_id) } | ||
|
||
# If one of the stopping pipeline is not in the pipeline_configs, we assume that we need to | ||
# delete it in registry. | ||
pipelines_registry.non_running_pipelines.keys | ||
.select { |pipeline_id| !configured_pipelines.include?(pipeline_id) } | ||
.each { |pipeline_id| actions << LogStash::PipelineAction::Delete.new(pipeline_id)} | ||
|
||
actions.sort # See logstash/pipeline_action.rb | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please review the locking mechanism.
the idea is to keep
locks[pipeline_id]
forever forcreate
,reload
,stop
anddelete
to stay mutually exclusiveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO
@locks.delete(pipeline_id)
need to stay there because keeping@locks[pipeline_id]
does not make sense if not also keeping@states[pipeline_id]
. Once a pipeline is removed, it'spipeline_id
should not exist anymore in the registry at all.I am not sure I understand in which condition it would be useful to keep it around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread A, B and C want to update @State of pipeline_id 1
A removes lock in @locks. B holds the old lock
C gets a new lock for pipeline_id 1 as A removed it. B and C have the right to update @State of pipeline_id 1
I think the purpose of @locks is to ensure only one thread can edit the same pipeline_id state simultaneously.
If @locks keeps the lock, it can keep the integrity of action A,B,C
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! 💡 I see what you mean. I think you are right here. Let me go over this a bit more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So yes +1 on this change per your reasoning above. The downside here is a memory leak for removed pipelines that will never be recreated but practically speaking the potential for this becoming a problem is extremely low.
I guess that the alternative would be to rethink/refactor the locking logic but that does not seem necessary.
I would probably add a comment about this and maybe link it to this discussion here so that if this code is revisited in the future it is more explicit in the code.