-
Notifications
You must be signed in to change notification settings - Fork 230
Open
Labels
Description
Description
We need a feature to acquire distributed locks on multiple keys simultaneously. The solution must:
- Acquire locks in a deterministic order (e.g., alphabetical) to prevent deadlocks.
- Return a composite lock that implements IDistributedLock so it can be used in a using block.
- Roll back all acquired locks if any single lock cannot be acquired within a timeout.
Real-World Use Case
Imagine we have three data banks (A, B, C) and users want to extract records from them. Each bank uses a cursor to mark the last retrieved record so that subsequent extractions don’t return duplicates. Users might request a combination—say, N records from Bank A, M from Bank B, and O from Bank C—in a single operation. To ensure data consistency and proper cursor advancement without overlap, we need to atomically lock the selected banks during the extraction.
Example Code Use Case
// Operation: extract records from Banks A, B, and C simultaneously.
var keysToLock = new[] { "BankA", "BankB", "BankC" };
var compositeLock = await distributedLockProvider.TryAcquireMultiLockAsync(keysToLock, TimeSpan.FromSeconds(2), cancellationToken);
I’m ready to implement this feature. Please let me know if you have any feedback or additional requirements.
HMDMHMDI