tier: Add force param to force tiering removal (#20355)

Currently, it is not possible to remove a tier if it is not accessible
or contains some data, add a force flag to make the removal successful
in that case.
This commit is contained in:
Anis Eleuch
2024-09-12 21:44:05 +01:00
committed by GitHub
parent 398ffb1136
commit e47d787adb
4 changed files with 13 additions and 9 deletions

View File

@@ -198,12 +198,14 @@ func (api adminAPIHandlers) RemoveTierHandler(w http.ResponseWriter, r *http.Req
vars := mux.Vars(r)
tier := vars["tier"]
force := r.Form.Get("force") == "true"
if err := globalTierConfigMgr.Reload(ctx, objAPI); err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}
if err := globalTierConfigMgr.Remove(ctx, tier); err != nil {
if err := globalTierConfigMgr.Remove(ctx, tier, force); err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}

View File

@@ -248,7 +248,7 @@ func (config *TierConfigMgr) Add(ctx context.Context, tier madmin.TierConfig, ig
}
// Remove removes tier if it is empty.
func (config *TierConfigMgr) Remove(ctx context.Context, tier string) error {
func (config *TierConfigMgr) Remove(ctx context.Context, tier string, force bool) error {
d, err := config.getDriver(ctx, tier)
if err != nil {
if errors.Is(err, errTierNotFound) {
@@ -256,10 +256,12 @@ func (config *TierConfigMgr) Remove(ctx context.Context, tier string) error {
}
return err
}
if inuse, err := d.InUse(ctx); err != nil {
return err
} else if inuse {
return errTierBackendNotEmpty
if !force {
if inuse, err := d.InUse(ctx); err != nil {
return err
} else if inuse {
return errTierBackendNotEmpty
}
}
config.Lock()
delete(config.Tiers, tier)