Skip to content

Commit f3f2a4b

Browse files
committed
feature: [getTenantIDs] apply review comments of code style
1 parent 53866de commit f3f2a4b

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

lib/logstorage/indexdb_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,9 @@ func TestGetTenantsIDs(t *testing.T) {
313313
}
314314
idb.debugFlush()
315315

316-
f := func(expectedTenantIDs []TenantID) {
317-
t.Helper()
318-
result := idb.searchTenants()
319-
if !reflect.DeepEqual(result, expectedTenantIDs) {
320-
t.Fatalf("unexpected tensntIds; got %v; want %v", result, expectedTenantIDs)
321-
}
316+
// run the test
317+
result := idb.searchTenants()
318+
if !reflect.DeepEqual(result, tenantIDs) {
319+
t.Fatalf("unexpected tensntIds; got %v; want %v", result, tenantIDs)
322320
}
323-
324-
expectedTenantIDs := tenantIDs
325-
326-
f(expectedTenantIDs)
327321
}

lib/logstorage/storage_search.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,24 +597,22 @@ func (s *Storage) getTenantIDs(ctx context.Context, start, end int64) ([]TenantI
597597
stopCh := ctx.Done()
598598

599599
tenantIDByWorker := make([][]TenantID, workersCount)
600-
maxTenantCount := 0
601600

602-
// Spin up workers
603-
var wgWorkers sync.WaitGroup
601+
// spin up workers
602+
var wg sync.WaitGroup
604603
workCh := make(chan *partition, workersCount)
605-
wgWorkers.Add(workersCount)
606604
for i := 0; i < workersCount; i++ {
605+
wg.Add(1)
607606
go func(workerID uint) {
607+
defer wg.Done()
608608
for pt := range workCh {
609609
if needStop(stopCh) {
610610
// The search has been canceled. Just skip all the scheduled work in order to save CPU time.
611611
continue
612612
}
613613
tenantIDs := pt.idb.searchTenants()
614614
tenantIDByWorker[workerID] = append(tenantIDByWorker[workerID], tenantIDs...)
615-
maxTenantCount = max(maxTenantCount, len(tenantIDByWorker[workerID]))
616615
}
617-
wgWorkers.Done()
618616
}(uint(i))
619617
}
620618

@@ -647,14 +645,14 @@ func (s *Storage) getTenantIDs(ctx context.Context, start, end int64) ([]TenantI
647645

648646
// Wait until workers finish their work
649647
close(workCh)
650-
wgWorkers.Wait()
648+
wg.Wait()
651649

652650
// Decrement references to partitions
653651
for _, ptw := range ptws {
654652
ptw.decRef()
655653
}
656654

657-
uniqTenantIDs := make(map[TenantID]struct{}, maxTenantCount)
655+
uniqTenantIDs := make(map[TenantID]struct{})
658656
for _, tenantIDs := range tenantIDByWorker {
659657
for _, tenantID := range tenantIDs {
660658
uniqTenantIDs[tenantID] = struct{}{}

0 commit comments

Comments
 (0)