compute_lock_key

Function compute_lock_key 

Source
pub fn compute_lock_key(resource_type: &str, resource_id: Uuid) -> i64
Expand description

Compute a stable i64 key for advisory locks using FNV-1a hash.

FNV-1a is deterministic across Rust versions and compilations, making it suitable for distributed lock coordination via PostgreSQL advisory locks.

§Arguments

  • resource_type - The type of resource being locked (e.g., “trajectory”, “scope”)
  • resource_id - The unique identifier of the resource

§Returns

A stable i64 hash that can be used with PostgreSQL’s pg_advisory_lock().

§Example

use cellstate_core::compute_lock_key;
use uuid::Uuid;

let resource_id = Uuid::now_v7();
let lock_key = compute_lock_key("trajectory", resource_id);
// Use lock_key with pg_advisory_lock(lock_key)