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

Start a new harvester when file was truncated #1882

Merged
merged 1 commit into from
Jun 17, 2016

Conversation

ruflin
Copy link
Collaborator

@ruflin ruflin commented Jun 17, 2016

Currently file truncation was handeld by the reader. In case of truncation, the same harvester stayed open and the reader just continued reading from the beginning. This is the most efficient way to make sure the truncated file is immidiately read.

From a logical point of view, truncation of a file is very similar to creating a new file. Instead of letting the reader just continue, the harvester is closed and a completely new harvester is started with a new reader. This means the reader only needs to detect a truncation, but doesnt' have to decide what happens.

The consequence of this change is that it can take up to scan_frequency to read the truncated file, but that is the same behaviour as for a new file. In addition the file handler will be closed when the old harvester is stopped.

@@ -74,7 +74,7 @@ func (h *Harvester) Harvest() {

h.SetOffset(0)
seeker.Seek(h.getOffset(), os.SEEK_SET)
continue
return
Copy link

Choose a reason for hiding this comment

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

The complete if err == errFileTruncate can be removed. Where/how does prospector detect the file being truncated? Still h.SetOffset(0) required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is the harvester that detects that the file was truncated, not prospector. The prospector only sees a finished harvester and opens a new one if the offset (which is 0).

Copy link

Choose a reason for hiding this comment

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

In this case it's still too much code. There is no need to call seeker.Seek.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, will remove it.

Currently file truncation was handled by the reader. In case of truncation, the same harvester stayed open and the reader just continued reading from the beginning. This is the most efficient way to make sure the truncated file is immediately read.

From a logical point of view, truncation of a file is very similar to creating a new file. Instead of letting the reader just continue, the harvester is closed and a completely new harvester is started with a new reader. This means the reader only needs to detect a truncation, but doesnt' have to decide what happens.

The consequence of this change is that it can take up to `scan_frequency` to read the truncated file, but that is the same behaviour as for a new file. In addition the file handler will be closed when the old harvester is stopped.
@ruflin ruflin force-pushed the refactor-truncated branch from f5ff342 to c13f555 Compare June 17, 2016 14:04
logp.Err("can not seek source")
return
}

logp.Info("File was truncated. Begin reading file from offset 0: %s", h.Path)
Copy link

Choose a reason for hiding this comment

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

Is info message enough? There is a chance we did loose lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a good point. We should make a WARN out of this and add a comment that this means that not all content was read potentially. WDYT?

But I suggest to make this in a second PR, ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@urso after our conversation yesterday about warn messages, I will leave it as info, ok?

Copy link

Choose a reason for hiding this comment

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

Didn't we remove the requirement to seek most recently?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, in this PR. But the logging that the file was truncated is still needed.

@urso urso merged commit b9eba6e into elastic:master Jun 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants