Fix globalDeploymentID race (#18275)

globalDeploymentID was being read while it was being set.

Fixes race:

```
WARNING: DATA RACE
Write at 0x0000079605a0 by main goroutine:
  github.com/minio/minio/cmd.connectLoadInitFormats()
      github.com/minio/minio/cmd/prepare-storage.go:269 +0x14f0
  github.com/minio/minio/cmd.waitForFormatErasure()
      github.com/minio/minio/cmd/prepare-storage.go:294 +0x21d
...

Previous read at 0x0000079605a0 by goroutine 105:
  github.com/minio/minio/cmd.newContext()
      github.com/minio/minio/cmd/utils.go:817 +0x31e
  github.com/minio/minio/cmd.adminMiddleware.func1()
      github.com/minio/minio/cmd/admin-router.go:110 +0x96
  net/http.HandlerFunc.ServeHTTP()
      net/http/server.go:2136 +0x47
  github.com/minio/minio/cmd.setBucketForwardingMiddleware.func1()
      github.com/minio/minio/cmd/generic-handlers.go:460 +0xb1a
  net/http.HandlerFunc.ServeHTTP()
      net/http/server.go:2136 +0x47
...
```
This commit is contained in:
Klaus Post 2023-10-18 08:06:57 -07:00 committed by GitHub
parent 557df666fd
commit 7926df0b80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 75 additions and 68 deletions

View File

@ -1001,7 +1001,7 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) {
Message: hr.errBody, Message: hr.errBody,
Resource: r.URL.Path, Resource: r.URL.Path,
RequestID: w.Header().Get(xhttp.AmzRequestID), RequestID: w.Header().Get(xhttp.AmzRequestID),
HostID: globalDeploymentID, HostID: globalDeploymentID(),
}) })
} }
if !started { if !started {
@ -1982,7 +1982,7 @@ func getServerInfo(ctx context.Context, poolsInfoEnabled bool, r *http.Request)
Domain: domain, Domain: domain,
Region: globalSite.Region, Region: globalSite.Region,
SQSARN: globalEventNotifier.GetARNList(false), SQSARN: globalEventNotifier.GetARNList(false),
DeploymentID: globalDeploymentID, DeploymentID: globalDeploymentID(),
Buckets: buckets, Buckets: buckets,
Objects: objects, Objects: objects,
Versions: versions, Versions: versions,
@ -2392,7 +2392,7 @@ func (a adminAPIHandlers) HealthInfoHandler(w http.ResponseWriter, r *http.Reque
Version: madmin.HealthInfoVersion, Version: madmin.HealthInfoVersion,
Minio: madmin.MinioHealthInfo{ Minio: madmin.MinioHealthInfo{
Info: madmin.MinioInfo{ Info: madmin.MinioInfo{
DeploymentID: globalDeploymentID, DeploymentID: globalDeploymentID(),
}, },
}, },
} }
@ -2690,7 +2690,7 @@ func getClusterMetaInfo(ctx context.Context) []byte {
ci.Info.NoOfBuckets = dataUsageInfo.BucketsCount ci.Info.NoOfBuckets = dataUsageInfo.BucketsCount
ci.Info.NoOfObjects = dataUsageInfo.ObjectsTotalCount ci.Info.NoOfObjects = dataUsageInfo.ObjectsTotalCount
ci.DeploymentID = globalDeploymentID ci.DeploymentID = globalDeploymentID()
ci.ClusterName = fmt.Sprintf("%d-servers-%d-disks-%s", ci.Info.NoOfServers, ci.Info.NoOfDrives, ci.Info.MinioVersion) ci.ClusterName = fmt.Sprintf("%d-servers-%d-disks-%s", ci.Info.NoOfServers, ci.Info.NoOfDrives, ci.Info.MinioVersion)
select { select {

View File

@ -978,7 +978,7 @@ func writeCustomErrorResponseJSON(ctx context.Context, w http.ResponseWriter, er
BucketName: reqInfo.BucketName, BucketName: reqInfo.BucketName,
Key: reqInfo.ObjectName, Key: reqInfo.ObjectName,
RequestID: w.Header().Get(xhttp.AmzRequestID), RequestID: w.Header().Get(xhttp.AmzRequestID),
HostID: globalDeploymentID, HostID: globalDeploymentID(),
} }
encodedErrorResponse := encodeResponseJSON(errorResponse) encodedErrorResponse := encodeResponseJSON(errorResponse)
writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeJSON) writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeJSON)

View File

@ -444,7 +444,7 @@ func genTransitionObjName(bucket string) (string, error) {
return "", err return "", err
} }
us := u.String() us := u.String()
obj := fmt.Sprintf("%s/%s/%s/%s/%s", globalDeploymentID, bucket, us[0:2], us[2:4], us) obj := fmt.Sprintf("%s/%s/%s/%s/%s", globalDeploymentID(), bucket, us[0:2], us[2:4], us)
return obj, nil return obj, nil
} }

