Skip to main content

Crate perl_workspace_index_state_machine

Crate perl_workspace_index_state_machine 

Source
Expand description

Enhanced index lifecycle state machine for production readiness.

This module provides a comprehensive state machine for index lifecycle management with additional states for initialization, updating, invalidation, and error handling. The state machine ensures thread-safe state transitions with proper guards and error recovery mechanisms.

§State Machine States

  • Idle: Index is idle and not initialized
  • Initializing: Index is being initialized
  • Building: Index is being built (workspace scan in progress)
  • Updating: Index is being updated (incremental changes)
  • Invalidating: Index is being invalidated
  • Ready: Index is ready for queries
  • Degraded: Index is degraded but partially functional
  • Error: Index is in error state

§State Transitions

Idle → Initializing → Building → Updating → Ready
 ↓         ↓            ↓          ↓         ↓
Error ← Error ← Error ← Error ← Error ← Error
 ↓         ↓            ↓          ↓         ↓
Degraded ← Degraded ← Degraded ← Degraded ← Degraded

§Thread Safety

  • All state transitions are protected by RwLock
  • State reads are lock-free (cloned state)
  • State writes use exclusive locks
  • Guards prevent invalid transitions

§Usage

use perl_workspace_index_state_machine::{IndexStateMachine, IndexState};

let machine = IndexStateMachine::new();
assert!(matches!(machine.state(), IndexState::Idle));

machine.transition_to_initializing();
machine.transition_to_building(100); // 100 files to index

Structs§

BuildPhaseTransition
A phase transition while building the workspace index.
IndexStateMachine
Thread-safe index state machine.
IndexStateTransition
State transition for index lifecycle instrumentation.

Enums§

BuildPhase
Build phases for the Building state.
DegradationReason
Reason for index degradation.
IndexState
Enhanced index state with additional production-ready states.
IndexStateKind
Coarse index state kinds for instrumentation and transition tracking.
InvalidationReason
Reason for index invalidation.
ResourceKind
Type of resource limit that was exceeded.
TransitionResult
Result of a state transition attempt.