Skip to main content

CompactionManager

Struct CompactionManager 

Source
pub struct CompactionManager { /* private fields */ }
Expand description

Manages Parquet file compaction for optimal storage and query performance.

Step 4 of the sustainable data strategy moved compaction from a global-stream pass to a per-tenant pass. Each invocation iterates the tenants discovered under <storage_dir>/<tenant>/... and emits a snapshot.<tenant>.<from>-<to>.parquet per qualifying chunk. Snapshot files are written atomically (tmp + rename) and their constituent raw files are removed only after the rename succeeds — so a mid-compaction crash leaves data intact.

Implementations§

Source§

impl CompactionManager

Source

pub fn new(storage_dir: impl Into<PathBuf>, config: CompactionConfig) -> Self

Create a new compaction manager

Source

pub fn should_compact(&self) -> bool

Check if compaction should run

Source

pub fn compact(&self) -> Result<CompactionResult>

Perform compaction across every discovered tenant.

Iterates the tenants under <storage_dir>/<tenant>/..., calls compact_tenant for each, and aggregates the results. Step 4 of the sustainable data strategy: per-tenant compaction instead of global, keyed off the per-tenant directory tree Step 1 introduced.

Errors compacting one tenant are logged but don’t abort the pass — other tenants still get compacted. The aggregate result reflects what actually completed.

The sweep stops starting work once max_pass_seconds is spent and resumes on the next tick. Tenants are visited in a stable order, so a sweep that runs out of budget always leaves the same tail — the per-pass bound is on time, and progress comes from the files each group removes.

Source

pub fn sweep_cursor(&self) -> Option<String>

Where the next sweep will start, or None before the first one.

Diagnostic: a cursor that never moves off one tenant means that tenant’s backlog is larger than a single pass’s budget.

Source

pub fn compact_until( &self, deadline: Option<Instant>, ) -> Result<CompactionResult>

Self::compact with an explicit deadline in place of the one max_pass_seconds derives.

Source

pub fn compact_tenant(&self, tenant_id: &str) -> Result<CompactionResult>

Compact one tenant’s event files into snapshot files under that tenant’s partition.

Per-tenant pipeline:

  1. List <storage>/<tenant>/...*.parquet, keeping an existing snapshot.* only while it is still under small_file_threshold so partial passes merge upward.
  2. Apply the configured strategy (size / time / full) to pick candidates.
  3. Split the candidates into groups bounded by max_input_bytes_per_snapshot and max_input_files_per_snapshot, and compact each group on its own. One group’s events are resident at a time, so a tenant’s size sets how many snapshots a pass writes, never how much memory it needs.

Each group is independently crash-safe: its snapshot is renamed into place before any of its own inputs is deleted, and a crash between groups leaves the earlier groups compacted and the later ones untouched.

Source

pub fn compact_tenant_until( &self, tenant_id: &str, deadline: Option<Instant>, ) -> Result<CompactionResult>

compact_tenant with a sweep deadline. Checked between groups, so the tenant’s remaining groups are left for the next tick rather than abandoned mid-group — a group either publishes its snapshot and deletes its inputs or does neither.

Source

pub fn stats(&self) -> CompactionStats

Get compaction statistics

Source

pub fn config(&self) -> &CompactionConfig

Get configuration

Source

pub fn compact_now(&self) -> Result<CompactionResult>

Trigger manual compaction

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.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

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

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

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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