-
-
Notifications
You must be signed in to change notification settings - Fork 766
[management] Remove store locks #4038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,9 +280,6 @@ func (am *DefaultAccountManager) GetIdpManager() idp.Manager { | |
// User that performs the update has to belong to the account. | ||
// Returns an updated Settings | ||
func (am *DefaultAccountManager) UpdateAccountSettings(ctx context.Context, accountID, userID string, newSettings *types.Settings) (*types.Settings, error) { | ||
unlock := am.Store.AcquireWriteLockByUID(ctx, accountID) | ||
defer unlock() | ||
|
||
allowed, err := am.permissionsManager.ValidateUserPermissions(ctx, accountID, userID, modules.Settings, operations.Update) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to validate user permissions: %w", err) | ||
|
@@ -460,8 +457,6 @@ func (am *DefaultAccountManager) peerLoginExpirationJob(ctx context.Context, acc | |
ctx := context.WithValue(ctx, nbcontext.AccountIDKey, accountID) | ||
//nolint | ||
ctx = context.WithValue(ctx, hook.ExecutionContextKey, fmt.Sprintf("%s-PEER-EXPIRATION", hook.SystemSource)) | ||
unlock := am.Store.AcquireWriteLockByUID(ctx, accountID) | ||
defer unlock() | ||
|
||
expiredPeers, err := am.getExpiredPeers(ctx, accountID) | ||
if err != nil { | ||
|
@@ -497,9 +492,6 @@ func (am *DefaultAccountManager) schedulePeerLoginExpiration(ctx context.Context | |
// peerInactivityExpirationJob marks login expired for all inactive peers and returns the minimum duration in which the next peer of the account will expire by inactivity if found | ||
func (am *DefaultAccountManager) peerInactivityExpirationJob(ctx context.Context, accountID string) func() (time.Duration, bool) { | ||
return func() (time.Duration, bool) { | ||
unlock := am.Store.AcquireWriteLockByUID(ctx, accountID) | ||
defer unlock() | ||
|
||
inactivePeers, err := am.getInactivePeers(ctx, accountID) | ||
if err != nil { | ||
log.WithContext(ctx).Errorf("failed getting inactive peers for account %s", accountID) | ||
|
@@ -640,8 +632,6 @@ func (am *DefaultAccountManager) isCacheCold(ctx context.Context, store cacheSto | |
|
||
// DeleteAccount deletes an account and all its users from local store and from the remote IDP if the requester is an admin and account owner | ||
func (am *DefaultAccountManager) DeleteAccount(ctx context.Context, accountID, userID string) error { | ||
unlock := am.Store.AcquireWriteLockByUID(ctx, accountID) | ||
defer unlock() | ||
account, err := am.Store.GetAccount(ctx, accountID) | ||
if err != nil { | ||
return err | ||
|
@@ -1007,9 +997,6 @@ func (am *DefaultAccountManager) updateAccountDomainAttributesIfNotUpToDate(ctx | |
return nil | ||
} | ||
|
||
unlockAccount := am.Store.AcquireWriteLockByUID(ctx, accountID) | ||
defer unlockAccount() | ||
|
||
Comment on lines
-1010
to
-1012
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that here better to add a transaction |
||
accountDomain, domainCategory, err := am.Store.GetAccountDomainAndCategory(ctx, store.LockingStrengthShare, accountID) | ||
if err != nil { | ||
log.WithContext(ctx).Errorf("error getting account domain and category: %v", err) | ||
|
@@ -1102,9 +1089,6 @@ func (am *DefaultAccountManager) addNewPrivateAccount(ctx context.Context, domai | |
} | ||
|
||
func (am *DefaultAccountManager) addNewUserToDomainAccount(ctx context.Context, domainAccountID string, userAuth nbcontext.UserAuth) (string, error) { | ||
unlockAccount := am.Store.AcquireWriteLockByUID(ctx, domainAccountID) | ||
defer unlockAccount() | ||
|
||
newUser := types.NewRegularUser(userAuth.UserId) | ||
newUser.AccountID = domainAccountID | ||
err := am.Store.SaveUser(ctx, store.LockingStrengthUpdate, newUser) | ||
|
@@ -1251,13 +1235,6 @@ func (am *DefaultAccountManager) SyncUserJWTGroups(ctx context.Context, userAuth | |
return nil | ||
} | ||
|
||
unlockAccount := am.Store.AcquireWriteLockByUID(ctx, userAuth.AccountId) | ||
defer func() { | ||
if unlockAccount != nil { | ||
unlockAccount() | ||
} | ||
}() | ||
|
||
var addNewGroups []string | ||
var removeOldGroups []string | ||
var hasChanges bool | ||
|
@@ -1326,8 +1303,6 @@ func (am *DefaultAccountManager) SyncUserJWTGroups(ctx context.Context, userAuth | |
return fmt.Errorf("error incrementing network serial: %w", err) | ||
} | ||
} | ||
unlockAccount() | ||
unlockAccount = nil | ||
|
||
return nil | ||
}) | ||
|
@@ -1542,11 +1517,6 @@ func (am *DefaultAccountManager) SyncAndMarkPeer(ctx context.Context, accountID | |
log.WithContext(ctx).Debugf("SyncAndMarkPeer: took %v", time.Since(start)) | ||
}() | ||
|
||
accountUnlock := am.Store.AcquireReadLockByUID(ctx, accountID) | ||
defer accountUnlock() | ||
peerUnlock := am.Store.AcquireWriteLockByUID(ctx, peerPubKey) | ||
defer peerUnlock() | ||
|
||
peer, netMap, postureChecks, err := am.SyncPeer(ctx, types.PeerSync{WireGuardPubKey: peerPubKey, Meta: meta}, accountID) | ||
if err != nil { | ||
return nil, nil, nil, fmt.Errorf("error syncing peer: %w", err) | ||
|
@@ -1561,11 +1531,6 @@ func (am *DefaultAccountManager) SyncAndMarkPeer(ctx context.Context, accountID | |
} | ||
|
||
func (am *DefaultAccountManager) OnPeerDisconnected(ctx context.Context, accountID string, peerPubKey string) error { | ||
accountUnlock := am.Store.AcquireReadLockByUID(ctx, accountID) | ||
defer accountUnlock() | ||
peerUnlock := am.Store.AcquireWriteLockByUID(ctx, peerPubKey) | ||
defer peerUnlock() | ||
|
||
err := am.MarkPeerConnected(ctx, peerPubKey, false, nil, accountID) | ||
if err != nil { | ||
log.WithContext(ctx).Warnf("failed marking peer as disconnected %s %v", peerPubKey, err) | ||
|
@@ -1581,12 +1546,6 @@ func (am *DefaultAccountManager) SyncPeerMeta(ctx context.Context, peerPubKey st | |
return err | ||
} | ||
|
||
unlock := am.Store.AcquireReadLockByUID(ctx, accountID) | ||
defer unlock() | ||
|
||
unlockPeer := am.Store.AcquireWriteLockByUID(ctx, peerPubKey) | ||
defer unlockPeer() | ||
|
||
_, _, _, err = am.SyncPeer(ctx, types.PeerSync{WireGuardPubKey: peerPubKey, Meta: meta, UpdateAccountPeers: true}, accountID) | ||
if err != nil { | ||
return mapError(ctx, err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,9 +70,6 @@ func (m *managerImpl) CreateNetwork(ctx context.Context, userID string, network | |
|
||
network.ID = xid.New().String() | ||
|
||
unlock := m.store.AcquireWriteLockByUID(ctx, network.AccountID) | ||
defer unlock() | ||
|
||
err = m.store.SaveNetwork(ctx, store.LockingStrengthUpdate, network) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to save network: %w", err) | ||
|
@@ -104,9 +101,6 @@ func (m *managerImpl) UpdateNetwork(ctx context.Context, userID string, network | |
return nil, status.NewPermissionDeniedError() | ||
} | ||
|
||
unlock := m.store.AcquireWriteLockByUID(ctx, network.AccountID) | ||
defer unlock() | ||
|
||
Comment on lines
-107
to
-109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we need to add a transaction here, as some changes could be made between select and actual update |
||
_, err = m.store.GetNetworkByID(ctx, store.LockingStrengthUpdate, network.AccountID, network.ID) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get network: %w", err) | ||
|
@@ -131,9 +125,6 @@ func (m *managerImpl) DeleteNetwork(ctx context.Context, accountID, userID, netw | |
return fmt.Errorf("failed to get network: %w", err) | ||
} | ||
|
||
unlock := m.store.AcquireWriteLockByUID(ctx, accountID) | ||
defer unlock() | ||
|
||
var eventsToStore []func() | ||
err = m.store.ExecuteInTransaction(ctx, func(transaction store.Store) error { | ||
resources, err := transaction.GetNetworkResourcesByNetID(ctx, store.LockingStrengthUpdate, accountID, networkID) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that here we can have possible race. somewhere between user are being removed and actual removal of an account, still possible that user could be created