pub struct StorageTierMigrator {
pub config: MigratorConfig,
pub blocks: HashMap<String, BlockMeta>,
pub migration_log: VecDeque<MigrationAction>,
pub total_migrations: u64,
pub total_bytes_migrated: u64,
}Expand description
Production-grade intelligent block migration engine.
Tracks blocks across four storage tiers (Hot, Warm, Cold, Archive) and
demotes them according to configurable TierPolicy rules based on age,
access frequency, and size constraints.
§Lifecycle
- Configure via
MigratorConfigand create withStorageTierMigrator::new. - Register blocks with
register_block. - Record access events with
record_access. - Trigger a migration cycle with
run_migration_cycle. - Inspect results via
migration_logormigrator_stats.
Fields§
§config: MigratorConfigMigrator configuration (policies, dry-run flag, batch/max sizes).
blocks: HashMap<String, BlockMeta>Map from CID → block metadata. Central registry.
migration_log: VecDeque<MigrationAction>Bounded ring-buffer of recently executed (or dry-run planned) migrations.
total_migrations: u64All-time migration execution count.
total_bytes_migrated: u64All-time total bytes migrated.
Implementations§
Source§impl StorageTierMigrator
impl StorageTierMigrator
Sourcepub fn new(config: MigratorConfig) -> Self
pub fn new(config: MigratorConfig) -> Self
Create a new migrator from the given configuration.
Sourcepub fn register_block(&mut self, meta: BlockMeta)
pub fn register_block(&mut self, meta: BlockMeta)
Register a new block or overwrite an existing entry with updated metadata.
Sourcepub fn unregister_block(&mut self, cid: &str) -> bool
pub fn unregister_block(&mut self, cid: &str) -> bool
Remove a block from the registry. Returns true if the block existed.
Sourcepub fn record_access(&mut self, cid: &str, now_ms: u64) -> bool
pub fn record_access(&mut self, cid: &str, now_ms: u64) -> bool
Record an access event for a block, incrementing its counter and
updating last_accessed_ms. Returns true if the block was found.
Sourcepub fn evaluate_block(
&self,
meta: &BlockMeta,
now_ms: u64,
) -> Option<MigrationAction>
pub fn evaluate_block( &self, meta: &BlockMeta, now_ms: u64, ) -> Option<MigrationAction>
Evaluate whether a single block needs to be migrated, given the current
timestamp now_ms.
Policies are checked in descending tier priority order. If a block’s
current tier matches a policy and any demotion condition is satisfied,
a MigrationAction targeting the next-colder tier is returned.
Returns None if no migration is required.
Sourcepub fn plan_migrations(&self, now_ms: u64) -> Vec<MigrationAction>
pub fn plan_migrations(&self, now_ms: u64) -> Vec<MigrationAction>
Evaluate every tracked block and return the list of MigrationActions
that should be executed.
Actions are sorted by from_tier.priority() descending (hottest blocks
first) and capped at MigratorConfig::max_migrations_per_run.
Sourcepub fn execute_migrations(
&mut self,
actions: Vec<MigrationAction>,
now_ms: u64,
) -> MigrationResult
pub fn execute_migrations( &mut self, actions: Vec<MigrationAction>, now_ms: u64, ) -> MigrationResult
Execute a pre-planned list of migration actions.
In dry-run mode: populates actions_planned but leaves block metadata
untouched. In live mode: blocks are processed in batches of
MigratorConfig::batch_size. CIDs that no longer exist in the registry
are recorded in failed_cids.
Sourcepub fn run_migration_cycle(&mut self, now_ms: u64) -> MigrationResult
pub fn run_migration_cycle(&mut self, now_ms: u64) -> MigrationResult
Convenience method: plan migrations for now_ms, then execute them in
one atomic call. Returns a combined MigrationResult.
Sourcepub fn blocks_in_tier(&self, tier: &StorageTier) -> Vec<&BlockMeta>
pub fn blocks_in_tier(&self, tier: &StorageTier) -> Vec<&BlockMeta>
Returns all blocks currently residing in tier, sorted by
access_count descending (most-accessed first).
Sourcepub fn migration_log(&self) -> &VecDeque<MigrationAction>
pub fn migration_log(&self) -> &VecDeque<MigrationAction>
Immutable reference to the internal migration log ring-buffer.
Sourcepub fn migrator_stats(&self) -> MigratorStats
pub fn migrator_stats(&self) -> MigratorStats
Snapshot of current migrator statistics.
Auto Trait Implementations§
impl Freeze for StorageTierMigrator
impl RefUnwindSafe for StorageTierMigrator
impl Send for StorageTierMigrator
impl Sync for StorageTierMigrator
impl Unpin for StorageTierMigrator
impl UnsafeUnpin for StorageTierMigrator
impl UnwindSafe for StorageTierMigrator
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