Skip to content

Commit

Permalink
Refactoring of entry reading (elastic#12716) (elastic#13204)
Browse files Browse the repository at this point in the history
Original description:
I have cleaned up the coda around reading entries and fixed an issue when iterating through journals.

Closes elastic#11505
(cherry picked from commit 3c9734c)

Closes elastic#13123
  • Loading branch information
kvch committed Aug 8, 2019
1 parent fec835c commit 9be0dc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ https://github.com/elastic/beats/compare/v6.8.0...6.8.1[Check the HEAD diff]

*Journalbeat*

- Use backoff when no new events are found. {pull}11861[11861]
- Iterate over journal correctly, so no duplicate entries are sent. {pull}12716[12716]

*Metricbeat*

*Packetbeat*
Expand Down
12 changes: 7 additions & 5 deletions journalbeat/reader/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,22 @@ func (r *Reader) Next() (*beat.Event, error) {
return nil, err
}

switch {
// error while reading next entry
if c < 0 {
case c < 0:
return nil, fmt.Errorf("error while reading next entry %+v", syscall.Errno(-c))
}

// no new entry, so wait
if c == 0 {
case c == 0:
hasNewEntry, err := r.checkForNewEvents()
if err != nil {
return nil, err
}
if !hasNewEntry {
continue
r.backoff.Wait()
}
continue
// new entries are available
default:
}

entry, err := r.journal.GetEntry()
Expand Down

0 comments on commit 9be0dc0

Please sign in to comment.