Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions processor/batchprocessor/batch_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
// errTooManyBatchers is returned when the MetadataCardinalityLimit has been reached.
var errTooManyBatchers = consumererror.NewPermanent(errors.New("too many batcher metadata-value combinations"))

// errShuttingDown is returned when data is received while the processor is shutting down.
var errShuttingDown = errors.New("batch processor is shutting down")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the component sending the data, I think this can be retried if it is not marked as permanent.


// batch_processor is a component that accepts spans and metrics, places them
// into batches and sends downstream.
//
Expand Down Expand Up @@ -290,9 +293,15 @@ func (sb *singleShardBatcher[T]) start(context.Context) error {
return nil
}

func (sb *singleShardBatcher[T]) consume(_ context.Context, data T) error {
sb.single.newItem <- data
return nil
func (sb *singleShardBatcher[T]) consume(ctx context.Context, data T) error {
select {
case sb.single.newItem <- data:
return nil
case <-ctx.Done():
return ctx.Err()
case <-sb.processor.shutdownC:
return errShuttingDown
}
}

func (sb *singleShardBatcher[T]) currentMetadataCardinality() int {
Expand Down Expand Up @@ -362,8 +371,14 @@ func (mb *multiShardBatcher[T]) consume(ctx context.Context, data T) error {
}
mb.lock.Unlock()
}
b.(*shard[T]).newItem <- data
return nil
select {
case b.(*shard[T]).newItem <- data:
return nil
case <-ctx.Done():
return ctx.Err()
case <-mb.processor.shutdownC:
return errShuttingDown
}
}

func (mb *multiShardBatcher[T]) currentMetadataCardinality() int {
Expand Down
Loading