site replication: clear config if remove --all specified (#15716)

This commit is contained in:
Poorna 2022-09-20 14:32:23 -07:00 committed by GitHub
parent c7dcbfd6c1
commit aec2aa3497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -239,7 +239,7 @@ func (c *SiteReplicationSys) loadFromDisk(ctx context.Context, objAPI ObjectLaye
c.Lock() c.Lock()
defer c.Unlock() defer c.Unlock()
c.state = srState(sdata.SRState) c.state = srState(sdata.SRState)
c.enabled = true c.enabled = len(c.state.Peers) != 0
return nil return nil
} }
@ -273,6 +273,27 @@ func (c *SiteReplicationSys) saveToDisk(ctx context.Context, state srState) erro
return nil return nil
} }
func (c *SiteReplicationSys) removeFromDisk(ctx context.Context) error {
objAPI := newObjectLayerFn()
if objAPI == nil {
return errServerNotInitialized
}
if err := deleteConfig(ctx, objAPI, getSRStateFilePath()); err != nil {
return err
}
for _, err := range globalNotificationSys.ReloadSiteReplicationConfig(ctx) {
logger.LogIf(ctx, err)
}
c.Lock()
defer c.Unlock()
c.state = srState{}
c.enabled = false
return nil
}
const ( const (
// Access key of service account used for perform cluster-replication // Access key of service account used for perform cluster-replication
// operations. // operations.
@ -2060,14 +2081,40 @@ func (c *SiteReplicationSys) RemovePeerCluster(ctx context.Context, objectAPI Ob
} }
wg.Wait() wg.Wait()
errdID := ""
for dID, err := range errs { for dID, err := range errs {
if err != nil { if err != nil {
return madmin.ReplicateRemoveStatus{ if !rreq.RemoveAll {
ErrDetail: err.Error(), return madmin.ReplicateRemoveStatus{
Status: madmin.ReplicateRemoveStatusPartial, ErrDetail: err.Error(),
}, errSRPeerResp(fmt.Errorf("unable to update peer %s: %w", c.state.Peers[dID].Name, err)) Status: madmin.ReplicateRemoveStatusPartial,
}, errSRPeerResp(fmt.Errorf("unable to update peer %s: %w", c.state.Peers[dID].Name, err))
}
errdID = dID
} }
} }
// force local config to be cleared even if peers failed since the remote targets are deleted
// by now from the replication config and user intended to forcibly clear all site replication
if rreq.RemoveAll {
if err = c.removeFromDisk(ctx); err != nil {
return madmin.ReplicateRemoveStatus{
Status: madmin.ReplicateRemoveStatusPartial,
ErrDetail: fmt.Sprintf("unable to remove cluster-replication state on local: %v", err),
}, nil
}
if errdID != "" {
err := errs[errdID]
return madmin.ReplicateRemoveStatus{
Status: madmin.ReplicateRemoveStatusPartial,
ErrDetail: err.Error(),
}, nil
}
return madmin.ReplicateRemoveStatus{
Status: madmin.ReplicateRemoveStatusSuccess,
}, nil
}
// Update cluster state // Update cluster state
var state srState var state srState
if len(updatedPeers) > 1 { if len(updatedPeers) > 1 {