Skip to content
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

Modify clean_removed handling #3827

Merged
merged 2 commits into from
Apr 18, 2017
Merged

Conversation

ruflin
Copy link
Member

@ruflin ruflin commented Mar 28, 2017

Previously if a file could be found under the same name as a state, the state was not removed. But this could have been also an other file. With this change also the file itself is compared and if it is not the same file, the state will be removed. This has the affect that in case a file is renamed after monitoring the file finished, the state will be removed. In most cases this should not have any side affect.

The positive effect of this change is that there will be less left over states in the registry.

Closes elastic#3789

@ruflin ruflin added Filebeat Filebeat in progress Pull request is currently in progress. labels Mar 28, 2017
@ruflin ruflin force-pushed the improved-clean-removed branch 2 times, most recently from 1c223e5 to d774da1 Compare April 6, 2017 08:40
@ruflin ruflin added review and removed in progress Pull request is currently in progress. labels Apr 6, 2017
@ruflin
Copy link
Member Author

ruflin commented Apr 6, 2017

@elastic/beats Would be good to hear your thoughts on this change.

@@ -94,24 +94,35 @@ func (l *Log) Run() {
if l.config.CleanRemoved {
for _, state := range l.Prospector.states.GetStates() {
// os.Stat will return an error in case the file does not exist
_, err := os.Stat(state.Source)
stat, err := os.Stat(state.Source)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be more strict here and check vs os.PathError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. What should we do in all other cases? Log an error and not remove the state?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that's probably the best we can do. os.PathError is all that can return right now but you never now..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

// Only clean up files where state is Finished
if state.Finished {
state.TTL = 0
err := l.Prospector.updateState(input.NewEvent(state))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could return here and check the error in the caller, and also remove the else

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to return directly if state is not finished but I kept the error handling local.

Previously if a file could be found under the same name as a state, the state was not removed. But this could have been also an other file. With this change also the file itself is compared and if it is not the same file, the state will be removed. This has the affect that in case a file is renamed after monitoring the file finished, the state will be removed. In most cases this should not have any side affect.

The positive effect of this change is that there will be less left over states in the registry.

Closes elastic#3789
Copy link
Member Author

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review changes implemented and rebase on master

// Only clean up files where state is Finished
if state.Finished {
state.TTL = 0
err := l.Prospector.updateState(input.NewEvent(state))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to return directly if state is not finished but I kept the error handling local.

@@ -94,24 +94,35 @@ func (l *Log) Run() {
if l.config.CleanRemoved {
for _, state := range l.Prospector.states.GetStates() {
// os.Stat will return an error in case the file does not exist
_, err := os.Stat(state.Source)
stat, err := os.Stat(state.Source)
if err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@7AC 7AC merged commit caf398f into elastic:master Apr 18, 2017
@ruflin ruflin deleted the improved-clean-removed branch April 18, 2017 17:11
@tsg tsg mentioned this pull request Jul 24, 2017
28 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants