Module lock_manager

Source
Expand description

Workflow Lock Manager for Concurrent Access Control

This module provides a thread-safe lock manager for controlling concurrent access to AIM workflows. It uses fine-grained locking to allow maximum concurrency while ensuring data consistency during write operations.

§Overview

The lock manager implements a per-workflow locking strategy that:

  • Allows unlimited concurrent read access to workflows
  • Ensures exclusive write access to individual workflows
  • Uses reference-based locking to prevent conflicts
  • Provides a global singleton instance for application-wide coordination

§Concurrency Model

AIM uses a Multi-Version Concurrency Control (MVCC) model where:

  • Readers access consistent snapshots without blocking
  • Writers acquire exclusive locks on specific workflows
  • Locks are automatically released when guard objects are dropped
  • Fine-grained locking minimizes contention compared to global locks

§Examples

use aimx::aim::get_lock_manager;
use aimx::Reference;

// Get the global lock manager instance
let lock_manager = get_lock_manager();

// Acquire a lock for a specific workflow
let reference = Reference::One("my_workflow".to_string());
let lock_guard = lock_manager.acquire_workflow_lock(reference);

// The lock is held until `lock_guard` is dropped
// Perform write operations on the workflow...

// Lock is automatically released when `lock_guard` goes out of scope

§Thread Safety

The LockManager is designed to be used as a global singleton and is completely thread-safe. All operations use atomic reference counting and concurrent data structures to ensure safe access from multiple threads.

§Implementation Details

  • Uses DashMap for lock-free concurrent access to the lock table
  • Employs Arc<Mutex<()>> for shared ownership of individual locks
  • Provides lazy initialization of locks on first access
  • Future enhancements may include file system-level locking mechanisms

Structs§

LockManager
Manages concurrent access to workflows through fine-grained locking

Functions§

get_lock_manager
Returns the global singleton instance of the LockManager