From 0e693e0284def47f8a86962fa2d7fa55965e0161 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Tue, 24 Jan 2017 21:41:05 +0530 Subject: [PATCH] Add dry-run query param for HealFormat API (#3618) --- cmd/admin-handlers.go | 24 +++++++++++++++++------- pkg/madmin/API.md | 11 +++++++++-- pkg/madmin/examples/heal-format.go | 12 ++++++++++-- pkg/madmin/heal-commands.go | 9 ++++++--- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 2639d7c3b..b83f49652 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -398,7 +398,7 @@ func (adminAPI adminAPIHandlers) ListBucketsHealHandler(w http.ResponseWriter, r writeSuccessResponseXML(w, encodeResponse(listResponse)) } -// HealBucketHandler - POST /?heal&bucket=mybucket +// HealBucketHandler - POST /?heal&bucket=mybucket&dry-run // - x-minio-operation = bucket // - bucket is mandatory query parameter // Heal a given bucket, if present. @@ -425,7 +425,7 @@ func (adminAPI adminAPIHandlers) HealBucketHandler(w http.ResponseWriter, r *htt return } - // if dry-run=yes, then only perform validations and return success. + // if dry-run is present in query-params, then only perform validations and return success. if isDryRun(vars) { writeSuccessResponseHeadersOnly(w) return @@ -442,15 +442,16 @@ func (adminAPI adminAPIHandlers) HealBucketHandler(w http.ResponseWriter, r *htt writeSuccessResponseHeadersOnly(w) } -// isDryRun - returns true if dry-run query param was set to yes and false otherwise. +// isDryRun - returns true if dry-run query param was set and false otherwise. +// otherwise. func isDryRun(qval url.Values) bool { - if dryRun := qval.Get(string(mgmtDryRun)); dryRun == "yes" { + if _, dryRun := qval[string(mgmtDryRun)]; dryRun { return true } return false } -// HealObjectHandler - POST /?heal&bucket=mybucket&object=myobject +// HealObjectHandler - POST /?heal&bucket=mybucket&object=myobject&dry-run // - x-minio-operation = object // - bucket and object are both mandatory query parameters // Heal a given object, if present. @@ -485,7 +486,8 @@ func (adminAPI adminAPIHandlers) HealObjectHandler(w http.ResponseWriter, r *htt return } - // if dry-run=yes, then only perform validations and return success. + // if dry-run is set in query params then perform validations + // and return success. if isDryRun(vars) { writeSuccessResponseHeadersOnly(w) return @@ -501,7 +503,7 @@ func (adminAPI adminAPIHandlers) HealObjectHandler(w http.ResponseWriter, r *htt writeSuccessResponseHeadersOnly(w) } -// HealFormatHandler - POST /?heal +// HealFormatHandler - POST /?heal&dry-run // - x-minio-operation = format // - bucket and object are both mandatory query parameters // Heal a given object, if present. @@ -528,6 +530,14 @@ func (adminAPI adminAPIHandlers) HealFormatHandler(w http.ResponseWriter, r *htt return } + // if dry-run is set in query-params, return success as + // validations are successful so far. + vars := r.URL.Query() + if isDryRun(vars) { + writeSuccessResponseHeadersOnly(w) + return + } + // Create a new set of storage instances to heal format.json. bootstrapDisks, err := initStorageDisks(globalEndpoints) if err != nil { diff --git a/pkg/madmin/API.md b/pkg/madmin/API.md index 420f20984..5d588db51 100644 --- a/pkg/madmin/API.md +++ b/pkg/madmin/API.md @@ -251,13 +251,20 @@ __Example__ ``` -### HealFormat() error +### HealFormat(isDryRun bool) error Heal storage format on available disks. This is used when disks were replaced or were found with missing format. This is supported only for erasure-coded backend. __Example__ ``` go - err := madmClnt.HealFormat() + isDryRun := true + err := madmClnt.HealFormat(isDryRun) + if err != nil { + log.Fatalln(err) + } + + isDryRun = false + err = madmClnt.HealFormat(isDryRun) if err != nil { log.Fatalln(err) } diff --git a/pkg/madmin/examples/heal-format.go b/pkg/madmin/examples/heal-format.go index 4b915747d..fb0484beb 100644 --- a/pkg/madmin/examples/heal-format.go +++ b/pkg/madmin/examples/heal-format.go @@ -39,8 +39,16 @@ func main() { log.Fatalln(err) } - // Heal storage format on available disks. - err = madmClnt.HealFormat() + // Attempt healing format in dry-run mode. + isDryRun := true + err = madmClnt.HealFormat(isDryRun) + if err != nil { + log.Fatalln(err) + } + + // Perform actual healing of format. + isDryRun = false + err = madmClnt.HealFormat(isDryRun) if err != nil { log.Fatalln(err) } diff --git a/pkg/madmin/heal-commands.go b/pkg/madmin/heal-commands.go index ba6d6fa12..34128345f 100644 --- a/pkg/madmin/heal-commands.go +++ b/pkg/madmin/heal-commands.go @@ -344,7 +344,7 @@ func (adm *AdminClient) HealBucket(bucket string, dryrun bool) error { queryVal.Set("heal", "") queryVal.Set(string(healBucket), bucket) if dryrun { - queryVal.Set(string(healDryRun), "yes") + queryVal.Set(string(healDryRun), "") } hdrs := make(http.Header) @@ -378,7 +378,7 @@ func (adm *AdminClient) HealObject(bucket, object string, dryrun bool) error { queryVal.Set(string(healBucket), bucket) queryVal.Set(string(healObject), object) if dryrun { - queryVal.Set(string(healDryRun), "yes") + queryVal.Set(string(healDryRun), "") } hdrs := make(http.Header) @@ -405,9 +405,12 @@ func (adm *AdminClient) HealObject(bucket, object string, dryrun bool) error { } // HealFormat - heal storage format on available disks. -func (adm *AdminClient) HealFormat() error { +func (adm *AdminClient) HealFormat(dryrun bool) error { queryVal := url.Values{} queryVal.Set("heal", "") + if dryrun { + queryVal.Set(string(healDryRun), "") + } // Set x-minio-operation to format. hdrs := make(http.Header)