pub struct Compactor<K, V, T, D> {
cfg: PersistConfig,
metrics: Arc<Metrics>,
sender: Sender<(Instant, CompactReq<T>, Machine<K, V, T, D>, Sender<Result<(), Error>>)>,
_phantom: PhantomData<fn() -> D>,
}
Expand description
A service for performing physical and logical compaction.
This will possibly be called over RPC in the future. Physical compaction is merging adjacent batches. Logical compaction is advancing timestamps to a new since and consolidating the resulting updates.
Fields§
§cfg: PersistConfig
§metrics: Arc<Metrics>
§sender: Sender<(Instant, CompactReq<T>, Machine<K, V, T, D>, Sender<Result<(), Error>>)>
§_phantom: PhantomData<fn() -> D>
Implementations§
Source§impl<K, V, T, D> Compactor<K, V, T, D>
impl<K, V, T, D> Compactor<K, V, T, D>
pub fn new( cfg: PersistConfig, metrics: Arc<Metrics>, write_schemas: Schemas<K, V>, gc: GarbageCollector<K, V, T, D>, ) -> Self
Sourcepub fn compact_and_apply_background(
&self,
req: CompactReq<T>,
machine: &Machine<K, V, T, D>,
) -> Option<Receiver<Result<(), Error>>>
pub fn compact_and_apply_background( &self, req: CompactReq<T>, machine: &Machine<K, V, T, D>, ) -> Option<Receiver<Result<(), Error>>>
Enqueues a CompactReq to be consumed by the compaction background task when available.
Returns a receiver that indicates when compaction has completed. The receiver can be safely dropped at any time if the caller does not wish to wait on completion.
pub(crate) async fn compact_and_apply( machine: &Machine<K, V, T, D>, req: CompactReq<T>, write_schemas: Schemas<K, V>, ) -> Result<RoutineMaintenance, Error>
pub async fn compact_all( stream: impl Stream<Item = Result<FueledMergeRes<T>, Error>>, req: CompactReq<T>, ) -> Result<CompactRes<T>, Error>
pub async fn apply( res: FueledMergeRes<T>, metrics: &Metrics, machine: &Machine<K, V, T, D>, ) -> Result<RoutineMaintenance, Error>
Sourcepub fn compact_stream(
cfg: CompactConfig,
blob: Arc<dyn Blob>,
metrics: Arc<Metrics>,
shard_metrics: Arc<ShardMetrics>,
isolated_runtime: Arc<IsolatedRuntime>,
req: CompactReq<T>,
write_schemas: Schemas<K, V>,
incremental_enabled: bool,
) -> impl Stream<Item = Result<FueledMergeRes<T>, Error>>
pub fn compact_stream( cfg: CompactConfig, blob: Arc<dyn Blob>, metrics: Arc<Metrics>, shard_metrics: Arc<ShardMetrics>, isolated_runtime: Arc<IsolatedRuntime>, req: CompactReq<T>, write_schemas: Schemas<K, V>, incremental_enabled: bool, ) -> impl Stream<Item = Result<FueledMergeRes<T>, Error>>
Compacts input batches in bounded memory.
The memory bound is broken into pieces: 1. in-progress work 2. fetching parts from runs 3. additional in-flight requests to Blob
- In-progress work is bounded by 2 * BatchBuilderConfig::blob_target_size. This usage is met at two mutually exclusive moments:
- When reading in a part, we hold the columnar format in memory while writing its contents into a heap.
- When writing a part, we hold a temporary updates buffer while encoding/writing it into a columnar format for Blob.
-
When compacting runs, only 1 part from each one is held in memory at a time. Compaction will determine an appropriate number of runs to compact together given the memory bound and accounting for the reservation in (1). A minimum of 2 * BatchBuilderConfig::blob_target_size of memory is expected, to be able to at least have the capacity to compact two runs together at a time, and more runs will be compacted together if more memory is available.
-
If there is excess memory after accounting for (1) and (2), we increase the number of outstanding parts we can keep in-flight to Blob.
Sourcepub async fn compact(
cfg: CompactConfig,
blob: Arc<dyn Blob>,
metrics: Arc<Metrics>,
shard_metrics: Arc<ShardMetrics>,
isolated_runtime: Arc<IsolatedRuntime>,
req: CompactReq<T>,
write_schemas: Schemas<K, V>,
) -> Result<CompactRes<T>, Error>
pub async fn compact( cfg: CompactConfig, blob: Arc<dyn Blob>, metrics: Arc<Metrics>, shard_metrics: Arc<ShardMetrics>, isolated_runtime: Arc<IsolatedRuntime>, req: CompactReq<T>, write_schemas: Schemas<K, V>, ) -> Result<CompactRes<T>, Error>
Compacts the input batches together, returning a single compacted batch. Under the hood this just calls Self::compact_stream and Self::compact_all, but it is a convenience method that allows the caller to not have to deal with the streaming API.
Sourcefn chunk_runs<'a>(
ordered_runs: &'a [(RunLocation, &'a Description<T>, &'a RunMeta, Cow<'a, [RunPart<T>]>)],
cfg: &CompactConfig,
metrics: &Metrics,
run_reserved_memory_bytes: usize,
) -> Vec<(Vec<(&'a RunLocation, &'a Description<T>, &'a RunMeta, &'a [RunPart<T>])>, usize)>
fn chunk_runs<'a>( ordered_runs: &'a [(RunLocation, &'a Description<T>, &'a RunMeta, Cow<'a, [RunPart<T>]>)], cfg: &CompactConfig, metrics: &Metrics, run_reserved_memory_bytes: usize, ) -> Vec<(Vec<(&'a RunLocation, &'a Description<T>, &'a RunMeta, &'a [RunPart<T>])>, usize)>
Chunks runs with the following rules:
- Runs from multiple batches are allowed to be mixed as long as every run in the the batch is present in the chunk.
- Otherwise runs are split into chunks of runs from a single batch.
Sourceasync fn flatten_runs<'a>(
req: &'a CompactReq<T>,
target_order: RunOrder,
blob: &'a dyn Blob,
metrics: &'a Metrics,
) -> Result<Vec<(RunLocation, &'a Description<T>, &'a RunMeta, Cow<'a, [RunPart<T>]>)>>
async fn flatten_runs<'a>( req: &'a CompactReq<T>, target_order: RunOrder, blob: &'a dyn Blob, metrics: &'a Metrics, ) -> Result<Vec<(RunLocation, &'a Description<T>, &'a RunMeta, Cow<'a, [RunPart<T>]>)>>
Flattens the runs in the input batches into a single ordered list of runs.
Sourcepub(crate) async fn compact_runs(
cfg: &CompactConfig,
shard_id: &ShardId,
desc: &Description<T>,
runs: Vec<(&Description<T>, &RunMeta, &[RunPart<T>])>,
blob: Arc<dyn Blob>,
metrics: Arc<Metrics>,
shard_metrics: Arc<ShardMetrics>,
isolated_runtime: Arc<IsolatedRuntime>,
write_schemas: Schemas<K, V>,
) -> Result<HollowBatch<T>, Error>
pub(crate) async fn compact_runs( cfg: &CompactConfig, shard_id: &ShardId, desc: &Description<T>, runs: Vec<(&Description<T>, &RunMeta, &[RunPart<T>])>, blob: Arc<dyn Blob>, metrics: Arc<Metrics>, shard_metrics: Arc<ShardMetrics>, isolated_runtime: Arc<IsolatedRuntime>, write_schemas: Schemas<K, V>, ) -> Result<HollowBatch<T>, Error>
Compacts runs together. If the input runs are sorted, a single run will be created as output.
Maximum possible memory usage is (# runs + 2) * [crate::PersistConfig::blob_target_size]
fn validate_req(req: &CompactReq<T>) -> Result<(), Error>
Trait Implementations§
Auto Trait Implementations§
impl<K, V, T, D> Freeze for Compactor<K, V, T, D>
impl<K, V, T, D> !RefUnwindSafe for Compactor<K, V, T, D>
impl<K, V, T, D> Send for Compactor<K, V, T, D>
impl<K, V, T, D> Sync for Compactor<K, V, T, D>
impl<K, V, T, D> Unpin for Compactor<K, V, T, D>
impl<K, V, T, D> !UnwindSafe for Compactor<K, V, T, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
Source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.Source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.Source§impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
Source§fn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
std::ops::AddAssign
, for types that do not implement AddAssign
.