src/meta/plugins/semaphore/README.md
A distributed semaphore implementation based on meta-service, providing reliable resource management across distributed systems.
This crate implements a distributed semaphore using a meta-service as the underlying storage and coordination mechanism. It provides a robust way to manage and coordinate access to limited resources across distributed systems.
<prefix>/meta -> {capacity: 10} // Planned for future versions
<prefix>/queue/<seq_1> -> {id: "<id_1>", value: 1}
<prefix>/queue/<seq_2> -> {id: "<id_2>", value: 2}
<prefix>/queue/<seq_3> -> {id: "<id_3>", value: 1}
<prefix>/seq_generator -> {}
<prefix>: User-defined string to identify a semaphore instancequeue/*: Contains semaphore entries with sequence numbersseq_generator: Generates globally unique sequence numbersid: User-defined identifiervalue: Resource amount consumedSemaphore: The main entry point for semaphore operationsAcquirer: Handles the semaphore acquisition processAcquiredGuard: Manages the lifecycle of an acquired semaphoreSemaphoreEntry: Represents a semaphore entry in the queueSemaphoreKey: Defines the key structure for semaphore entrieslet client = MetaGrpcClient::try_create(/*..*/);
let acquired_guard = Semaphore::new_acquired(
client,
"your/semaphore/name/in/meta/service",
2, // capacity: 2 acquired at most
"id11", // ID of this acquirer
Duration::from_secs(3) // lease time
).await?;
acquired_guard.await;
// Released
seq_generatorSemaphoreEntry and inserts it at queue/<seq>acquired and waiting entriesmeta key for consistencyThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.