lib/logstorage: skip scheduled work when stopCh is closed

This saves CPU time
This commit is contained in:
Aliaksandr Valialkin 2024-04-24 23:28:52 +02:00
parent e42b9d26a9
commit ffdafc32c6
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -133,6 +133,13 @@ func (s *Storage) search(workersCount int, so *genericSearchOptions, stopCh <-ch
bs := getBlockSearch()
for bsws := range workCh {
for _, bsw := range bsws {
select {
case <-stopCh:
// The search has been canceled. Just skip all the scheduled work in order to save CPU time.
continue
default:
}
bs.search(bsw)
if bs.br.RowsCount() > 0 {
processBlockResult(workerID, &bs.br)