Skip to content

Commit

Permalink
Check for SourceUnit support dynamically in the SourceManager (#2205)
Browse files Browse the repository at this point in the history
* Check for SourceUnit support dynamically in the SourceManager

* Only call the function if we can use source units
  • Loading branch information
mcastorina committed Dec 14, 2023
1 parent 06b137f commit f6bbc59
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/sources/source_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type SourceManager struct {
// Max number of units to scan concurrently per source.
concurrentUnits int
// Run the sources using source unit enumeration / chunking if available.
useSourceUnits bool
// Checked at runtime to allow feature flagging.
useSourceUnitsFunc func() bool
// Downstream chunks channel to be scanned.
outputChunks chan *Chunk
// Set when Wait() returns.
Expand Down Expand Up @@ -67,7 +68,13 @@ func WithBufferedOutput(size int) func(*SourceManager) {
// WithSourceUnits enables using source unit enumeration and chunking if the
// source supports it.
func WithSourceUnits() func(*SourceManager) {
return func(mgr *SourceManager) { mgr.useSourceUnits = true }
return func(mgr *SourceManager) {
mgr.useSourceUnitsFunc = func() bool { return true }
}
}

func WithSourceUnitsFunc(f func() bool) func(*SourceManager) {
return func(mgr *SourceManager) { mgr.useSourceUnitsFunc = f }
}

// WithConcurrentUnits limits the number of units to be scanned concurrently.
Expand Down Expand Up @@ -229,7 +236,8 @@ func (s *SourceManager) run(ctx context.Context, source Source, report *JobProgr
"source_type", source.Type().String(),
)
// Check for the preferred method of tracking source units.
if enumChunker, ok := source.(SourceUnitEnumChunker); ok && s.useSourceUnits && len(targets) == 0 {
canUseSourceUnits := len(targets) == 0 && s.useSourceUnitsFunc != nil
if enumChunker, ok := source.(SourceUnitEnumChunker); ok && canUseSourceUnits && s.useSourceUnitsFunc() {
return s.runWithUnits(ctx, enumChunker, report)
}
return s.runWithoutUnits(ctx, source, report, targets...)
Expand Down

0 comments on commit f6bbc59

Please sign in to comment.