Skip to content

Commit f9d64a0

Browse files
[management] Remove all store locks from grpc side (#4374)
1 parent 86555c4 commit f9d64a0

File tree

4 files changed

+0
-61
lines changed

4 files changed

+0
-61
lines changed

management/server/account.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,11 +1639,6 @@ func (am *DefaultAccountManager) SyncAndMarkPeer(ctx context.Context, accountID
16391639
log.WithContext(ctx).Debugf("SyncAndMarkPeer: took %v", time.Since(start))
16401640
}()
16411641

1642-
accountUnlock := am.Store.AcquireReadLockByUID(ctx, accountID)
1643-
defer accountUnlock()
1644-
peerUnlock := am.Store.AcquireWriteLockByUID(ctx, peerPubKey)
1645-
defer peerUnlock()
1646-
16471642
peer, netMap, postureChecks, err := am.SyncPeer(ctx, types.PeerSync{WireGuardPubKey: peerPubKey, Meta: meta}, accountID)
16481643
if err != nil {
16491644
return nil, nil, nil, fmt.Errorf("error syncing peer: %w", err)
@@ -1658,18 +1653,12 @@ func (am *DefaultAccountManager) SyncAndMarkPeer(ctx context.Context, accountID
16581653
}
16591654

16601655
func (am *DefaultAccountManager) OnPeerDisconnected(ctx context.Context, accountID string, peerPubKey string) error {
1661-
accountUnlock := am.Store.AcquireReadLockByUID(ctx, accountID)
1662-
defer accountUnlock()
1663-
peerUnlock := am.Store.AcquireWriteLockByUID(ctx, peerPubKey)
1664-
defer peerUnlock()
1665-
16661656
err := am.MarkPeerConnected(ctx, peerPubKey, false, nil, accountID)
16671657
if err != nil {
16681658
log.WithContext(ctx).Warnf("failed marking peer as disconnected %s %v", peerPubKey, err)
16691659
}
16701660

16711661
return nil
1672-
16731662
}
16741663

16751664
func (am *DefaultAccountManager) SyncPeerMeta(ctx context.Context, peerPubKey string, meta nbpeer.PeerSystemMeta) error {
@@ -1678,12 +1667,6 @@ func (am *DefaultAccountManager) SyncPeerMeta(ctx context.Context, peerPubKey st
16781667
return err
16791668
}
16801669

1681-
unlock := am.Store.AcquireReadLockByUID(ctx, accountID)
1682-
defer unlock()
1683-
1684-
unlockPeer := am.Store.AcquireWriteLockByUID(ctx, peerPubKey)
1685-
defer unlockPeer()
1686-
16871670
_, _, _, err = am.SyncPeer(ctx, types.PeerSync{WireGuardPubKey: peerPubKey, Meta: meta, UpdateAccountPeers: true}, accountID)
16881671
if err != nil {
16891672
return mapError(ctx, err)

management/server/peer.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,6 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s
609609
newPeer.DNSLabel = freeLabel
610610
newPeer.IP = freeIP
611611

612-
unlock := am.Store.AcquireReadLockByUID(ctx, accountID)
613-
defer func() {
614-
if unlock != nil {
615-
unlock()
616-
}
617-
}()
618-
619612
err = am.Store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
620613
err = transaction.AddPeerToAccount(ctx, newPeer)
621614
if err != nil {
@@ -667,14 +660,10 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s
667660
return nil
668661
})
669662
if err == nil {
670-
unlock()
671-
unlock = nil
672663
break
673664
}
674665

675666
if isUniqueConstraintError(err) {
676-
unlock()
677-
unlock = nil
678667
log.WithContext(ctx).WithFields(log.Fields{"dns_label": freeLabel, "ip": freeIP}).Tracef("Failed to add peer in attempt %d, retrying: %v", attempt, err)
679668
continue
680669
}
@@ -833,15 +822,6 @@ func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login types.Peer
833822
}
834823
}
835824

836-
unlockAccount := am.Store.AcquireReadLockByUID(ctx, accountID)
837-
defer unlockAccount()
838-
unlockPeer := am.Store.AcquireWriteLockByUID(ctx, login.WireGuardPubKey)
839-
defer func() {
840-
if unlockPeer != nil {
841-
unlockPeer()
842-
}
843-
}()
844-
845825
var peer *nbpeer.Peer
846826
var updateRemotePeers bool
847827
var isRequiresApproval bool
@@ -922,9 +902,6 @@ func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login types.Peer
922902
return nil, nil, nil, err
923903
}
924904

925-
unlockPeer()
926-
unlockPeer = nil
927-
928905
if updateRemotePeers || isStatusChanged || (isPeerUpdated && len(postureChecks) > 0) {
929906
am.BufferUpdateAccountPeers(ctx, accountID)
930907
}

management/server/store/sql_store.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,6 @@ func (s *SqlStore) AcquireWriteLockByUID(ctx context.Context, uniqueID string) (
163163
return unlock
164164
}
165165

166-
// AcquireReadLockByUID acquires an ID lock for writing to a resource and returns a function that releases the lock
167-
func (s *SqlStore) AcquireReadLockByUID(ctx context.Context, uniqueID string) (unlock func()) {
168-
log.WithContext(ctx).Tracef("acquiring read lock for ID %s", uniqueID)
169-
170-
startWait := time.Now()
171-
value, _ := s.resourceLocks.LoadOrStore(uniqueID, &sync.RWMutex{})
172-
mtx := value.(*sync.RWMutex)
173-
mtx.RLock()
174-
log.WithContext(ctx).Tracef("waiting to acquire read lock for ID %s in %v", uniqueID, time.Since(startWait))
175-
startHold := time.Now()
176-
177-
unlock = func() {
178-
mtx.RUnlock()
179-
log.WithContext(ctx).Tracef("released read lock for ID %s in %v", uniqueID, time.Since(startHold))
180-
}
181-
182-
return unlock
183-
}
184-
185166
// Deprecated: Full account operations are no longer supported
186167
func (s *SqlStore) SaveAccount(ctx context.Context, account *types.Account) error {
187168
start := time.Now()

management/server/store/store.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ type Store interface {
170170

171171
// AcquireWriteLockByUID should attempt to acquire a lock for write purposes and return a function that releases the lock
172172
AcquireWriteLockByUID(ctx context.Context, uniqueID string) func()
173-
// AcquireReadLockByUID should attempt to acquire lock for read purposes and return a function that releases the lock
174-
AcquireReadLockByUID(ctx context.Context, uniqueID string) func()
175173
// AcquireGlobalLock should attempt to acquire a global lock and return a function that releases the lock
176174
AcquireGlobalLock(ctx context.Context) func()
177175

0 commit comments

Comments
 (0)