@@ -1952,20 +1952,19 @@ func (am *DefaultAccountManager) GetOrCreateAccountByPrivateDomain(ctx context.C
1952
1952
return nil , false , status .Errorf (status .Internal , "failed to get or create new account by private domain" )
1953
1953
}
1954
1954
1955
- func (am * DefaultAccountManager ) UpdateToPrimaryAccount (ctx context.Context , accountId string ) (* types.Account , error ) {
1956
- var account * types.Account
1955
+ func (am * DefaultAccountManager ) UpdateToPrimaryAccount (ctx context.Context , accountId string ) error {
1957
1956
err := am .Store .ExecuteInTransaction (ctx , func (transaction store.Store ) error {
1958
1957
var err error
1959
- account , err = transaction .GetAccount (ctx , accountId )
1958
+ ok , domain , err : = transaction .IsPrimaryAccount (ctx , accountId )
1960
1959
if err != nil {
1961
1960
return err
1962
1961
}
1963
1962
1964
- if account . IsDomainPrimaryAccount {
1963
+ if ok {
1965
1964
return nil
1966
1965
}
1967
1966
1968
- existingPrimaryAccountID , err := transaction .GetAccountIDByPrivateDomain (ctx , store .LockingStrengthNone , account . Domain )
1967
+ existingPrimaryAccountID , err := transaction .GetAccountIDByPrivateDomain (ctx , store .LockingStrengthNone , domain )
1969
1968
1970
1969
// error is not a not found error
1971
1970
if handleNotFound (err ) != nil {
@@ -1981,9 +1980,7 @@ func (am *DefaultAccountManager) UpdateToPrimaryAccount(ctx context.Context, acc
1981
1980
return status .Errorf (status .Internal , "cannot update account to primary" )
1982
1981
}
1983
1982
1984
- account .IsDomainPrimaryAccount = true
1985
-
1986
- if err := transaction .SaveAccount (ctx , account ); err != nil {
1983
+ if err := transaction .MarkAccountPrimary (ctx , accountId ); err != nil {
1987
1984
log .WithContext (ctx ).WithFields (log.Fields {
1988
1985
"accountId" : accountId ,
1989
1986
}).Errorf ("failed to update account to primary: %v" , err )
@@ -1993,10 +1990,10 @@ func (am *DefaultAccountManager) UpdateToPrimaryAccount(ctx context.Context, acc
1993
1990
return nil
1994
1991
})
1995
1992
if err != nil {
1996
- return nil , err
1993
+ return err
1997
1994
}
1998
1995
1999
- return account , nil
1996
+ return nil
2000
1997
}
2001
1998
2002
1999
// propagateUserGroupMemberships propagates all account users' group memberships to their peers.
@@ -2067,14 +2064,12 @@ func (am *DefaultAccountManager) reallocateAccountPeerIPs(ctx context.Context, t
2067
2064
Mask : net .CIDRMask (newNetworkRange .Bits (), newNetworkRange .Addr ().BitLen ()),
2068
2065
}
2069
2066
2070
- account , err := transaction .GetAccount (ctx , accountID )
2067
+ err := transaction .UpdateAccountNetwork (ctx , accountID , newIPNet )
2071
2068
if err != nil {
2072
2069
return err
2073
2070
}
2074
2071
2075
- account .Network .Net = newIPNet
2076
-
2077
- peers , err := transaction .GetAccountPeers (ctx , store .LockingStrengthNone , accountID , "" , "" )
2072
+ peers , err := transaction .GetAccountPeers (ctx , store .LockingStrengthUpdate , accountID , "" , "" )
2078
2073
if err != nil {
2079
2074
return err
2080
2075
}
@@ -2094,10 +2089,6 @@ func (am *DefaultAccountManager) reallocateAccountPeerIPs(ctx context.Context, t
2094
2089
takenIPs = append (takenIPs , newIP )
2095
2090
}
2096
2091
2097
- if err = transaction .SaveAccount (ctx , account ); err != nil {
2098
- return err
2099
- }
2100
-
2101
2092
for _ , peer := range peers {
2102
2093
if err = transaction .SavePeer (ctx , accountID , peer ); err != nil {
2103
2094
return status .Errorf (status .Internal , "save updated peer %s: %v" , peer .ID , err )
0 commit comments