Skip to content

Commit

Permalink
fix: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Vihas Splunk committed Aug 18, 2023
1 parent 1e3c11e commit 93dc34a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions pkg/stanza/fileconsumer/file_threadpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,17 @@ func (m *Manager) clearOldReadersConcurrent(ctx context.Context) {
// so we can just find the first reader whose poll cycle is less than our
// limit i.e. last 3 cycles, and keep every reader after that
oldReaders := make([]*reader, 0)
for i := 0; i < len(m.knownFiles); i++ {
i := 0
for ; i < len(m.knownFiles); i++ {
reader := m.knownFiles[i]
if reader.generation < 3 {
oldReaders = m.knownFiles[:i]
m.knownFiles = m.knownFiles[i:]
if reader.generation >= 3 {
oldReaders = append(oldReaders, reader)
i += 1
} else {
break
}
}

if len(m.knownFiles) > 0 && m.knownFiles[len(m.knownFiles)-1].generation >= 3 {
oldReaders = m.knownFiles[:len(m.knownFiles)]
m.knownFiles = m.knownFiles[len(m.knownFiles):]
}
m.knownFiles = m.knownFiles[i:]

var lostWG sync.WaitGroup
for _, r := range oldReaders {
Expand Down

0 comments on commit 93dc34a

Please sign in to comment.