pub struct StorageMigrationPlanner {
pub records: HashMap<u64, MigrationRecord>,
pub next_task_id: u64,
}Expand description
Plans and tracks migrations of blocks across storage tiers.
§Example
use ipfrs_storage::migration_planner::{StorageMigrationPlanner, StorageTier};
let mut planner = StorageMigrationPlanner::new();
let id = planner.plan_migration(1, "bafyexample".into(), StorageTier::Nvme, StorageTier::Hdd, 4_000_000, vec![]);
assert!(planner.start_task(id, 0));
assert!(planner.complete_task(id, 10));Fields§
§records: HashMap<u64, MigrationRecord>All records keyed by their task_id.
next_task_id: u64Counter used to assign the next unique task identifier.
Implementations§
Source§impl StorageMigrationPlanner
impl StorageMigrationPlanner
Sourcepub fn plan_migration(
&mut self,
block_id: u64,
cid: String,
from: StorageTier,
to: StorageTier,
size_bytes: u64,
depends_on: Vec<u64>,
) -> u64
pub fn plan_migration( &mut self, block_id: u64, cid: String, from: StorageTier, to: StorageTier, size_bytes: u64, depends_on: Vec<u64>, ) -> u64
Sourcepub fn start_task(&mut self, task_id: u64, current_tick: u64) -> bool
pub fn start_task(&mut self, task_id: u64, current_tick: u64) -> bool
Transitions a task from Pending to
InProgress.
Returns false if:
- the task does not exist,
- the task is not in
Pendingstate, or - any dependency is not yet
Completed.
Sourcepub fn complete_task(&mut self, task_id: u64, current_tick: u64) -> bool
pub fn complete_task(&mut self, task_id: u64, current_tick: u64) -> bool
Transitions a task from InProgress to
Completed.
Returns false if the task is not found or not InProgress.
Sourcepub fn fail_task(&mut self, task_id: u64) -> bool
pub fn fail_task(&mut self, task_id: u64) -> bool
Transitions a task to Failed.
Accepted from either Pending or
InProgress. Returns false if the task
is not found or already in a terminal state.
Sourcepub fn rollback_task(&mut self, task_id: u64) -> bool
pub fn rollback_task(&mut self, task_id: u64) -> bool
Transitions a task from Failed to
RolledBack.
Returns false if the task is not found or not in Failed state.
Sourcepub fn ready_tasks(&self) -> Vec<u64>
pub fn ready_tasks(&self) -> Vec<u64>
Sourcepub fn get_record(&self, task_id: u64) -> Option<&MigrationRecord>
pub fn get_record(&self, task_id: u64) -> Option<&MigrationRecord>
Returns an immutable reference to the record for task_id, or None.
Sourcepub fn stats(&self) -> PlannerStats
pub fn stats(&self) -> PlannerStats
Computes aggregate statistics over all tracked records.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StorageMigrationPlanner
impl RefUnwindSafe for StorageMigrationPlanner
impl Send for StorageMigrationPlanner
impl Sync for StorageMigrationPlanner
impl Unpin for StorageMigrationPlanner
impl UnsafeUnpin for StorageMigrationPlanner
impl UnwindSafe for StorageMigrationPlanner
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
Mutably borrows from an owned value. Read more
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>
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 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>
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