From 8fb3f683098c5be775a847664683cc91e7432df7 Mon Sep 17 00:00:00 2001 From: Shubhendu Ram Tripathi Date: Fri, 3 Nov 2023 16:30:04 +0530 Subject: [PATCH] Support replication of site replication state changes While few remote sites are down, any changes to the site replication state e.g. `ReplicateILMExpiry` flag should get replicated to site when it's back online. This would be done exactly before healing any ILM rules changes during remote sites were down, so that these flags are taken in consideration. Signed-off-by: Shubhendu Ram Tripathi --- cluster-commands.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/cluster-commands.go b/cluster-commands.go index c6fe435..d461dc5 100644 --- a/cluster-commands.go +++ b/cluster-commands.go @@ -117,7 +117,6 @@ type SiteReplicationInfo struct { Name string `json:"name,omitempty"` Sites []PeerInfo `json:"sites,omitempty"` ServiceAccountAccessKey string `json:"serviceAccountAccessKey,omitempty"` - ReplicateILMExpiry bool `json:"replicate-ilm-expiry"` } // SiteReplicationInfo - returns cluster replication information. @@ -155,7 +154,7 @@ type SRPeerJoinReq struct { SvcAcctSecretKey string `json:"svcAcctSecretKey"` SvcAcctParent string `json:"svcAcctParent"` Peers map[string]PeerInfo `json:"peers"` - ReplicateILMExpiry bool `json:"replicate-ilm-expiry"` + UpdatedAt time.Time `json:"updatedAt"` } // PeerInfo - contains some properties of a cluster peer. @@ -983,6 +982,36 @@ func (adm *AdminClient) SRPeerEdit(ctx context.Context, pi PeerInfo) error { return nil } +// SRStateEdit - used only by minio server to update peer state +// for a server already in the site replication setup +func (adm *AdminClient) SRStateEdit(ctx context.Context, state SRStateEditReq) error { + b, err := json.Marshal(state) + if err != nil { + return err + } + + q := make(url.Values) + q.Set("api-version", SiteReplAPIVersion) + + reqData := requestData{ + relPath: adminAPIPrefix + "/site-replication/state/edit", + content: b, + queryValues: q, + } + + resp, err := adm.executeMethod(ctx, http.MethodPut, reqData) + defer closeResponse(resp) + if err != nil { + return err + } + + if resp.StatusCode != http.StatusOK { + return httpRespToErrorResponse(resp) + } + + return nil +} + // SiteReplicationRemove - unlinks a site from site replication func (adm *AdminClient) SiteReplicationRemove(ctx context.Context, removeReq SRRemoveReq) (st ReplicateRemoveStatus, err error) { rmvBytes, err := json.Marshal(removeReq) @@ -1053,6 +1082,12 @@ type SRRemoveReq struct { RemoveAll bool `json:"all"` // true if all sites are to be removed. } +// SRStateEditReq - arg body for SRStateEditReq +type SRStateEditReq struct { + Peers map[string]PeerInfo `json:"peers"` + UpdatedAt time.Time `json:"updatedAt"` +} + const ( ReplicateRemoveStatusSuccess = "Requested site(s) were removed from cluster replication successfully." ReplicateRemoveStatusPartial = "Some site(s) could not be removed from cluster replication configuration."