-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add capability for memory and persistent queue to block when add items
Signed-off-by: Bogdan Drutu <[email protected]>
- Loading branch information
1 parent
7f4664e
commit e5ca0d6
Showing
8 changed files
with
406 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
component: exporterhelper | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add capability for memory and persistent queue to block when add items | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [12074] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [api] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package exporterqueue // import "go.opentelemetry.io/collector/exporter/exporterqueue" | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
) | ||
|
||
// cond is equivalent with sync.Cond, but context.Context aware. Which means Wait() will return if context is done. | ||
// Also, it requires the caller to hold the c.L during all calls. | ||
type cond struct { | ||
L sync.Locker | ||
ch chan struct{} | ||
waiting int64 | ||
} | ||
|
||
func newCond(l sync.Locker) *cond { | ||
return &cond{L: l, ch: make(chan struct{}, 1)} | ||
} | ||
|
||
// Signal wakes one goroutine waiting on c, if there is any. | ||
// It requires for the caller to hold c.L during the call. | ||
func (c *cond) Signal() { | ||
if c.waiting == 0 { | ||
return | ||
} | ||
c.waiting-- | ||
c.ch <- struct{}{} | ||
} | ||
|
||
// Broadcast wakes all goroutines waiting on c. | ||
// It requires for the caller to hold c.L during the call. | ||
func (c *cond) Broadcast() { | ||
for ; c.waiting > 0; c.waiting-- { | ||
c.ch <- struct{}{} | ||
} | ||
} | ||
|
||
// Wait atomically unlocks c.L and suspends execution of the calling goroutine. After later resuming execution, Wait locks c.L before returning. | ||
func (c *cond) Wait(ctx context.Context) error { | ||
c.waiting++ | ||
c.L.Unlock() | ||
select { | ||
case <-ctx.Done(): | ||
c.L.Lock() | ||
if c.waiting == 0 { | ||
// If waiting is 0, it means that there was a signal sent and nobody else waits for it. | ||
// Consume it, so that we don't unblock other consumer unnecessary, | ||
// or we don't block the producer because the channel buffer is full. | ||
<-c.ch | ||
} else { | ||
// Decrease the number of waiting routines. | ||
c.waiting-- | ||
} | ||
return ctx.Err() | ||
case <-c.ch: | ||
c.L.Lock() | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.