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>", permits: 1}
<prefix>/queue/<seq_2> -> {id: "<id_2>", permits: 2}
<prefix>/queue/<seq_3> -> {id: "<id_3>", permits: 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 identifierpermits: Resource amount consumedSemaphore: The main entry point for semaphore operationsPermit: Manages the lifecycle of an acquired semaphorePermitEntry: Represents a semaphore entry in the queuePermitKey: Defines the key structure for semaphore entriesAcquirer: Internal helper that handles the semaphore acquisition processlet client = MetaGrpcClient::try_create(/*..*/);
let permit = 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?;
permit.await?;
// Removed from meta-service
seq_generatorPermitEntry 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.