View File

@ -131,7 +131,7 @@ func performCallhome(ctx context.Context) {
Version: madmin.HealthInfoVersion, Version: madmin.HealthInfoVersion,
Minio: madmin.MinioHealthInfo{ Minio: madmin.MinioHealthInfo{
Info: madmin.MinioInfo{ Info: madmin.MinioInfo{
DeploymentID: globalDeploymentID, DeploymentID: globalDeploymentID(),
}, },
}, },
} }

View File

@ -122,8 +122,8 @@ func init() {
const consolePrefix = "CONSOLE_" const consolePrefix = "CONSOLE_"
func minioConfigToConsoleFeatures() { func minioConfigToConsoleFeatures() {
os.Setenv("CONSOLE_PBKDF_SALT", globalDeploymentID) os.Setenv("CONSOLE_PBKDF_SALT", globalDeploymentID())
os.Setenv("CONSOLE_PBKDF_PASSPHRASE", globalDeploymentID) os.Setenv("CONSOLE_PBKDF_PASSPHRASE", globalDeploymentID())
if globalMinioEndpoint != "" { if globalMinioEndpoint != "" {
os.Setenv("CONSOLE_MINIO_SERVER", globalMinioEndpoint) os.Setenv("CONSOLE_MINIO_SERVER", globalMinioEndpoint)
} else { } else {
@ -191,7 +191,7 @@ func buildOpenIDConsoleConfig() consoleoauth2.OpenIDPCfg {
DisplayName: cfg.DisplayName, DisplayName: cfg.DisplayName,
ClientID: cfg.ClientID, ClientID: cfg.ClientID,
ClientSecret: cfg.ClientSecret, ClientSecret: cfg.ClientSecret,
HMACSalt: globalDeploymentID, HMACSalt: globalDeploymentID(),
HMACPassphrase: cfg.ClientID, HMACPassphrase: cfg.ClientID,
Scopes: strings.Join(cfg.DiscoveryDoc.ScopesSupported, ","), Scopes: strings.Join(cfg.DiscoveryDoc.ScopesSupported, ","),
Userinfo: cfg.ClaimUserinfo, Userinfo: cfg.ClaimUserinfo,

View File

@ -1142,7 +1142,7 @@ func (er erasureObjects) HealObject(ctx context.Context, bucket, object, version
if reqInfo != nil { if reqInfo != nil {
newReqInfo = logger.NewReqInfo(reqInfo.RemoteHost, reqInfo.UserAgent, reqInfo.DeploymentID, reqInfo.RequestID, reqInfo.API, bucket, object) newReqInfo = logger.NewReqInfo(reqInfo.RemoteHost, reqInfo.UserAgent, reqInfo.DeploymentID, reqInfo.RequestID, reqInfo.API, bucket, object)
} else { } else {
newReqInfo = logger.NewReqInfo("", "", globalDeploymentID, "", "Heal", bucket, object) newReqInfo = logger.NewReqInfo("", "", globalDeploymentID(), "", "Heal", bucket, object)
} }
healCtx := logger.SetReqInfo(GlobalContext, newReqInfo) healCtx := logger.SetReqInfo(GlobalContext, newReqInfo)

View File

@ -320,7 +320,7 @@ func (er erasureObjects) ListMultipartUploads(ctx context.Context, bucket, objec
populatedUploadIds.Add(uploadID) populatedUploadIds.Add(uploadID)
uploads = append(uploads, MultipartInfo{ uploads = append(uploads, MultipartInfo{
Object: object, Object: object,
UploadID: base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf("%s.%s", globalDeploymentID, uploadID))), UploadID: base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf("%s.%s", globalDeploymentID(), uploadID))),
Initiated: fi.ModTime, Initiated: fi.ModTime,
}) })
} }
@ -481,7 +481,7 @@ func (er erasureObjects) newMultipartUpload(ctx context.Context, bucket string,
partsMetadata[index].Metadata = userDefined partsMetadata[index].Metadata = userDefined
} }
uploadUUID := mustGetUUID() uploadUUID := mustGetUUID()
uploadID := base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf("%s.%s", globalDeploymentID, uploadUUID))) uploadID := base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf("%s.%s", globalDeploymentID(), uploadUUID)))
uploadIDPath := er.getUploadIDDir(bucket, object, uploadUUID) uploadIDPath := er.getUploadIDDir(bucket, object, uploadUUID)
// Write updated `xl.meta` to all disks. // Write updated `xl.meta` to all disks.

View File

@ -223,7 +223,7 @@ func (args eventArgs) ToEvent(escape bool) event.Event {
} }
// Add deployment as part of response elements. // Add deployment as part of response elements.
respElements["x-minio-deployment-id"] = globalDeploymentID respElements["x-minio-deployment-id"] = globalDeploymentID()
if args.RespElements["content-length"] != "" { if args.RespElements["content-length"] != "" {
respElements["content-length"] = args.RespElements["content-length"] respElements["content-length"] = args.RespElements["content-length"]
} }

