Skip to content

Commit dfbafa8

Browse files
committed
chore: follow-up of #709, unified the waitgroup var name as wg, and use defer for wg.Done
1 parent 8289f63 commit dfbafa8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/logstorage/storage_search.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,12 +1224,13 @@ func (db *DataBlock) initFromBlockResult(br *blockResult) {
12241224
//
12251225
// It uses workersCount parallel workers for the search and calls writeBlock for each matching block.
12261226
func (s *Storage) searchParallel(workersCount int, so *genericSearchOptions, qs *QueryStats, stopCh <-chan struct{}, writeBlock writeBlockResultFunc) {
1227-
// Spin up workers
1228-
var wgWorkers sync.WaitGroup
1227+
// spin up workers
1228+
var wg sync.WaitGroup
12291229
workCh := make(chan *blockSearchWorkBatch, workersCount)
1230-
wgWorkers.Add(workersCount)
1231-
for i := 0; i < workersCount; i++ {
1230+
for workerID := 0; workerID < workersCount; workerID++ {
1231+
wg.Add(1)
12321232
go func(workerID uint) {
1233+
defer wg.Done()
12331234
qsLocal := &QueryStats{}
12341235
bs := getBlockSearch()
12351236
bm := getBitmap(0)
@@ -1264,8 +1265,7 @@ func (s *Storage) searchParallel(workersCount int, so *genericSearchOptions, qs
12641265
putBlockSearch(bs)
12651266
putBitmap(bm)
12661267
qs.UpdateAtomic(qsLocal)
1267-
wgWorkers.Done()
1268-
}(uint(i))
1268+
}(uint(workerID))
12691269
}
12701270

12711271
// Select partitions according to the selected time range
@@ -1314,7 +1314,7 @@ func (s *Storage) searchParallel(workersCount int, so *genericSearchOptions, qs
13141314

13151315
// Wait until workers finish their work
13161316
close(workCh)
1317-
wgWorkers.Wait()
1317+
wg.Wait()
13181318

13191319
// Finalize partition search
13201320
for _, psf := range psfs {

0 commit comments

Comments
 (0)