MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / acquireLineageLocks

Method acquireLineageLocks

lineage.go:506–522  ·  view source on GitHub ↗

acquireLineageLocks acquires distributed locks for multiple shadow balances using MultiLocker. MultiLocker handles sorting (prevents deadlock) and deduplication automatically. This is used for both credit and debit lineage processing to prevent race conditions. Parameters: - ctx context.Context: Th

(ctx context.Context, balanceIDs []string)

Source from the content-addressed store, hash-verified

504// - *redlock.MultiLocker: The acquired multi-lock.
505// - error: An error if the locks could not be acquired.
506func (l *LedgerForge) acquireLineageLocks(ctx context.Context, balanceIDs []string) (*redlock.MultiLocker, error) {
507 // Prefix all keys to avoid collision with main transaction locks
508 lockKeys := make([]string, 0, len(balanceIDs))
509 for _, id := range balanceIDs {
510 lockKeys = append(lockKeys, fmt.Sprintf("lineage:%s", id))
511 }
512
513 // MultiLocker handles deduplication and sorts keys lexicographically
514 locker := redlock.NewMultiLocker(l.redis, lockKeys, model.GenerateUUIDWithSuffix("loc"))
515
516 err := locker.Lock(ctx, l.Config().Transaction.LockDuration)
517 if err != nil {
518 return nil, fmt.Errorf("failed to acquire lineage locks: %w", err)
519 }
520
521 return locker, nil
522}
523
524// getSourceAggregateBalance retrieves or creates the aggregate balance for the source identity.
525//

Callers 2

processLineageCreditMethod · 0.95
processLineageDebitMethod · 0.95

Calls 3

LockMethod · 0.95
ConfigMethod · 0.95
GenerateUUIDWithSuffixFunction · 0.92

Tested by

no test coverage detected