Skip to content

Commit

Permalink
Use channel instead of mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonip committed Oct 16, 2024
1 parent f654fba commit 038ff5b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions x-pack/apm-server/sampling/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const (
)

var (
// gcMutex is a global mutex to protect gc from running concurrently when 2 TBS processors are active during a hot reload
gcMutex sync.Mutex
// gcCh works like a global mutex to protect gc from running concurrently when 2 TBS processors are active during a hot reload
gcCh = make(chan struct{}, 1)
)

// Processor is a tail-sampling event processor.
Expand Down Expand Up @@ -391,8 +391,16 @@ func (p *Processor) Run() error {
}
})
g.Go(func() error {
gcMutex.Lock()
defer gcMutex.Unlock()
// Protect this goroutine from running concurrently when 2 TBS processors are active
// as badger GC is not concurrent safe.
select {
case <-p.stopping:
return nil
case gcCh <- struct{}{}:
}
defer func() {
<-gcCh
}()
// This goroutine is responsible for periodically garbage
// collecting the Badger value log, using the recommended
// discard ratio of 0.5.
Expand Down

0 comments on commit 038ff5b

Please sign in to comment.