pub struct WarningCollector { /* private fields */ }Expand description
A thread-safe collector for ExtensionWarnings.
Extensions create a single WarningCollector (typically stored in their
global or bind-data state) and call emit whenever a warning
condition is detected. Warnings can later be surfaced through a table
function (e.g., SELECT * FROM __extension_warnings()).
§Thread safety
WarningCollector uses a Mutex internally and is safe to share across
threads via Arc<WarningCollector>. A panic on another thread while it held
the lock does not lose warnings: every operation is a single Vec call, so
the list is intact, and the collector keeps using it.
§Bounded
A collector keeps at most a limit of warnings between drains
(DEFAULT_MAX_WARNINGS, 10,000, from new; any other with
with_limit). Past it, emit does not
store the warning but counts it in dropped, so a
condition reported once per request or row cannot grow the list without
bound in a long-lived process (2,000,000 warnings were 381 MB). The first
warnings are the ones kept.
Behaviour change in 0.20.0: before it, every warning was stored, and a collector never drained grew for as long as the process lived.
Implementations§
Source§impl WarningCollector
impl WarningCollector
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new, empty WarningCollector that keeps at most
DEFAULT_MAX_WARNINGS warnings between drains.
Warnings past the limit are counted (dropped), not
stored.
Sourcepub const fn with_limit(limit: usize) -> Self
pub const fn with_limit(limit: usize) -> Self
Creates a collector that keeps at most limit warnings between drains.
Sourcepub fn emit(&self, warning: ExtensionWarning)
pub fn emit(&self, warning: ExtensionWarning)
Emits a warning, adding it to the collector, or counting it in
dropped when the collector is full.
Sourcepub fn snapshot(&self) -> Vec<ExtensionWarning>
pub fn snapshot(&self) -> Vec<ExtensionWarning>
Returns a snapshot of all collected warnings without clearing them.
Sourcepub fn drain(&self) -> Vec<ExtensionWarning>
pub fn drain(&self) -> Vec<ExtensionWarning>
Drains all collected warnings, returning them and leaving the collector empty.
Resets dropped: read it first to learn how many
warnings the full collector discarded since the last drain.