-
Notifications
You must be signed in to change notification settings - Fork 3.5k
delete pipeline in registry #12414
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
Merged
kaisecheng
merged 7 commits into
elastic:master
from
kaisecheng:fix/delete-recreate-same-pipeline
Nov 6, 2020
Merged
delete pipeline in registry #12414
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
413556d
delete pipeline in registry if finished
kaisecheng f62525e
delete pipeline in registry
kaisecheng be9b413
add test case
kaisecheng fcc310c
add test cases
kaisecheng ba7d49a
update comment
kaisecheng 00c63a8
optimize pipeline_configs
kaisecheng 23ca57c
format code
kaisecheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,14 +41,21 @@ def resolve(pipelines_registry, pipeline_configs) | |
| end | ||
| end | ||
|
|
||
| configured_pipelines = pipeline_configs.map { |config| config.pipeline_id.to_sym } | ||
| 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 terminated pipeline is not in the pipeline_configs, 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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,stopanddeleteto 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_idshould 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?
Uh oh!
There was an error while loading. Please reload this page.
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.