Skip to main content

EmbeddedBroker

Struct EmbeddedBroker 

Source
pub struct EmbeddedBroker {
    pub recovered_torn_lines: u64,
    /* private fields */
}
Expand description

File-backed broker instance.

Fields§

§recovered_torn_lines: u64

Torn trailing lines dropped during recovery (public field asserted by the contract tests; not currently read by any caller or exported as a metric).

Implementations§

Source§

impl EmbeddedBroker

Source

pub fn provision( data_dir: &Path, manifest: &BridgeManifest, ) -> Result<Self, BusError>

Provision a fresh bridge in data_dir from manifest alone (R12). Fails if the directory already contains a bridge.

Source

pub fn open(data_dir: &Path) -> Result<Self, BusError>

Open an existing bridge, recovering offsets (and truncating at most one torn trailing line per partition) from the segment files.

Source

pub fn manifest(&self) -> &BridgeManifest

The manifest this bridge was provisioned from.

Source

pub fn data_dir(&self) -> &Path

Data directory.

Source

pub fn fetch_read_only( data_dir: &Path, topic: &str, partition: u32, offset: u64, max: usize, ) -> Result<Vec<StoredEvent>, BusError>

Read-only event fetch for tooling running BESIDE a live daemon (avctl event-tail). Self::open is NOT safe for that use: its recovery “repairs” a torn segment tail via set_len and atomically rewrites the idempotency sidecar — racing a daemon that is mid-append (between write_all of the record bytes and the trailing newline), a second process’s repair truncates bytes the daemon goes on to ack as durable: a silently lost or corrupted acked audit event. There is no cross-process lock, so the only safe concurrent mode is one that mutates nothing.

This path only reads: the manifest (capped, to validate the topic/partition and locate the segment), then a bounded streaming scan of the one segment file. An unparseable line is skipped (same policy as EventBus::fetch); an unterminated trailing line — an in-flight append or crash-torn tail — is ignored, never truncated; a record above the per-line bound stops the scan at that point (fail-stop, mutation-free).

Source§

impl EmbeddedBroker

Source

pub fn enforce_retention(&self, now_ms: u64) -> Result<u64, BusError>

Enforce per-topic hot retention at time now_ms: when retention.cold_uri is set, each expired record is first exported to the cold tier as its own write-once object (via the authenticated ColdArchive for scheme:// URIs, or write_cold_event_once for local directory paths) before being removed from the hot segment via atomic rewrite; with cold_uri unset, expired records are dropped from the hot segment without export. Returns the number of records expired.

Trait Implementations§

Source§

impl EventBus for EmbeddedBroker

Source§

fn find_event_by_uid( &self, topic: &str, key: &str, event_uid: &str, ) -> Result<Option<PublishAck>, BusError>

O(1) event-UID lookup via the partition’s in-memory seen_event_uids map. The default trait impl at bus.rs::find_event_by_uid linearly scans the segment from offset 0 with fetch, which for EmbeddedBroker re-opens the segment file each call and streams from the head with a BufReader — so each fetch page for offset > 0 also walks the whole prefix. resolve_lifecycle_ack in the harness calls this on EVERY emit_bridge_event (twice per session close — RECEIPT + SESSION_CLOSE), which meant close latency grew O(total events per partition²) amortised. The Kafka and NATS bus implementations both override with O(1) lookups; only the embedded broker was still on the trait default.

Source§

fn set_control_key(&self, _key: [u8; 32]) -> Result<(), BusError>

Configure the signer-derived key used for authenticated local controls.
Source§

fn publish( &self, topic: &str, key: &str, value: &Value, ) -> Result<PublishAck, BusError>

Publish value onto topic, partitioned by key. Returns the ack.
Source§

fn publish_idempotent( &self, topic: &str, key: &str, value: &Value, event_uid: &str, ) -> Result<PublishAck, BusError>

Publish a stable event UID. Backends with native or local deduplication override this method; the default preserves compatibility while the UID remains embedded in the event payload for downstream deduplication.
Source§

fn fetch( &self, topic: &str, partition: u32, offset: u64, max: usize, ) -> Result<Vec<StoredEvent>, BusError>

Read up to max events from topic/partition starting at offset (ordered replay).
Source§

fn partitions(&self, topic: &str) -> Result<u32, BusError>

Number of partitions configured for topic.
Source§

fn topics(&self) -> Vec<String>

Topics currently provisioned.
Source§

fn maintenance(&self, now_ms: u64) -> Result<u64, BusError>

Run backend maintenance such as hot-retention expiry. Managed brokers may return zero when retention is enforced natively.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,