Skip to main content

BlockMigrationPlanner

Struct BlockMigrationPlanner 

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

Block migration planner: registers blocks, creates plans, executes them, and provides scheduling and defragmentation helpers.

Implementations§

Source§

impl BlockMigrationPlanner

Source

pub fn new() -> Self

Create a planner with default configuration.

Source

pub fn with_config(config: BmpPlannerConfig) -> Self

Create a planner with the supplied configuration.

Source

pub fn config(&self) -> &BmpPlannerConfig

Return a reference to the current configuration.

Source

pub fn set_config(&mut self, config: BmpPlannerConfig)

Replace the configuration.

Source

pub fn register_block( &mut self, id: BmpBlockId, size_bytes: u64, src_node: impl Into<String>, tier: u8, access_frequency: f64, )

Register a new block (or overwrite if it already exists).

Source

pub fn update_access(&mut self, id: &BmpBlockId) -> Result<(), BmpError>

Record an access event for a block, bumping last_accessed and applying a simple exponential-moving-average update to access_frequency.

Source

pub fn pin(&mut self, id: &BmpBlockId) -> Result<(), BmpError>

Pin a block so it will not be selected for automatic migration.

Source

pub fn unpin(&mut self, id: &BmpBlockId) -> Result<(), BmpError>

Unpin a previously pinned block.

Source

pub fn block_meta(&self, id: &BmpBlockId) -> Option<&BmpBlockMeta>

Return a reference to a block’s metadata, or None if not registered.

Source

pub fn block_count(&self) -> usize

Number of currently registered blocks.

Source

pub fn create_plan( &mut self, block_ids: Vec<BmpBlockId>, dst_node: impl Into<String>, priority: u32, ) -> Result<BmpPlanId, BmpError>

Create a migration plan for the given blocks.

The src_node is inferred from the first block’s current location; if the list spans multiple source nodes the first one wins (callers should group by node before creating plans when that matters).

Returns Err if any block is pinned or if any block is not registered.

Source

pub fn cancel_plan(&mut self, plan_id: BmpPlanId) -> Result<(), BmpError>

Cancel a pending plan. Plans that are already InProgress, Completed, Failed, or Cancelled cannot be cancelled again.

Source

pub fn execute_plan( &mut self, plan_id: BmpPlanId, ) -> Result<BmpExecutionResult, BmpError>

Execute a migration plan.

Each block is migrated in sequence; a simulated success/failure decision is made via xorshift64 (roughly 90 % success when !dry_run). In dry_run mode all blocks succeed without moving.

Source

pub fn schedule_migrations( &mut self, policy: BmpPriorityPolicy, max_plans: usize, ) -> Result<Vec<BmpPlanId>, BmpError>

Automatically select blocks that need migration and create plans for them.

“Needing migration” means the block has a dst_node already set, or is unpinned and in a non-zero tier (tier > 0 → candidate for promotion). Up to max_plans plans are created, each containing a single block, ordered according to policy.

Source

pub fn run_batch_migration( &mut self, policy: BmpPriorityPolicy, batch_size: usize, ) -> BmpBatchResult

Create up to batch_size plans using policy and execute them all, respecting max_concurrent_migrations.

Source

pub fn defragment_plan(&mut self, nodes: &[String]) -> Vec<BmpPlanId>

Generate plans to balance blocks evenly across the supplied nodes.

Blocks that are already on the least-loaded node (or are pinned) are skipped. The target is total_blocks / nodes.len() per node. Returns Vec<BmpPlanId> of all newly created plans.

Source

pub fn migration_stats(&self) -> BmpPlannerStats

Compute and return aggregate statistics.

Source

pub fn plan_count(&self) -> usize

Return the number of plans in the planner.

Source

pub fn plan(&self, plan_id: BmpPlanId) -> Option<&BmpMigrationPlan>

Return a reference to a plan, or None.

Source

pub fn plans_iter(&self) -> impl Iterator<Item = &BmpMigrationPlan>

Iterate over all plans.

Source

pub fn recent_records(&self, n: usize) -> Vec<&BmpMigrationRecord>

Return the most recent n log records.

Source

pub fn log_len(&self) -> usize

Total number of records in the execution log.

Trait Implementations§

Source§

impl Default for BlockMigrationPlanner

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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