mirror of https://github.com/minio/minio.git
avoid locks when unnecessary in SiteReplicationMetaInfo() (#16650)
This commit is contained in:
parent
7f2c90a0ed
commit
b94733ab31
|
@ -2034,9 +2034,7 @@ func (a adminAPIHandlers) ExportIAM(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
case allUsersFile:
|
case allUsersFile:
|
||||||
userIdentities := make(map[string]UserIdentity)
|
userIdentities := make(map[string]UserIdentity)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadUsers(ctx, regUser, userIdentities)
|
err := globalIAMSys.store.loadUsers(ctx, regUser, userIdentities)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
||||||
return
|
return
|
||||||
|
@ -2064,9 +2062,7 @@ func (a adminAPIHandlers) ExportIAM(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
case allGroupsFile:
|
case allGroupsFile:
|
||||||
groups := make(map[string]GroupInfo)
|
groups := make(map[string]GroupInfo)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadGroups(ctx, groups)
|
err := globalIAMSys.store.loadGroups(ctx, groups)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
||||||
return
|
return
|
||||||
|
@ -2083,9 +2079,7 @@ func (a adminAPIHandlers) ExportIAM(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
case allSvcAcctsFile:
|
case allSvcAcctsFile:
|
||||||
serviceAccounts := make(map[string]UserIdentity)
|
serviceAccounts := make(map[string]UserIdentity)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadUsers(ctx, svcUser, serviceAccounts)
|
err := globalIAMSys.store.loadUsers(ctx, svcUser, serviceAccounts)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
||||||
return
|
return
|
||||||
|
@ -2134,9 +2128,7 @@ func (a adminAPIHandlers) ExportIAM(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
case userPolicyMappingsFile:
|
case userPolicyMappingsFile:
|
||||||
userPolicyMap := make(map[string]MappedPolicy)
|
userPolicyMap := make(map[string]MappedPolicy)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadMappedPolicies(ctx, regUser, false, userPolicyMap)
|
err := globalIAMSys.store.loadMappedPolicies(ctx, regUser, false, userPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
||||||
return
|
return
|
||||||
|
@ -2153,9 +2145,7 @@ func (a adminAPIHandlers) ExportIAM(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
case groupPolicyMappingsFile:
|
case groupPolicyMappingsFile:
|
||||||
groupPolicyMap := make(map[string]MappedPolicy)
|
groupPolicyMap := make(map[string]MappedPolicy)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadMappedPolicies(ctx, regUser, true, groupPolicyMap)
|
err := globalIAMSys.store.loadMappedPolicies(ctx, regUser, true, groupPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
||||||
return
|
return
|
||||||
|
@ -2172,9 +2162,7 @@ func (a adminAPIHandlers) ExportIAM(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
case stsUserPolicyMappingsFile:
|
case stsUserPolicyMappingsFile:
|
||||||
userPolicyMap := make(map[string]MappedPolicy)
|
userPolicyMap := make(map[string]MappedPolicy)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, false, userPolicyMap)
|
err := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, false, userPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
||||||
return
|
return
|
||||||
|
@ -2190,9 +2178,7 @@ func (a adminAPIHandlers) ExportIAM(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
case stsGroupPolicyMappingsFile:
|
case stsGroupPolicyMappingsFile:
|
||||||
groupPolicyMap := make(map[string]MappedPolicy)
|
groupPolicyMap := make(map[string]MappedPolicy)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, true, groupPolicyMap)
|
err := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, true, groupPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, iamFile, ""), r.URL)
|
||||||
return
|
return
|
||||||
|
|
|
@ -194,7 +194,6 @@ type SiteReplicationSys struct {
|
||||||
state srState
|
state srState
|
||||||
|
|
||||||
iamMetaCache srIAMCache
|
iamMetaCache srIAMCache
|
||||||
iamInfoLk sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type srState srStateV1
|
type srState srStateV1
|
||||||
|
@ -1696,9 +1695,7 @@ func (c *SiteReplicationSys) syncToAllPeers(ctx context.Context) error {
|
||||||
// may not have any local users.
|
// may not have any local users.
|
||||||
{
|
{
|
||||||
userAccounts := make(map[string]UserIdentity)
|
userAccounts := make(map[string]UserIdentity)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadUsers(ctx, regUser, userAccounts)
|
err := globalIAMSys.store.loadUsers(ctx, regUser, userAccounts)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errSRBackendIssue(err)
|
return errSRBackendIssue(err)
|
||||||
}
|
}
|
||||||
|
@ -1725,10 +1722,7 @@ func (c *SiteReplicationSys) syncToAllPeers(ctx context.Context) error {
|
||||||
// DNs here
|
// DNs here
|
||||||
{
|
{
|
||||||
groups := make(map[string]GroupInfo)
|
groups := make(map[string]GroupInfo)
|
||||||
|
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadGroups(ctx, groups)
|
err := globalIAMSys.store.loadGroups(ctx, groups)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errSRBackendIssue(err)
|
return errSRBackendIssue(err)
|
||||||
}
|
}
|
||||||
|
@ -1755,9 +1749,7 @@ func (c *SiteReplicationSys) syncToAllPeers(ctx context.Context) error {
|
||||||
{
|
{
|
||||||
// Replicate policy mappings on local to all peers.
|
// Replicate policy mappings on local to all peers.
|
||||||
groupPolicyMap := make(map[string]MappedPolicy)
|
groupPolicyMap := make(map[string]MappedPolicy)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
errG := globalIAMSys.store.loadMappedPolicies(ctx, unknownIAMUserType, true, groupPolicyMap)
|
errG := globalIAMSys.store.loadMappedPolicies(ctx, unknownIAMUserType, true, groupPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if errG != nil {
|
if errG != nil {
|
||||||
return errSRBackendIssue(errG)
|
return errSRBackendIssue(errG)
|
||||||
}
|
}
|
||||||
|
@ -1783,9 +1775,7 @@ func (c *SiteReplicationSys) syncToAllPeers(ctx context.Context) error {
|
||||||
// valid claims.
|
// valid claims.
|
||||||
{
|
{
|
||||||
serviceAccounts := make(map[string]UserIdentity)
|
serviceAccounts := make(map[string]UserIdentity)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
err := globalIAMSys.store.loadUsers(ctx, svcUser, serviceAccounts)
|
err := globalIAMSys.store.loadUsers(ctx, svcUser, serviceAccounts)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errSRBackendIssue(err)
|
return errSRBackendIssue(err)
|
||||||
}
|
}
|
||||||
|
@ -1841,9 +1831,7 @@ func (c *SiteReplicationSys) syncToAllPeers(ctx context.Context) error {
|
||||||
{
|
{
|
||||||
// Replicate policy mappings on local to all peers.
|
// Replicate policy mappings on local to all peers.
|
||||||
userPolicyMap := make(map[string]MappedPolicy)
|
userPolicyMap := make(map[string]MappedPolicy)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
errU := globalIAMSys.store.loadMappedPolicies(ctx, regUser, false, userPolicyMap)
|
errU := globalIAMSys.store.loadMappedPolicies(ctx, regUser, false, userPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if errU != nil {
|
if errU != nil {
|
||||||
return errSRBackendIssue(errU)
|
return errSRBackendIssue(errU)
|
||||||
}
|
}
|
||||||
|
@ -1869,9 +1857,7 @@ func (c *SiteReplicationSys) syncToAllPeers(ctx context.Context) error {
|
||||||
{
|
{
|
||||||
// Replicate policy mappings on local to all peers.
|
// Replicate policy mappings on local to all peers.
|
||||||
stsPolicyMap := make(map[string]MappedPolicy)
|
stsPolicyMap := make(map[string]MappedPolicy)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
errU := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, false, stsPolicyMap)
|
errU := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, false, stsPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if errU != nil {
|
if errU != nil {
|
||||||
return errSRBackendIssue(errU)
|
return errSRBackendIssue(errU)
|
||||||
}
|
}
|
||||||
|
@ -3252,8 +3238,6 @@ func (c *SiteReplicationSys) SiteReplicationMetaInfo(ctx context.Context, objAPI
|
||||||
if opts.Users && opts.Groups && opts.Policies && !opts.Buckets {
|
if opts.Users && opts.Groups && opts.Policies && !opts.Buckets {
|
||||||
// serialize SiteReplicationMetaInfo calls - if data in cache is within
|
// serialize SiteReplicationMetaInfo calls - if data in cache is within
|
||||||
// healing interval, avoid fetching IAM data again from disk.
|
// healing interval, avoid fetching IAM data again from disk.
|
||||||
c.iamInfoLk.Lock()
|
|
||||||
defer c.iamInfoLk.Unlock()
|
|
||||||
if metaInfo, ok := c.getSRCachedIAMInfo(); ok {
|
if metaInfo, ok := c.getSRCachedIAMInfo(); ok {
|
||||||
return metaInfo, nil
|
return metaInfo, nil
|
||||||
}
|
}
|
||||||
|
@ -3289,21 +3273,15 @@ func (c *SiteReplicationSys) SiteReplicationMetaInfo(ctx context.Context, objAPI
|
||||||
userPolicyMap[opts.EntityValue] = mp
|
userPolicyMap[opts.EntityValue] = mp
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
stsErr := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, false, userPolicyMap)
|
stsErr := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, false, userPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if stsErr != nil {
|
if stsErr != nil {
|
||||||
return info, errSRBackendIssue(stsErr)
|
return info, errSRBackendIssue(stsErr)
|
||||||
}
|
}
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
usrErr := globalIAMSys.store.loadMappedPolicies(ctx, regUser, false, userPolicyMap)
|
usrErr := globalIAMSys.store.loadMappedPolicies(ctx, regUser, false, userPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if usrErr != nil {
|
if usrErr != nil {
|
||||||
return info, errSRBackendIssue(usrErr)
|
return info, errSRBackendIssue(usrErr)
|
||||||
}
|
}
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
svcErr := globalIAMSys.store.loadMappedPolicies(ctx, svcUser, false, userPolicyMap)
|
svcErr := globalIAMSys.store.loadMappedPolicies(ctx, svcUser, false, userPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if svcErr != nil {
|
if svcErr != nil {
|
||||||
return info, errSRBackendIssue(svcErr)
|
return info, errSRBackendIssue(svcErr)
|
||||||
}
|
}
|
||||||
|
@ -3324,23 +3302,17 @@ func (c *SiteReplicationSys) SiteReplicationMetaInfo(ctx context.Context, objAPI
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
userAccounts := make(map[string]UserIdentity)
|
userAccounts := make(map[string]UserIdentity)
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
uerr := globalIAMSys.store.loadUsers(ctx, regUser, userAccounts)
|
uerr := globalIAMSys.store.loadUsers(ctx, regUser, userAccounts)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if uerr != nil {
|
if uerr != nil {
|
||||||
return info, errSRBackendIssue(uerr)
|
return info, errSRBackendIssue(uerr)
|
||||||
}
|
}
|
||||||
|
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
serr := globalIAMSys.store.loadUsers(ctx, svcUser, userAccounts)
|
serr := globalIAMSys.store.loadUsers(ctx, svcUser, userAccounts)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if serr != nil {
|
if serr != nil {
|
||||||
return info, errSRBackendIssue(serr)
|
return info, errSRBackendIssue(serr)
|
||||||
}
|
}
|
||||||
|
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
terr := globalIAMSys.store.loadUsers(ctx, stsUser, userAccounts)
|
terr := globalIAMSys.store.loadUsers(ctx, stsUser, userAccounts)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if terr != nil {
|
if terr != nil {
|
||||||
return info, errSRBackendIssue(terr)
|
return info, errSRBackendIssue(terr)
|
||||||
}
|
}
|
||||||
|
@ -3372,15 +3344,11 @@ func (c *SiteReplicationSys) SiteReplicationMetaInfo(ctx context.Context, objAPI
|
||||||
groupPolicyMap[opts.EntityValue] = mp
|
groupPolicyMap[opts.EntityValue] = mp
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
stsErr := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, true, groupPolicyMap)
|
stsErr := globalIAMSys.store.loadMappedPolicies(ctx, stsUser, true, groupPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if stsErr != nil {
|
if stsErr != nil {
|
||||||
return info, errSRBackendIssue(stsErr)
|
return info, errSRBackendIssue(stsErr)
|
||||||
}
|
}
|
||||||
globalIAMSys.store.rlock()
|
|
||||||
userErr := globalIAMSys.store.loadMappedPolicies(ctx, regUser, true, groupPolicyMap)
|
userErr := globalIAMSys.store.loadMappedPolicies(ctx, regUser, true, groupPolicyMap)
|
||||||
globalIAMSys.store.runlock()
|
|
||||||
if userErr != nil {
|
if userErr != nil {
|
||||||
return info, errSRBackendIssue(userErr)
|
return info, errSRBackendIssue(userErr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue