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
impl BlockMigrationPlanner
Sourcepub fn with_config(config: BmpPlannerConfig) -> Self
pub fn with_config(config: BmpPlannerConfig) -> Self
Create a planner with the supplied configuration.
Sourcepub fn config(&self) -> &BmpPlannerConfig
pub fn config(&self) -> &BmpPlannerConfig
Return a reference to the current configuration.
Sourcepub fn set_config(&mut self, config: BmpPlannerConfig)
pub fn set_config(&mut self, config: BmpPlannerConfig)
Replace the configuration.
Sourcepub fn register_block(
&mut self,
id: BmpBlockId,
size_bytes: u64,
src_node: impl Into<String>,
tier: u8,
access_frequency: f64,
)
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).
Sourcepub fn update_access(&mut self, id: &BmpBlockId) -> Result<(), BmpError>
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.
Sourcepub fn pin(&mut self, id: &BmpBlockId) -> Result<(), BmpError>
pub fn pin(&mut self, id: &BmpBlockId) -> Result<(), BmpError>
Pin a block so it will not be selected for automatic migration.
Sourcepub fn unpin(&mut self, id: &BmpBlockId) -> Result<(), BmpError>
pub fn unpin(&mut self, id: &BmpBlockId) -> Result<(), BmpError>
Unpin a previously pinned block.
Sourcepub fn block_meta(&self, id: &BmpBlockId) -> Option<&BmpBlockMeta>
pub fn block_meta(&self, id: &BmpBlockId) -> Option<&BmpBlockMeta>
Return a reference to a block’s metadata, or None if not registered.
Sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Number of currently registered blocks.
Sourcepub fn create_plan(
&mut self,
block_ids: Vec<BmpBlockId>,
dst_node: impl Into<String>,
priority: u32,
) -> Result<BmpPlanId, BmpError>
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.
Sourcepub fn cancel_plan(&mut self, plan_id: BmpPlanId) -> Result<(), BmpError>
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.
Sourcepub fn execute_plan(
&mut self,
plan_id: BmpPlanId,
) -> Result<BmpExecutionResult, BmpError>
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.
Sourcepub fn schedule_migrations(
&mut self,
policy: BmpPriorityPolicy,
max_plans: usize,
) -> Result<Vec<BmpPlanId>, BmpError>
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.
Sourcepub fn run_batch_migration(
&mut self,
policy: BmpPriorityPolicy,
batch_size: usize,
) -> BmpBatchResult
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.
Sourcepub fn defragment_plan(&mut self, nodes: &[String]) -> Vec<BmpPlanId> ⓘ
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.
Sourcepub fn migration_stats(&self) -> BmpPlannerStats
pub fn migration_stats(&self) -> BmpPlannerStats
Compute and return aggregate statistics.
Sourcepub fn plan_count(&self) -> usize
pub fn plan_count(&self) -> usize
Return the number of plans in the planner.
Sourcepub fn plan(&self, plan_id: BmpPlanId) -> Option<&BmpMigrationPlan>
pub fn plan(&self, plan_id: BmpPlanId) -> Option<&BmpMigrationPlan>
Return a reference to a plan, or None.
Sourcepub fn plans_iter(&self) -> impl Iterator<Item = &BmpMigrationPlan>
pub fn plans_iter(&self) -> impl Iterator<Item = &BmpMigrationPlan>
Iterate over all plans.
Sourcepub fn recent_records(&self, n: usize) -> Vec<&BmpMigrationRecord>
pub fn recent_records(&self, n: usize) -> Vec<&BmpMigrationRecord>
Return the most recent n log records.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BlockMigrationPlanner
impl RefUnwindSafe for BlockMigrationPlanner
impl Send for BlockMigrationPlanner
impl Sync for BlockMigrationPlanner
impl Unpin for BlockMigrationPlanner
impl UnsafeUnpin for BlockMigrationPlanner
impl UnwindSafe for BlockMigrationPlanner
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more