mirror of
https://github.com/minio/minio.git
synced 2025-01-11 23:13:23 -05:00
fix: concurrency bug in site-replication (#14786)
The site replication status call was using a loop iteration variable sent directly into go-routines instead of being passed as an argument. As the variable is being updated in the loop, previously launched go routines do not necessarily use the value at the time they were launched.
This commit is contained in:
parent
507f993075
commit
ddf84f8257
@ -40,7 +40,6 @@ import (
|
|||||||
"github.com/minio/minio/internal/auth"
|
"github.com/minio/minio/internal/auth"
|
||||||
sreplication "github.com/minio/minio/internal/bucket/replication"
|
sreplication "github.com/minio/minio/internal/bucket/replication"
|
||||||
"github.com/minio/minio/internal/logger"
|
"github.com/minio/minio/internal/logger"
|
||||||
"github.com/minio/minio/internal/sync/errgroup"
|
|
||||||
"github.com/minio/pkg/bucket/policy"
|
"github.com/minio/pkg/bucket/policy"
|
||||||
bktpolicy "github.com/minio/pkg/bucket/policy"
|
bktpolicy "github.com/minio/pkg/bucket/policy"
|
||||||
iampolicy "github.com/minio/pkg/iam/policy"
|
iampolicy "github.com/minio/pkg/iam/policy"
|
||||||
@ -2124,38 +2123,38 @@ func (c *SiteReplicationSys) SiteReplicationStatus(ctx context.Context, objAPI O
|
|||||||
}
|
}
|
||||||
|
|
||||||
sris := make([]madmin.SRInfo, len(c.state.Peers))
|
sris := make([]madmin.SRInfo, len(c.state.Peers))
|
||||||
sriErrs := make([]error, len(c.state.Peers))
|
idxMap := make(map[string]int, len(c.state.Peers))
|
||||||
g := errgroup.WithNErrs(len(c.state.Peers))
|
|
||||||
var depIDs []string
|
var depIDs []string
|
||||||
|
i := 0
|
||||||
for d := range c.state.Peers {
|
for d := range c.state.Peers {
|
||||||
depIDs = append(depIDs, d)
|
depIDs = append(depIDs, d)
|
||||||
|
idxMap[d] = i
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
for index := range depIDs {
|
|
||||||
index := index
|
metaInfoConcErr := c.concDo(
|
||||||
if depIDs[index] == globalDeploymentID {
|
func() error {
|
||||||
g.Go(func() error {
|
srInfo, err := c.SiteReplicationMetaInfo(ctx, objAPI, opts)
|
||||||
sris[index], sriErrs[index] = c.SiteReplicationMetaInfo(ctx, objAPI, opts)
|
k := idxMap[globalDeploymentID]
|
||||||
return nil
|
sris[k] = srInfo
|
||||||
}, index)
|
return err
|
||||||
continue
|
},
|
||||||
}
|
func(deploymentID string, p madmin.PeerInfo) error {
|
||||||
g.Go(func() error {
|
admClient, err := c.getAdminClient(ctx, deploymentID)
|
||||||
admClient, err := c.getAdminClient(ctx, depIDs[index])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sris[index], sriErrs[index] = admClient.SRMetaInfo(ctx, opts)
|
srInfo, err := admClient.SRMetaInfo(ctx, opts)
|
||||||
return nil
|
k := idxMap[deploymentID]
|
||||||
}, index)
|
sris[k] = srInfo
|
||||||
}
|
return err
|
||||||
// Wait for the go routines.
|
},
|
||||||
g.Wait()
|
)
|
||||||
|
|
||||||
for _, serr := range sriErrs {
|
if metaInfoConcErr.summaryErr != nil {
|
||||||
if serr != nil {
|
return info, errSRBackendIssue(metaInfoConcErr.summaryErr)
|
||||||
return info, errSRBackendIssue(serr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info.Enabled = true
|
info.Enabled = true
|
||||||
info.Sites = make(map[string]madmin.PeerInfo, len(c.state.Peers))
|
info.Sites = make(map[string]madmin.PeerInfo, len(c.state.Peers))
|
||||||
for d, peer := range c.state.Peers {
|
for d, peer := range c.state.Peers {
|
||||||
|
Loading…
Reference in New Issue
Block a user