aba2f14595
Additional elements added: * monkit metric for observers methods like Start/Fork/Join/Finish to be able to check how much time those methods are taking * few more logs e.g. entries with processed range * segmentsProcessed metric to be able to check loop progress Change-Id: I65dd51f7f5c4bdbb4014fbf04e5b6b10bdb035ec
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
// Copyright (C) 2022 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package rangedlooptest
|
|
|
|
import (
|
|
"context"
|
|
|
|
"storj.io/storj/satellite/metabase/rangedloop"
|
|
"storj.io/storj/satellite/metabase/segmentloop"
|
|
)
|
|
|
|
var _ rangedloop.RangeSplitter = (*InfiniteSegmentProvider)(nil)
|
|
var _ rangedloop.SegmentProvider = (*InfiniteSegmentProvider)(nil)
|
|
|
|
// InfiniteSegmentProvider allow to iterate indefinitely to test service cancellation.
|
|
type InfiniteSegmentProvider struct {
|
|
}
|
|
|
|
// CreateRanges splits the segments into equal ranges.
|
|
func (m *InfiniteSegmentProvider) CreateRanges(nRanges int, batchSize int) (segmentsProviders []rangedloop.SegmentProvider, err error) {
|
|
for i := 0; i < nRanges; i++ {
|
|
segmentsProviders = append(segmentsProviders, &InfiniteSegmentProvider{})
|
|
}
|
|
return segmentsProviders, nil
|
|
}
|
|
|
|
// Range returns range which is processed by this provider.
|
|
func (m *InfiniteSegmentProvider) Range() rangedloop.UUIDRange {
|
|
return rangedloop.UUIDRange{}
|
|
}
|
|
|
|
// Iterate allows to loop over the segments stored in the provider.
|
|
func (m *InfiniteSegmentProvider) Iterate(ctx context.Context, fn func([]segmentloop.Segment) error) error {
|
|
for {
|
|
err := fn(make([]segmentloop.Segment, 3))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|