-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix harvester shutdown for prospector reloading #3563
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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,90 @@ | ||
package channel | ||
|
||
import ( | ||
"sync" | ||
"sync/atomic" | ||
|
||
"github.com/elastic/beats/filebeat/input" | ||
) | ||
|
||
// Outlet struct is used to be passed to an object which needs an outlet | ||
// | ||
// The difference between signal and done channel is as following: | ||
// - signal channel can be added through SetSignal and is used to | ||
// interrupt events sent through OnEventSignal- | ||
// - done channel is used to close and stop the outlet | ||
// | ||
// If SetSignal is used, it must be ensure that there is only one event producer. | ||
type Outlet struct { | ||
wg *sync.WaitGroup // Use for counting active events | ||
done <-chan struct{} | ||
signal <-chan struct{} | ||
channel chan *input.Event | ||
isOpen int32 // atomic indicator | ||
} | ||
|
||
func NewOutlet( | ||
done <-chan struct{}, | ||
c chan *input.Event, | ||
wg *sync.WaitGroup, | ||
) *Outlet { | ||
return &Outlet{ | ||
done: done, | ||
channel: c, | ||
wg: wg, | ||
isOpen: 1, | ||
} | ||
} | ||
|
||
// SetSignal sets the signal channel for OnEventSignal | ||
// If SetSignal is used, it must be ensure that only one producer exists. | ||
func (o *Outlet) SetSignal(signal <-chan struct{}) { | ||
o.signal = signal | ||
} | ||
|
||
func (o *Outlet) OnEvent(event *input.Event) bool { | ||
open := atomic.LoadInt32(&o.isOpen) == 1 | ||
if !open { | ||
return false | ||
} | ||
|
||
if o.wg != nil { | ||
o.wg.Add(1) | ||
} | ||
|
||
select { | ||
case <-o.done: | ||
if o.wg != nil { | ||
o.wg.Done() | ||
} | ||
atomic.StoreInt32(&o.isOpen, 0) | ||
return false | ||
case o.channel <- event: | ||
return true | ||
} | ||
} | ||
|
||
// OnEventSignal can be stopped by the signal that is set with SetSignal | ||
// This does not close the outlet. Only OnEvent does close the outlet. | ||
// If OnEventSignal is used, it must be ensured that only one producer is used. | ||
func (o *Outlet) OnEventSignal(event *input.Event) bool { | ||
open := atomic.LoadInt32(&o.isOpen) == 1 | ||
if !open { | ||
return false | ||
} | ||
|
||
if o.wg != nil { | ||
o.wg.Add(1) | ||
} | ||
|
||
select { | ||
case <-o.signal: | ||
if o.wg != nil { | ||
o.wg.Done() | ||
} | ||
o.signal = nil | ||
return false | ||
case o.channel <- event: | ||
return true | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.
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.
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.
if outlet is used by multiple producers this can race I think. If it's used by one single producer only, there is no need for the atomics. Also, setting a channel to
nil
has a similar effect as anil
channel blocks forever and a closed channel always receives. e.g.: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.
I would prefer to keep the current implementation to make it possible to use the same Outlet also for prospector to spooler in the future. So we only have one implementation which supports both use cases.
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.
it's time to get rid of the spooler...