View File

@ -23,7 +23,6 @@ import (
"net/http" "net/http"
"os" "os"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/minio/console/restapi" "github.com/minio/console/restapi"
@ -35,6 +34,7 @@ import (
"github.com/minio/minio/internal/config" "github.com/minio/minio/internal/config"
"github.com/minio/minio/internal/handlers" "github.com/minio/minio/internal/handlers"
"github.com/minio/minio/internal/kms" "github.com/minio/minio/internal/kms"
"go.uber.org/atomic"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/minio/minio/internal/auth" "github.com/minio/minio/internal/auth"
@ -313,7 +313,14 @@ var (
globalAuthZPlugin *polplugin.AuthZPlugin globalAuthZPlugin *polplugin.AuthZPlugin
// Deployment ID - unique per deployment // Deployment ID - unique per deployment
globalDeploymentID string globalDeploymentIDPtr atomic.Pointer[string]
globalDeploymentID = func() string {
ptr := globalDeploymentIDPtr.Load()
if ptr == nil {
return ""
}
return *ptr
}
globalAllHealState *allHealState globalAllHealState *allHealState

View File

@ -245,7 +245,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r
Key: object, Key: object,
Resource: r.URL.Path, Resource: r.URL.Path,
RequestID: w.Header().Get(xhttp.AmzRequestID), RequestID: w.Header().Get(xhttp.AmzRequestID),
HostID: globalDeploymentID, HostID: globalDeploymentID(),
}) })
writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML) writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML)
} else { } else {
@ -264,7 +264,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r
Key: object, Key: object,
Resource: r.URL.Path, Resource: r.URL.Path,
RequestID: w.Header().Get(xhttp.AmzRequestID), RequestID: w.Header().Get(xhttp.AmzRequestID),
HostID: globalDeploymentID, HostID: globalDeploymentID(),
}) })
writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML) writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML)
} else { } else {
@ -3141,7 +3141,7 @@ func (api objectAPIHandlers) PostRestoreObjectHandler(w http.ResponseWriter, r *
Key: object, Key: object,
Resource: r.URL.Path, Resource: r.URL.Path,
RequestID: w.Header().Get(xhttp.AmzRequestID), RequestID: w.Header().Get(xhttp.AmzRequestID),
HostID: globalDeploymentID, HostID: globalDeploymentID(),
}) })
writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML) writeResponse(w, serr.HTTPStatusCode(), encodedErrorResponse, mimeXML)
} else { } else {

View File

@ -351,7 +351,7 @@ func siteNetperf(ctx context.Context, duration time.Duration) madmin.SiteNetPerf
for _, info := range clusterInfos.Sites { for _, info := range clusterInfos.Sites {
// skip self // skip self
if globalDeploymentID == info.DeploymentID { if globalDeploymentID() == info.DeploymentID {
continue continue
} }
info := info info := info

View File

@ -225,9 +225,9 @@ func connectLoadInitFormats(verboseLogging bool, firstDisk bool, endpoints Endpo
return nil, nil, err return nil, nil, err
} }
// Assign globalDeploymentID on first run for the // Assign globalDeploymentID() on first run for the
// minio server managing the first disk // minio server managing the first disk
globalDeploymentID = format.ID globalDeploymentIDPtr.Store(&format.ID)
return storageDisks, format, nil return storageDisks, format, nil
} }
@ -266,7 +266,7 @@ func connectLoadInitFormats(verboseLogging bool, firstDisk bool, endpoints Endpo
} }
} }
globalDeploymentID = format.ID globalDeploymentIDPtr.Store(&format.ID)
if err = formatErasureFixLocalDeploymentID(endpoints, storageDisks, format); err != nil { if err = formatErasureFixLocalDeploymentID(endpoints, storageDisks, format); err != nil {
logger.LogIf(GlobalContext, err) logger.LogIf(GlobalContext, err)

View File

@ -713,7 +713,7 @@ func serverMain(ctx *cli.Context) {
} }
}) })
xhttp.SetDeploymentID(globalDeploymentID) xhttp.SetDeploymentID(globalDeploymentID())
xhttp.SetMinIOVersion(Version) xhttp.SetMinIOVersion(Version)
for _, n := range globalNodes { for _, n := range globalNodes {
@ -721,7 +721,7 @@ func serverMain(ctx *cli.Context) {
if n.IsLocal { if n.IsLocal {
nodeName = globalLocalNodeName nodeName = globalLocalNodeName
} }
nodeNameSum := sha256.Sum256([]byte(nodeName + globalDeploymentID)) nodeNameSum := sha256.Sum256([]byte(nodeName + globalDeploymentID()))
globalNodeNamesHex[hex.EncodeToString(nodeNameSum[:])] = struct{}{} globalNodeNamesHex[hex.EncodeToString(nodeNameSum[:])] = struct{}{}
} }

View File

@ -110,7 +110,7 @@ func (sm *siteResyncMetrics) load(ctx context.Context, objAPI ObjectLayer) error
return nil return nil
} }
for _, peer := range info.Sites { for _, peer := range info.Sites {
if peer.DeploymentID == globalDeploymentID { if peer.DeploymentID == globalDeploymentID() {
continue continue
} }
rs, err := loadSiteResyncMetadata(ctx, objAPI, peer.DeploymentID) rs, err := loadSiteResyncMetadata(ctx, objAPI, peer.DeploymentID)

View File

@ -365,7 +365,7 @@ func (c *SiteReplicationSys) getSiteStatuses(ctx context.Context, sites ...madmi
PeerSite: v, PeerSite: v,
DeploymentID: info.DeploymentID, DeploymentID: info.DeploymentID,
Empty: len(buckets) == 0, Empty: len(buckets) == 0,
self: info.DeploymentID == globalDeploymentID, self: info.DeploymentID == globalDeploymentID(),
}) })
} }
return return
@ -410,7 +410,7 @@ func (c *SiteReplicationSys) AddPeerClusters(ctx context.Context, psites []madmi
} }
} }
if selfIdx == -1 { if selfIdx == -1 {
return madmin.ReplicateAddStatus{}, errSRBackendIssue(fmt.Errorf("global deployment ID %s mismatch, expected one of %s", globalDeploymentID, deploymentIDsSet)) return madmin.ReplicateAddStatus{}, errSRBackendIssue(fmt.Errorf("global deployment ID %s mismatch, expected one of %s", globalDeploymentID(), deploymentIDsSet))
} }
if !currDeploymentIDsSet.IsEmpty() { if !currDeploymentIDsSet.IsEmpty() {
// If current cluster is already SR enabled and no new site being added ,fail. // If current cluster is already SR enabled and no new site being added ,fail.
@ -569,7 +569,7 @@ func (c *SiteReplicationSys) AddPeerClusters(ctx context.Context, psites []madmi
func (c *SiteReplicationSys) PeerJoinReq(ctx context.Context, arg madmin.SRPeerJoinReq) error { func (c *SiteReplicationSys) PeerJoinReq(ctx context.Context, arg madmin.SRPeerJoinReq) error {
var ourName string var ourName string
for d, p := range arg.Peers { for d, p := range arg.Peers {
if d == globalDeploymentID { if d == globalDeploymentID() {
ourName = p.Name ourName = p.Name
break break
} }
@ -658,7 +658,7 @@ func (c *SiteReplicationSys) Netperf(ctx context.Context, duration time.Duration
for _, info := range infos.Sites { for _, info := range infos.Sites {
info := info info := info
// will call siteNetperf, means call others's adminAPISiteReplicationDevNull // will call siteNetperf, means call others's adminAPISiteReplicationDevNull
if globalDeploymentID == info.DeploymentID { if globalDeploymentID() == info.DeploymentID {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
@ -1090,7 +1090,7 @@ func (c *SiteReplicationSys) PeerBucketConfigureReplHandler(ctx context.Context,
defer c.RUnlock() defer c.RUnlock()
errMap := make(map[string]error, len(c.state.Peers)) errMap := make(map[string]error, len(c.state.Peers))
for d, peer := range c.state.Peers { for d, peer := range c.state.Peers {
if d == globalDeploymentID { if d == globalDeploymentID() {
continue continue
} }
errMap[d] = configurePeerFn(d, peer) errMap[d] = configurePeerFn(d, peer)
@ -2112,7 +2112,7 @@ func (c *SiteReplicationSys) concDo(selfActionFn func() error, peerActionFn func
for i := range depIDs { for i := range depIDs {
go func(i int) { go func(i int) {
defer wg.Done() defer wg.Done()
if depIDs[i] == globalDeploymentID { if depIDs[i] == globalDeploymentID() {
if selfActionFn != nil { if selfActionFn != nil {
errs[i] = selfActionFn() errs[i] = selfActionFn()
} }
@ -2193,11 +2193,11 @@ func (c *SiteReplicationSys) RemovePeerCluster(ctx context.Context, objectAPI Ob
for _, v := range info.Sites { for _, v := range info.Sites {
wg.Add(1) wg.Add(1)
if v.DeploymentID == globalDeploymentID { if v.DeploymentID == globalDeploymentID() {
go func() { go func() {
defer wg.Done() defer wg.Done()
err := c.RemoveRemoteTargetsForEndpoint(ctx, objectAPI, rmvEndpoints, false) err := c.RemoveRemoteTargetsForEndpoint(ctx, objectAPI, rmvEndpoints, false)
errs[globalDeploymentID] = err errs[globalDeploymentID()] = err
}() }()
continue continue
} }
@ -2209,7 +2209,7 @@ func (c *SiteReplicationSys) RemovePeerCluster(ctx context.Context, objectAPI Ob
return return
} }
// set the requesting site's deploymentID for verification of peer request // set the requesting site's deploymentID for verification of peer request
rreq.RequestingDepID = globalDeploymentID rreq.RequestingDepID = globalDeploymentID()
if _, err = admClient.SRPeerRemove(ctx, rreq); err != nil { if _, err = admClient.SRPeerRemove(ctx, rreq); err != nil {
if errors.Is(err, errMissingSRConfig) { if errors.Is(err, errMissingSRConfig) {
// ignore if peer is already removed. // ignore if peer is already removed.
@ -2223,7 +2223,7 @@ func (c *SiteReplicationSys) RemovePeerCluster(ctx context.Context, objectAPI Ob
wg.Wait() wg.Wait()
errdID := "" errdID := ""
selfTgtsDeleted := errs[globalDeploymentID] == nil // true if all remote targets and replication config cleared successfully on local cluster selfTgtsDeleted := errs[globalDeploymentID()] == nil // true if all remote targets and replication config cleared successfully on local cluster
for dID, err := range errs { for dID, err := range errs {
if err != nil { if err != nil {
@ -2311,7 +2311,7 @@ func (c *SiteReplicationSys) InternalRemoveReq(ctx context.Context, objectAPI Ob
for _, p := range c.state.Peers { for _, p := range c.state.Peers {
peerMap[p.Name] = p peerMap[p.Name] = p
if p.DeploymentID == globalDeploymentID { if p.DeploymentID == globalDeploymentID() {
ourName = p.Name ourName = p.Name
} }
updatedPeers[p.DeploymentID] = p updatedPeers[p.DeploymentID] = p
@ -2327,7 +2327,7 @@ func (c *SiteReplicationSys) InternalRemoveReq(ctx context.Context, objectAPI Ob
if !ok { if !ok {
return errMissingSRConfig return errMissingSRConfig
} }
if info.DeploymentID == globalDeploymentID { if info.DeploymentID == globalDeploymentID() {
unlinkSelf = true unlinkSelf = true
continue continue
} }
@ -2608,7 +2608,7 @@ func (c *SiteReplicationSys) siteReplicationStatus(ctx context.Context, objAPI O
if err != nil { if err != nil {
return err return err
} }
sris[depIdx[globalDeploymentID]] = srInfo sris[depIdx[globalDeploymentID()]] = srInfo
return nil return nil
}, },
func(deploymentID string, p madmin.PeerInfo) error { func(deploymentID string, p madmin.PeerInfo) error {
@ -3354,7 +3354,7 @@ func (c *SiteReplicationSys) SiteReplicationMetaInfo(ctx context.Context, objAPI
if !c.enabled { if !c.enabled {
return info, nil return info, nil
} }
info.DeploymentID = globalDeploymentID info.DeploymentID = globalDeploymentID()
if opts.Buckets || opts.Entity == madmin.SRBucketEntity { if opts.Buckets || opts.Entity == madmin.SRBucketEntity {
var ( var (
buckets []BucketInfo buckets []BucketInfo
@ -3611,7 +3611,7 @@ func (c *SiteReplicationSys) EditPeerCluster(ctx context.Context, peer madmin.Pe
admClient *madmin.AdminClient admClient *madmin.AdminClient
) )
if globalDeploymentID == peer.DeploymentID && !peer.SyncState.Empty() && !peer.DefaultBandwidth.IsSet { if globalDeploymentID() == peer.DeploymentID && !peer.SyncState.Empty() && !peer.DefaultBandwidth.IsSet {
return madmin.ReplicateEditStatus{}, errSRInvalidRequest(fmt.Errorf("a peer cluster, rather than the local cluster (endpoint=%s, deployment-id=%s) needs to be specified while setting a 'sync' replication mode", peer.Endpoint, peer.DeploymentID)) return madmin.ReplicateEditStatus{}, errSRInvalidRequest(fmt.Errorf("a peer cluster, rather than the local cluster (endpoint=%s, deployment-id=%s) needs to be specified while setting a 'sync' replication mode", peer.Endpoint, peer.DeploymentID))
} }
@ -3665,7 +3665,7 @@ func (c *SiteReplicationSys) EditPeerCluster(ctx context.Context, peer madmin.Pe
var wg sync.WaitGroup var wg sync.WaitGroup
for dID, v := range state.Peers { for dID, v := range state.Peers {
if v.DeploymentID == globalDeploymentID { if v.DeploymentID == globalDeploymentID() {
continue continue
} }
wg.Add(1) wg.Add(1)
@ -3792,7 +3792,7 @@ func (c *SiteReplicationSys) PeerEditReq(ctx context.Context, arg madmin.PeerInf
} }
c.state.Peers[arg.DeploymentID] = p c.state.Peers[arg.DeploymentID] = p
} }
if p.DeploymentID == globalDeploymentID { if p.DeploymentID == globalDeploymentID() {
ourName = p.Name ourName = p.Name
} }
} }
@ -3993,7 +3993,7 @@ func (c *SiteReplicationSys) healTagMetadata(ctx context.Context, objAPI ObjectL
if isBucketMetadataEqual(latestTaggingConfig, bStatus.meta.Tags) { if isBucketMetadataEqual(latestTaggingConfig, bStatus.meta.Tags) {
continue continue
} }
if dID == globalDeploymentID { if dID == globalDeploymentID() {
if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketTaggingConfig, latestTaggingConfigBytes); err != nil { if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketTaggingConfig, latestTaggingConfigBytes); err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to heal tagging metadata from peer site %s : %w", latestPeerName, err)) logger.LogIf(ctx, fmt.Errorf("Unable to heal tagging metadata from peer site %s : %w", latestPeerName, err))
} }
@ -4057,7 +4057,7 @@ func (c *SiteReplicationSys) healBucketPolicies(ctx context.Context, objAPI Obje
if strings.EqualFold(string(latestIAMPolicy), string(bStatus.meta.Policy)) { if strings.EqualFold(string(latestIAMPolicy), string(bStatus.meta.Policy)) {
continue continue
} }
if dID == globalDeploymentID { if dID == globalDeploymentID() {
if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketPolicyConfig, latestIAMPolicy); err != nil { if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketPolicyConfig, latestIAMPolicy); err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to heal bucket policy metadata from peer site %s : %w", latestPeerName, err)) logger.LogIf(ctx, fmt.Errorf("Unable to heal bucket policy metadata from peer site %s : %w", latestPeerName, err))
} }
@ -4132,7 +4132,7 @@ func (c *SiteReplicationSys) healBucketQuotaConfig(ctx context.Context, objAPI O
if isBucketMetadataEqual(latestQuotaConfig, bStatus.meta.QuotaConfig) { if isBucketMetadataEqual(latestQuotaConfig, bStatus.meta.QuotaConfig) {
continue continue
} }
if dID == globalDeploymentID { if dID == globalDeploymentID() {
if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketQuotaConfigFile, latestQuotaConfigBytes); err != nil { if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketQuotaConfigFile, latestQuotaConfigBytes); err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to heal quota metadata from peer site %s : %w", latestPeerName, err)) logger.LogIf(ctx, fmt.Errorf("Unable to heal quota metadata from peer site %s : %w", latestPeerName, err))
} }
@ -4207,7 +4207,7 @@ func (c *SiteReplicationSys) healVersioningMetadata(ctx context.Context, objAPI
if isBucketMetadataEqual(latestVersioningConfig, bStatus.meta.Versioning) { if isBucketMetadataEqual(latestVersioningConfig, bStatus.meta.Versioning) {
continue continue
} }
if dID == globalDeploymentID { if dID == globalDeploymentID() {
if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketVersioningConfig, latestVersioningConfigBytes); err != nil { if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketVersioningConfig, latestVersioningConfigBytes); err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to heal versioning metadata from peer site %s : %w", latestPeerName, err)) logger.LogIf(ctx, fmt.Errorf("Unable to heal versioning metadata from peer site %s : %w", latestPeerName, err))
} }
@ -4282,7 +4282,7 @@ func (c *SiteReplicationSys) healSSEMetadata(ctx context.Context, objAPI ObjectL
if isBucketMetadataEqual(latestSSEConfig, bStatus.meta.SSEConfig) { if isBucketMetadataEqual(latestSSEConfig, bStatus.meta.SSEConfig) {
continue continue
} }
if dID == globalDeploymentID { if dID == globalDeploymentID() {
if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketSSEConfig, latestSSEConfigBytes); err != nil { if _, err := globalBucketMetadataSys.Update(ctx, bucket, bucketSSEConfig, latestSSEConfigBytes); err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to heal sse metadata from peer site %s : %w", latestPeerName, err)) logger.LogIf(ctx, fmt.Errorf("Unable to heal sse metadata from peer site %s : %w", latestPeerName, err))
} }
@ -4357,7 +4357,7 @@ func (c *SiteReplicationSys) healOLockConfigMetadata(ctx context.Context, objAPI
if isBucketMetadataEqual(latestObjLockConfig, bStatus.meta.ObjectLockConfig) { if isBucketMetadataEqual(latestObjLockConfig, bStatus.meta.ObjectLockConfig) {
continue continue
} }
if dID == globalDeploymentID { if dID == globalDeploymentID() {
if _, err := globalBucketMetadataSys.Update(ctx, bucket, objectLockConfig, latestObjLockConfigBytes); err != nil { if _, err := globalBucketMetadataSys.Update(ctx, bucket, objectLockConfig, latestObjLockConfigBytes); err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to heal objectlock config metadata from peer site %s : %w", latestPeerName, err)) logger.LogIf(ctx, fmt.Errorf("Unable to heal objectlock config metadata from peer site %s : %w", latestPeerName, err))
} }
@ -4445,7 +4445,7 @@ func (c *SiteReplicationSys) healBucket(ctx context.Context, objAPI ObjectLayer,
bStatus := info.BucketStats[bucket][latestID].meta bStatus := info.BucketStats[bucket][latestID].meta
isMakeBucket := len(missingB) > 0 isMakeBucket := len(missingB) > 0
deleteOp := NoOp deleteOp := NoOp
if latestID != globalDeploymentID { if latestID != globalDeploymentID() {
return nil return nil
} }
if lastUpdate.Equal(bStatus.DeletedAt) { if lastUpdate.Equal(bStatus.DeletedAt) {
@ -4479,7 +4479,7 @@ func (c *SiteReplicationSys) healBucket(ctx context.Context, objAPI ObjectLayer,
} }
for _, dID := range missingB { for _, dID := range missingB {
peerName := info.Sites[dID].Name peerName := info.Sites[dID].Name
if dID == globalDeploymentID { if dID == globalDeploymentID() {
err := c.PeerBucketMakeWithVersioningHandler(ctx, bucket, opts) err := c.PeerBucketMakeWithVersioningHandler(ctx, bucket, opts)
if err != nil { if err != nil {
return c.annotateErr(makeBucketWithVersion, fmt.Errorf("error healing bucket for site replication %w from %s -> %s", return c.annotateErr(makeBucketWithVersion, fmt.Errorf("error healing bucket for site replication %w from %s -> %s",
@ -4512,7 +4512,7 @@ func (c *SiteReplicationSys) healBucket(ctx context.Context, objAPI ObjectLayer,
if deleteOp == Purge { if deleteOp == Purge {
for _, dID := range missingB { for _, dID := range missingB {
peerName := info.Sites[dID].Name peerName := info.Sites[dID].Name
if dID == globalDeploymentID { if dID == globalDeploymentID() {
c.purgeDeletedBucket(ctx, objAPI, bucket) c.purgeDeletedBucket(ctx, objAPI, bucket)
} else { } else {
admClient, err := c.getAdminClient(ctx, dID) admClient, err := c.getAdminClient(ctx, dID)
@ -4529,7 +4529,7 @@ func (c *SiteReplicationSys) healBucket(ctx context.Context, objAPI ObjectLayer,
if deleteOp == MarkDelete { if deleteOp == MarkDelete {
for _, dID := range withB { for _, dID := range withB {
peerName := info.Sites[dID].Name peerName := info.Sites[dID].Name
if dID == globalDeploymentID { if dID == globalDeploymentID() {
err := c.PeerBucketDeleteHandler(ctx, bucket, DeleteBucketOptions{ err := c.PeerBucketDeleteHandler(ctx, bucket, DeleteBucketOptions{
Force: true, Force: true,
}) })
@ -4685,14 +4685,14 @@ func (c *SiteReplicationSys) healPolicies(ctx context.Context, objAPI ObjectLaye
latestPolicyStat = ss latestPolicyStat = ss
} }
} }
if latestID != globalDeploymentID { if latestID != globalDeploymentID() {
// heal only from the site with latest info. // heal only from the site with latest info.
return nil return nil
} }
latestPeerName = info.Sites[latestID].Name latestPeerName = info.Sites[latestID].Name
// heal policy of peers if peer does not have it. // heal policy of peers if peer does not have it.
for dID, pStatus := range ps { for dID, pStatus := range ps {
if dID == globalDeploymentID { if dID == globalDeploymentID() {
continue continue
} }
if !pStatus.PolicyMismatch && pStatus.HasPolicy { if !pStatus.PolicyMismatch && pStatus.HasPolicy {
@ -4739,14 +4739,14 @@ func (c *SiteReplicationSys) healUserPolicies(ctx context.Context, objAPI Object
latestUserStat = ss latestUserStat = ss
} }
} }
if latestID != globalDeploymentID { if latestID != globalDeploymentID() {
// heal only from the site with latest info. // heal only from the site with latest info.
return nil return nil
} }
latestPeerName = info.Sites[latestID].Name latestPeerName = info.Sites[latestID].Name
// heal policy of peers if peer does not have it. // heal policy of peers if peer does not have it.
for dID, pStatus := range us { for dID, pStatus := range us {
if dID == globalDeploymentID { if dID == globalDeploymentID() {
continue continue
} }
if !pStatus.PolicyMismatch && pStatus.HasPolicyMapping { if !pStatus.PolicyMismatch && pStatus.HasPolicyMapping {
@ -4800,14 +4800,14 @@ func (c *SiteReplicationSys) healGroupPolicies(ctx context.Context, objAPI Objec
latestGroupStat = ss latestGroupStat = ss
} }
} }
if latestID != globalDeploymentID { if latestID != globalDeploymentID() {
// heal only from the site with latest info. // heal only from the site with latest info.
return nil return nil
} }
latestPeerName = info.Sites[latestID].Name latestPeerName = info.Sites[latestID].Name
// heal policy of peers if peer does not have it. // heal policy of peers if peer does not have it.
for dID, pStatus := range gs { for dID, pStatus := range gs {
if dID == globalDeploymentID { if dID == globalDeploymentID() {
continue continue
} }
if !pStatus.PolicyMismatch && pStatus.HasPolicyMapping { if !pStatus.PolicyMismatch && pStatus.HasPolicyMapping {
@ -4862,13 +4862,13 @@ func (c *SiteReplicationSys) healUsers(ctx context.Context, objAPI ObjectLayer,
latestUserStat = ss latestUserStat = ss
} }
} }
if latestID != globalDeploymentID { if latestID != globalDeploymentID() {
// heal only from the site with latest info. // heal only from the site with latest info.
return nil return nil
} }
latestPeerName = info.Sites[latestID].Name latestPeerName = info.Sites[latestID].Name
for dID, uStatus := range us { for dID, uStatus := range us {
if dID == globalDeploymentID { if dID == globalDeploymentID() {
continue continue
} }
if !uStatus.UserInfoMismatch { if !uStatus.UserInfoMismatch {
@ -5008,13 +5008,13 @@ func (c *SiteReplicationSys) healGroups(ctx context.Context, objAPI ObjectLayer,
latestGroupStat = ss latestGroupStat = ss
} }
} }
if latestID != globalDeploymentID { if latestID != globalDeploymentID() {
// heal only from the site with latest info. // heal only from the site with latest info.
return nil return nil
} }
latestPeerName = info.Sites[latestID].Name latestPeerName = info.Sites[latestID].Name
for dID, gStatus := range gs { for dID, gStatus := range gs {
if dID == globalDeploymentID { if dID == globalDeploymentID() {
continue continue
} }
if !gStatus.GroupDescMismatch { if !gStatus.GroupDescMismatch {
@ -5113,7 +5113,7 @@ func (c *SiteReplicationSys) getPeerForUpload(deplID string) (pi srPeerInfo, loc
PeerInfo: site, PeerInfo: site,
EndpointURL: ep, EndpointURL: ep,
} }
return pi, site.DeploymentID == globalDeploymentID return pi, site.DeploymentID == globalDeploymentID()
} }
} }
return pi, true return pi, true
@ -5130,7 +5130,7 @@ func (c *SiteReplicationSys) startResync(ctx context.Context, objAPI ObjectLayer
return res, errSRObjectLayerNotReady return res, errSRObjectLayerNotReady
} }
if peer.DeploymentID == globalDeploymentID { if peer.DeploymentID == globalDeploymentID() {
return res, errSRResyncToSelf return res, errSRResyncToSelf
} }
if _, ok := c.state.Peers[peer.DeploymentID]; !ok { if _, ok := c.state.Peers[peer.DeploymentID]; !ok {
@ -5244,7 +5244,7 @@ func (c *SiteReplicationSys) cancelResync(ctx context.Context, objAPI ObjectLaye
if objAPI == nil { if objAPI == nil {
return res, errSRObjectLayerNotReady return res, errSRObjectLayerNotReady
} }
if peer.DeploymentID == globalDeploymentID { if peer.DeploymentID == globalDeploymentID() {
return res, errSRResyncToSelf return res, errSRResyncToSelf
} }
if _, ok := c.state.Peers[peer.DeploymentID]; !ok { if _, ok := c.state.Peers[peer.DeploymentID]; !ok {

View File

@ -814,7 +814,7 @@ func newContext(r *http.Request, w http.ResponseWriter, api string) context.Cont
bucket := vars["bucket"] bucket := vars["bucket"]
object := likelyUnescapeGeneric(vars["object"], url.PathUnescape) object := likelyUnescapeGeneric(vars["object"], url.PathUnescape)
reqInfo := &logger.ReqInfo{ reqInfo := &logger.ReqInfo{
DeploymentID: globalDeploymentID, DeploymentID: globalDeploymentID(),
RequestID: reqID, RequestID: reqID,
RemoteHost: handlers.GetSourceIP(r), RemoteHost: handlers.GetSourceIP(r),
Host: getHostName(r), Host: getHostName(r),
@ -1048,7 +1048,7 @@ func auditLogInternal(ctx context.Context, opts AuditLogOptions) {
if len(logger.AuditTargets()) == 0 { if len(logger.AuditTargets()) == 0 {
return return
} }
entry := audit.NewEntry(globalDeploymentID) entry := audit.NewEntry(globalDeploymentID())
entry.Trigger = opts.Event entry.Trigger = opts.Event
entry.Event = opts.Event entry.Event = opts.Event
entry.Error = opts.Error entry.Error = opts.Error