admin heal: Support for uploads healing (#2076)
mc admin heal supports --incomplete flag to list and heal uploads.
This commit is contained in:
committed by
Harshavardhana
parent
29920f8c9c
commit
7c7969ed55
+56
-16
@@ -35,6 +35,10 @@ var (
|
||||
Name: "recursive, r",
|
||||
Usage: "List recursively.",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "incomplete, I",
|
||||
Usage: "List incomplete uploads",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -60,20 +64,36 @@ EXAMPLES:
|
||||
2. Recursively list objects than need to be healed.
|
||||
$ {{.HelpName}} --recursive play/
|
||||
|
||||
3. Recursively list incomplete uploads than need to be healed.
|
||||
$ {{.HelpName}} --incomplete --recursive play/
|
||||
|
||||
`,
|
||||
}
|
||||
|
||||
// healListMessage container to hold heal information.
|
||||
type healListMessage struct {
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
Object madmin.ObjectInfo `json:"object"`
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
Object *madmin.ObjectInfo `json:"object"`
|
||||
Upload *madmin.UploadInfo `json:"upload"`
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u healListMessage) String() string {
|
||||
msg := fmt.Sprintf("Object: %s/%s, ", u.Bucket, u.Object.Key)
|
||||
switch u.Object.HealObjectInfo.Status {
|
||||
msg := ""
|
||||
var healStatus madmin.HealStatus
|
||||
|
||||
// Check if we have object heal information
|
||||
if u.Object != nil {
|
||||
msg += fmt.Sprintf("Object: %s/%s, ", u.Bucket, u.Object.Key)
|
||||
healStatus = u.Object.HealObjectInfo.Status
|
||||
} else {
|
||||
msg += fmt.Sprintf("Upload: %s/%s, ", u.Bucket, u.Upload.Key)
|
||||
healStatus = u.Upload.HealUploadInfo.Status
|
||||
}
|
||||
|
||||
// Print heal status
|
||||
switch healStatus {
|
||||
case madmin.CanHeal:
|
||||
msg += "can be healed"
|
||||
case madmin.Corrupted:
|
||||
@@ -142,6 +162,7 @@ func mainAdminHealList(ctx *cli.Context) error {
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
isRecursive := ctx.Bool("recursive")
|
||||
isIncomplete := ctx.Bool("incomplete")
|
||||
|
||||
// Create a new Minio Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
@@ -197,19 +218,38 @@ func mainAdminHealList(ctx *cli.Context) error {
|
||||
for _, currBucket := range buckets {
|
||||
// Search for objects that need to be healed in the current bucket
|
||||
doneCh := make(chan struct{})
|
||||
listCh, e := client.ListObjectsHeal(currBucket, object, isRecursive, doneCh)
|
||||
fatalIf(probe.NewError(e), "Cannot list heal objects.")
|
||||
// Iterate over objects and print them when not errors
|
||||
for obj := range listCh {
|
||||
if obj.Err != nil {
|
||||
errorIf(probe.NewError(obj.Err), "Cannot heal object `"+obj.Key+"`.")
|
||||
continue
|
||||
|
||||
if isIncomplete {
|
||||
listCh, e := client.ListUploadsHeal(currBucket, object, isRecursive, doneCh)
|
||||
fatalIf(probe.NewError(e), "Cannot list heal uploads.")
|
||||
// Iterate over uploads and print them when not errors
|
||||
for upload := range listCh {
|
||||
if upload.Err != nil {
|
||||
errorIf(probe.NewError(upload.Err), "Cannot heal upload `"+upload.Key+"`.")
|
||||
continue
|
||||
}
|
||||
// Skip for non-recursive use case.
|
||||
if upload.HealUploadInfo == nil {
|
||||
continue
|
||||
}
|
||||
printMsg(healListMessage{Bucket: currBucket, Upload: &upload})
|
||||
}
|
||||
// Skip for non-recursive use case.
|
||||
if obj.HealObjectInfo == nil {
|
||||
continue
|
||||
|
||||
} else {
|
||||
listCh, e := client.ListObjectsHeal(currBucket, object, isRecursive, doneCh)
|
||||
fatalIf(probe.NewError(e), "Cannot list heal objects.")
|
||||
// Iterate over objects and print them when not errors
|
||||
for obj := range listCh {
|
||||
if obj.Err != nil {
|
||||
errorIf(probe.NewError(obj.Err), "Cannot heal object `"+obj.Key+"`.")
|
||||
continue
|
||||
}
|
||||
// Skip for non-recursive use case.
|
||||
if obj.HealObjectInfo == nil {
|
||||
continue
|
||||
}
|
||||
printMsg(healListMessage{Bucket: currBucket, Object: &obj})
|
||||
}
|
||||
printMsg(healListMessage{Bucket: currBucket, Object: obj})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+101
-43
@@ -33,12 +33,16 @@ var (
|
||||
adminHealFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "recursive, r",
|
||||
Usage: "List recursively.",
|
||||
Usage: "Heal recursively.",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "fake, k",
|
||||
Usage: "Issue a fake heal operation.",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "incomplete, I",
|
||||
Usage: "Heal uploads recursively.",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -61,7 +65,10 @@ EXAMPLES:
|
||||
2. Heal all objects under 'dir' prefix
|
||||
$ {{.HelpName}} --recursive play/testbucket/dir/
|
||||
|
||||
3. Issue a fake heal operation to see what the server could report
|
||||
3. Heal all uploads under 'dir' prefix
|
||||
$ {{.HelpName}} --incomplete --recursive play/testbucket/dir/
|
||||
|
||||
4. Issue a fake heal operation to see what the server could report
|
||||
$ {{.HelpName}} --fake play/testbucket/dir/
|
||||
|
||||
`
|
||||
@@ -77,21 +84,27 @@ var adminHealCmd = cli.Command{
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
// healObjectMessage container to hold repair information.
|
||||
type healObjectMessage struct {
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
Object madmin.ObjectInfo `json:"object"`
|
||||
// healMessage container to hold repair information.
|
||||
type healMessage struct {
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
Object *madmin.ObjectInfo `json:"object"`
|
||||
Upload *madmin.UploadInfo `json:"upload"`
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u healObjectMessage) String() string {
|
||||
msg := fmt.Sprintf("Object %s/%s is healed.", u.Bucket, u.Object.Key)
|
||||
func (u healMessage) String() string {
|
||||
msg := ""
|
||||
if u.Object != nil {
|
||||
msg += fmt.Sprintf("Object %s/%s is healed.", u.Bucket, u.Object.Key)
|
||||
} else {
|
||||
msg += fmt.Sprintf("Upload %s/%s/%s is healed.", u.Bucket, u.Upload.Key, u.Upload.UploadID)
|
||||
}
|
||||
return console.Colorize("Heal", msg)
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
func (u healObjectMessage) JSON() string {
|
||||
func (u healMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.Marshal(u)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
@@ -99,6 +112,79 @@ func (u healObjectMessage) JSON() string {
|
||||
return string(statusJSONBytes)
|
||||
}
|
||||
|
||||
func healObjects(client *madmin.AdminClient, bucket, object string, isRecursive, isFake bool) {
|
||||
// Search for objects that need healing
|
||||
doneCh := make(chan struct{})
|
||||
healObjectsCh, e := client.ListObjectsHeal(bucket, object, isRecursive, doneCh)
|
||||
fatalIf(probe.NewError(e), "Cannot list objects to be healed.")
|
||||
|
||||
// Iterate over objects that need healing
|
||||
for obj := range healObjectsCh {
|
||||
// Continue to next object upon any error.
|
||||
if obj.Err != nil {
|
||||
errorIf(probe.NewError(obj.Err), "Cannot list objects to be healed.")
|
||||
continue
|
||||
}
|
||||
// Heal object info is nil skip it, must be a directory.
|
||||
if obj.HealObjectInfo == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check the heal status, and call heal object API only when an object can be healed
|
||||
switch healInfo := *obj.HealObjectInfo; healInfo.Status {
|
||||
case madmin.CanHeal:
|
||||
// Heal Object
|
||||
if e = client.HealObject(bucket, obj.Key, isFake); e != nil {
|
||||
errorIf(probe.NewError(e), "Cannot repair object: `"+obj.Key+"`")
|
||||
continue
|
||||
}
|
||||
|
||||
// Print successful message
|
||||
printMsg(healMessage{Bucket: bucket, Object: &obj})
|
||||
case madmin.QuorumUnavailable:
|
||||
errorIf(errDummy().Trace(), obj.Key+" cannot be healed until quorum is available.")
|
||||
case madmin.Corrupted:
|
||||
errorIf(errDummy().Trace(), obj.Key+" cannot be healed, not enough information.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func healUploads(client *madmin.AdminClient, bucket, object string, isRecursive, isFake bool) {
|
||||
// Search for uploads that need healing
|
||||
doneCh := make(chan struct{})
|
||||
healUploadsCh, e := client.ListUploadsHeal(bucket, object, isRecursive, doneCh)
|
||||
fatalIf(probe.NewError(e), "Cannot list uploads to be healed.")
|
||||
|
||||
// Iterate over uploads that need healing
|
||||
for upload := range healUploadsCh {
|
||||
// Continue to next upload upon any error.
|
||||
if upload.Err != nil {
|
||||
errorIf(probe.NewError(upload.Err), "Cannot list uploads to be healed.")
|
||||
continue
|
||||
}
|
||||
// Heal upload info is nil skip it, must be a directory.
|
||||
if upload.HealUploadInfo == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check the heal status, and call heal upload API only when an upload can be healed
|
||||
switch healInfo := *upload.HealUploadInfo; healInfo.Status {
|
||||
case madmin.CanHeal:
|
||||
// Heal Upload
|
||||
if e = client.HealUpload(bucket, upload.Key, upload.UploadID, isFake); e != nil {
|
||||
errorIf(probe.NewError(e), "Cannot repair upload: `"+upload.Key+"`")
|
||||
continue
|
||||
}
|
||||
// Print successful message
|
||||
printMsg(healMessage{Bucket: bucket, Upload: &upload})
|
||||
case madmin.QuorumUnavailable:
|
||||
errorIf(errDummy().Trace(), upload.Key+" cannot be healed until quorum is available.")
|
||||
case madmin.Corrupted:
|
||||
errorIf(errDummy().Trace(), upload.Key+" cannot be healed, not enough information.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checkAdminHealSyntax - validate all the passed arguments
|
||||
func checkAdminHealSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
@@ -118,6 +204,7 @@ func mainAdminHeal(ctx *cli.Context) error {
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
isRecursive := ctx.Bool("recursive")
|
||||
isIncomplete := ctx.Bool("incomplete")
|
||||
isFake := ctx.Bool("fake")
|
||||
|
||||
console.SetColor("Heal", color.New(color.FgGreen, color.Bold))
|
||||
@@ -147,39 +234,10 @@ func mainAdminHeal(ctx *cli.Context) error {
|
||||
e = client.HealBucket(bucket, isFake)
|
||||
fatalIf(probe.NewError(e), "Cannot heal bucket.")
|
||||
|
||||
// Search for objects that need healing
|
||||
doneCh := make(chan struct{})
|
||||
healObjectsCh, e := client.ListObjectsHeal(bucket, object, isRecursive, doneCh)
|
||||
fatalIf(probe.NewError(e), "Cannot list objects to be healed.")
|
||||
|
||||
// Iterate over objects that need healing
|
||||
for obj := range healObjectsCh {
|
||||
// Continue to next object upon any error.
|
||||
if obj.Err != nil {
|
||||
errorIf(probe.NewError(obj.Err), "Cannot list objects to be healed.")
|
||||
continue
|
||||
}
|
||||
// Heal object info is nil skip it, must be a directory.
|
||||
if obj.HealObjectInfo == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check the heal status, and call heal object API only when an object can be healed
|
||||
switch healInfo := *obj.HealObjectInfo; healInfo.Status {
|
||||
case madmin.CanHeal:
|
||||
// Heal Object
|
||||
if e = client.HealObject(bucket, obj.Key, isFake); e != nil {
|
||||
errorIf(probe.NewError(e), "Cannot repair object: `"+obj.Key+"`")
|
||||
continue
|
||||
}
|
||||
|
||||
// Print successful message
|
||||
printMsg(healObjectMessage{Bucket: bucket, Object: obj})
|
||||
case madmin.QuorumUnavailable:
|
||||
errorIf(errDummy().Trace(), obj.Key+" cannot be healed until quorum is available.")
|
||||
case madmin.Corrupted:
|
||||
errorIf(errDummy().Trace(), obj.Key+" cannot be healed, not enough information.")
|
||||
}
|
||||
if !isIncomplete {
|
||||
healObjects(client, bucket, object, isRecursive, isFake)
|
||||
} else {
|
||||
healUploads(client, bucket, object, isRecursive, isFake)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+58
@@ -43,6 +43,8 @@ func main() {
|
||||
| | |[`HealBucket`](#HealBucket) |||
|
||||
| | |[`HealObject`](#HealObject)|||
|
||||
| | |[`HealFormat`](#HealFormat)|||
|
||||
| | |[`ListUploadsHeal`](#ListUploadsHeal)|||
|
||||
| | |[`HealUpload`](#HealUpload)|||
|
||||
|
||||
## 1. Constructor
|
||||
<a name="Minio"></a>
|
||||
@@ -277,6 +279,62 @@ __Example__
|
||||
log.Println("successfully healed storage format on available disks.")
|
||||
|
||||
```
|
||||
<a name="ListUploadsHeal"> </a>
|
||||
### ListUploadsHeal(bucket, prefix string, recursive bool, doneCh <-chan struct{}) (<-chan UploadInfo, error)
|
||||
List ongoing multipart uploads that need healing.
|
||||
|
||||
| Param | Type | Description |
|
||||
|---|---|---|
|
||||
|`ui.Key` | _string_ | Name of the object being uploaded |
|
||||
|`ui.UploadID` | _string_ | UploadID of the ongoing multipart upload |
|
||||
|`ui.HealUploadInfo.Status` | _HealStatus_| One of `Healthy`, `CanHeal`, `Corrupted`, `QuorumUnavailable`|
|
||||
|`ui.Err`| _error_ | non-nil if fetching fetching healing information failed |
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
|
||||
// Set true if recursive listing is needed.
|
||||
isRecursive := true
|
||||
// List objects that need healing for a given bucket and
|
||||
// prefix.
|
||||
healUploadsCh, err := madmClnt.ListUploadsHeal(bucket, prefix, isRecursive, doneCh)
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to get list of uploads to be healed: ", err)
|
||||
}
|
||||
|
||||
for upload := range healUploadsCh {
|
||||
if upload.Err != nil {
|
||||
log.Println("upload listing error: ", upload.Err)
|
||||
}
|
||||
|
||||
if upload.HealUploadInfo != nil {
|
||||
switch healInfo := *upload.HealUploadInfo; healInfo.Status {
|
||||
case madmin.CanHeal:
|
||||
fmt.Println(upload.Key, " can be healed.")
|
||||
case madmin.QuorumUnavailable:
|
||||
fmt.Println(upload.Key, " can't be healed until quorum is available.")
|
||||
case madmin.Corrupted:
|
||||
fmt.Println(upload.Key, " can't be healed, not enough information.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
<a name="HealUpload"></a>
|
||||
### HealUpload(bucket, object, uploadID string, isDryRun bool) error
|
||||
If upload is successfully healed returns nil, otherwise returns error indicating the reason for failure. If isDryRun is true, then the upload is not healed, but heal upload request is validated by the server. e.g, if the upload exists, if upload name is valid etc.
|
||||
|
||||
``` go
|
||||
isDryRun = false
|
||||
err = madmClnt.HealUpload("mybucket", "myobject", "myuploadID", isDryRun)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
log.Println("successfully healed mybucket/myobject/myuploadID")
|
||||
```
|
||||
|
||||
## 5. Config operations
|
||||
|
||||
|
||||
+2
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||||
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -276,12 +276,7 @@ func (c AdminClient) dumpHTTP(req *http.Request, resp *http.Response) error {
|
||||
|
||||
// Ends the http dump.
|
||||
_, err = fmt.Fprintln(c.traceOutput, "---------END-HTTP---------")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Returns success.
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// do - execute http request.
|
||||
|
||||
-6
@@ -20,7 +20,6 @@ package madmin
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
@@ -34,11 +33,6 @@ type setCredsReq struct {
|
||||
// SetCredentials - Call Set Credentials API to set new access and secret keys in the specified Minio server
|
||||
func (adm *AdminClient) SetCredentials(access, secret string) error {
|
||||
|
||||
// Disallow sending with the server if the connection is not secure
|
||||
if !adm.secure {
|
||||
return errors.New("setting new credentials requires HTTPS connection to the server")
|
||||
}
|
||||
|
||||
// Setup new request
|
||||
reqData := requestData{}
|
||||
reqData.queryValues = make(url.Values)
|
||||
|
||||
+251
-15
@@ -3,6 +3,8 @@
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
@@ -25,6 +27,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
maxUploadsList = 1000
|
||||
)
|
||||
|
||||
// listBucketHealResult container for listObjects response.
|
||||
type listBucketHealResult struct {
|
||||
// A response can contain CommonPrefixes only if you have
|
||||
@@ -89,11 +95,11 @@ type ListBucketsHealResponse struct {
|
||||
}
|
||||
|
||||
// HealStatus - represents different states of healing an object could be in.
|
||||
type healStatus int
|
||||
type HealStatus int
|
||||
|
||||
const (
|
||||
// Healthy - Object that is already healthy
|
||||
Healthy healStatus = iota
|
||||
Healthy HealStatus = iota
|
||||
// CanHeal - Object can be healed
|
||||
CanHeal
|
||||
// Corrupted - Object can't be healed
|
||||
@@ -104,7 +110,7 @@ const (
|
||||
|
||||
// HealBucketInfo - represents healing related information of a bucket.
|
||||
type HealBucketInfo struct {
|
||||
Status healStatus
|
||||
Status HealStatus
|
||||
}
|
||||
|
||||
// BucketInfo - represents bucket metadata.
|
||||
@@ -121,7 +127,7 @@ type BucketInfo struct {
|
||||
|
||||
// HealObjectInfo - represents healing related information of an object.
|
||||
type HealObjectInfo struct {
|
||||
Status healStatus
|
||||
Status HealStatus
|
||||
MissingDataCount int
|
||||
MissingPartityCount int
|
||||
}
|
||||
@@ -156,16 +162,76 @@ type ObjectInfo struct {
|
||||
HealObjectInfo *HealObjectInfo `json:"healObjectInfo,omitempty"`
|
||||
}
|
||||
|
||||
// UploadInfo - represents an ongoing upload that needs to be healed.
|
||||
type UploadInfo struct {
|
||||
Key string `json:"name"` // Name of the object being uploaded.
|
||||
|
||||
UploadID string `json:"uploadId"` // UploadID
|
||||
// Owner name.
|
||||
Owner struct {
|
||||
DisplayName string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
} `json:"owner"`
|
||||
|
||||
// The class of storage used to store the object.
|
||||
StorageClass string `json:"storageClass"`
|
||||
|
||||
Initiated time.Time `json:"initiated"` // Time at which upload was initiated.
|
||||
|
||||
// Error
|
||||
Err error `json:"-"`
|
||||
HealUploadInfo *HealObjectInfo `json:"healObjectInfo,omitempty"`
|
||||
}
|
||||
|
||||
// Initiator - has same properties as Owner.
|
||||
type Initiator Owner
|
||||
|
||||
// upload - represents an ongoing multipart upload.
|
||||
type upload struct {
|
||||
Key string
|
||||
UploadID string `xml:"UploadId"`
|
||||
Initiator Initiator
|
||||
Owner Owner
|
||||
StorageClass string
|
||||
Initiated time.Time
|
||||
HealUploadInfo *HealObjectInfo `xml:"HealObjectInfo,omitempty"`
|
||||
}
|
||||
|
||||
// listUploadsHealResponse - represents ListUploadsHeal response.
|
||||
type listUploadsHealResponse struct {
|
||||
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListMultipartUploadsResult" json:"-"`
|
||||
|
||||
Bucket string
|
||||
KeyMarker string
|
||||
UploadIDMarker string `xml:"UploadIdMarker"`
|
||||
NextKeyMarker string
|
||||
NextUploadIDMarker string `xml:"NextUploadIdMarker"`
|
||||
Delimiter string
|
||||
Prefix string
|
||||
EncodingType string `xml:"EncodingType,omitempty"`
|
||||
MaxUploads int
|
||||
IsTruncated bool
|
||||
|
||||
// List of pending uploads.
|
||||
Uploads []upload `xml:"Upload"`
|
||||
|
||||
// Delimed common prefixes.
|
||||
CommonPrefixes []commonPrefix
|
||||
}
|
||||
|
||||
type healQueryKey string
|
||||
|
||||
const (
|
||||
healBucket healQueryKey = "bucket"
|
||||
healObject healQueryKey = "object"
|
||||
healPrefix healQueryKey = "prefix"
|
||||
healMarker healQueryKey = "marker"
|
||||
healDelimiter healQueryKey = "delimiter"
|
||||
healMaxKey healQueryKey = "max-key"
|
||||
healDryRun healQueryKey = "dry-run"
|
||||
healBucket healQueryKey = "bucket"
|
||||
healObject healQueryKey = "object"
|
||||
healPrefix healQueryKey = "prefix"
|
||||
healMarker healQueryKey = "marker"
|
||||
healDelimiter healQueryKey = "delimiter"
|
||||
healMaxKey healQueryKey = "max-key"
|
||||
healDryRun healQueryKey = "dry-run"
|
||||
healUploadIDMarker healQueryKey = "upload-id-marker"
|
||||
healMaxUpload healQueryKey = "max-uploads"
|
||||
healUploadID healQueryKey = "upload-id"
|
||||
)
|
||||
|
||||
// mkHealQueryVal - helper function to construct heal REST API query params.
|
||||
@@ -211,10 +277,7 @@ func (adm *AdminClient) listObjectsHeal(bucket, prefix, marker, delimiter string
|
||||
}
|
||||
|
||||
err = xml.NewDecoder(resp.Body).Decode(&toBeHealedObjects)
|
||||
if err != nil {
|
||||
return toBeHealedObjects, err
|
||||
}
|
||||
return toBeHealedObjects, nil
|
||||
return toBeHealedObjects, err
|
||||
}
|
||||
|
||||
// ListObjectsHeal - Lists upto maxKeys objects that needing heal matching bucket, prefix, marker, delimiter.
|
||||
@@ -370,6 +433,43 @@ func (adm *AdminClient) HealBucket(bucket string, dryrun bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// HealUpload - Heal the given upload.
|
||||
func (adm *AdminClient) HealUpload(bucket, object, uploadID string, dryrun bool) error {
|
||||
// Construct query params.
|
||||
queryVal := url.Values{}
|
||||
queryVal.Set("heal", "")
|
||||
queryVal.Set(string(healBucket), bucket)
|
||||
queryVal.Set(string(healObject), object)
|
||||
queryVal.Set(string(healUploadID), uploadID)
|
||||
if dryrun {
|
||||
queryVal.Set(string(healDryRun), "")
|
||||
}
|
||||
|
||||
hdrs := make(http.Header)
|
||||
hdrs.Set(minioAdminOpHeader, "upload")
|
||||
|
||||
reqData := requestData{
|
||||
queryValues: queryVal,
|
||||
customHeaders: hdrs,
|
||||
}
|
||||
|
||||
// Execute POST on
|
||||
// /?heal&bucket=mybucket&object=myobject&upload-id=uploadID
|
||||
// to heal an upload.
|
||||
resp, err := adm.executeMethod("POST", reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return httpRespToErrorResponse(resp)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HealObject - Heal the given object.
|
||||
func (adm *AdminClient) HealObject(bucket, object string, dryrun bool) error {
|
||||
// Construct query params.
|
||||
@@ -435,3 +535,139 @@ func (adm *AdminClient) HealFormat(dryrun bool) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// mkUploadsHealQuery - helper function to construct query params for
|
||||
// ListUploadsHeal API.
|
||||
func mkUploadsHealQuery(bucket, prefix, marker, uploadIDMarker, delimiter, maxUploadsStr string) url.Values {
|
||||
|
||||
queryVal := make(url.Values)
|
||||
queryVal.Set("heal", "")
|
||||
queryVal.Set(string(healBucket), bucket)
|
||||
queryVal.Set(string(healPrefix), prefix)
|
||||
queryVal.Set(string(healMarker), marker)
|
||||
queryVal.Set(string(healUploadIDMarker), uploadIDMarker)
|
||||
queryVal.Set(string(healDelimiter), delimiter)
|
||||
queryVal.Set(string(healMaxUpload), maxUploadsStr)
|
||||
return queryVal
|
||||
}
|
||||
|
||||
func (adm *AdminClient) listUploadsHeal(bucket, prefix, marker, uploadIDMarker, delimiter string, maxUploads int) (listUploadsHealResponse, error) {
|
||||
// Construct query params.
|
||||
maxUploadsStr := fmt.Sprintf("%d", maxUploads)
|
||||
queryVal := mkUploadsHealQuery(bucket, prefix, marker, uploadIDMarker, delimiter, maxUploadsStr)
|
||||
|
||||
hdrs := make(http.Header)
|
||||
hdrs.Set(minioAdminOpHeader, "list-uploads")
|
||||
|
||||
reqData := requestData{
|
||||
queryValues: queryVal,
|
||||
customHeaders: hdrs,
|
||||
}
|
||||
|
||||
// Empty 'list' of objects to be healed.
|
||||
toBeHealedUploads := listUploadsHealResponse{}
|
||||
|
||||
// Execute GET on /?heal to list objects needing heal.
|
||||
resp, err := adm.executeMethod("GET", reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return listUploadsHealResponse{}, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return toBeHealedUploads, httpRespToErrorResponse(resp)
|
||||
|
||||
}
|
||||
|
||||
err = xml.NewDecoder(resp.Body).Decode(&toBeHealedUploads)
|
||||
if err != nil {
|
||||
return listUploadsHealResponse{}, err
|
||||
}
|
||||
|
||||
return toBeHealedUploads, nil
|
||||
}
|
||||
|
||||
// ListUploadsHeal - issues list heal uploads API request
|
||||
func (adm *AdminClient) ListUploadsHeal(bucket, prefix string, recursive bool,
|
||||
doneCh <-chan struct{}) (<-chan UploadInfo, error) {
|
||||
|
||||
// Default listing is delimited at "/"
|
||||
delimiter := "/"
|
||||
if recursive {
|
||||
// If recursive we do not delimit.
|
||||
delimiter = ""
|
||||
}
|
||||
|
||||
uploadIDMarker := ""
|
||||
|
||||
// Allocate new list objects channel.
|
||||
uploadStatCh := make(chan UploadInfo, maxUploadsList)
|
||||
|
||||
// Initiate list objects goroutine here.
|
||||
go func(uploadStatCh chan<- UploadInfo) {
|
||||
defer close(uploadStatCh)
|
||||
// Save marker for next request.
|
||||
var marker string
|
||||
for {
|
||||
// Get list of objects a maximum of 1000 per request.
|
||||
result, err := adm.listUploadsHeal(bucket, prefix, marker,
|
||||
uploadIDMarker, delimiter, maxUploadsList)
|
||||
if err != nil {
|
||||
uploadStatCh <- UploadInfo{
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// If contents are available loop through and
|
||||
// send over channel.
|
||||
for _, upload := range result.Uploads {
|
||||
select {
|
||||
// Send upload info.
|
||||
case uploadStatCh <- UploadInfo{
|
||||
Key: upload.Key,
|
||||
Initiated: upload.Initiated,
|
||||
HealUploadInfo: upload.HealUploadInfo,
|
||||
}:
|
||||
// If receives done from the caller, return here.
|
||||
case <-doneCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Send all common prefixes if any. NOTE:
|
||||
// prefixes are only present if the request is
|
||||
// delimited.
|
||||
for _, prefix := range result.CommonPrefixes {
|
||||
upload := UploadInfo{}
|
||||
upload.Key = prefix.Prefix
|
||||
select {
|
||||
// Send object prefixes.
|
||||
case uploadStatCh <- upload:
|
||||
// If receives done from the caller, return here.
|
||||
case <-doneCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// If next uploadID marker is present, set it
|
||||
// for the next request.
|
||||
if result.NextUploadIDMarker != "" {
|
||||
uploadIDMarker = result.NextUploadIDMarker
|
||||
}
|
||||
|
||||
// If next marker present, save it for next request.
|
||||
if result.KeyMarker != "" {
|
||||
marker = result.KeyMarker
|
||||
}
|
||||
|
||||
// Listing ends result is not truncated,
|
||||
// return right here.
|
||||
if !result.IsTruncated {
|
||||
return
|
||||
}
|
||||
}
|
||||
}(uploadStatCh)
|
||||
return uploadStatCh, nil
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -80,10 +80,10 @@
|
||||
"revisionTime": "2016-08-18T00:31:20Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "U2PFIqUAO4PpfqYZhouq/7KCXkU=",
|
||||
"checksumSHA1": "qFt4mCN7Nj3vwa9RtrVOIvqbEFA=",
|
||||
"path": "github.com/minio/minio/pkg/madmin",
|
||||
"revision": "e5d4e7aa9d7ba16bbf0c0fe135eb05102132b528",
|
||||
"revisionTime": "2017-03-03T11:01:42Z"
|
||||
"revision": "d8e515a396cabaae8b27fece79fe776956f6e972",
|
||||
"revisionTime": "2017-03-18T17:05:16Z"
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio/pkg/probe",
|
||||
|
||||
Reference in New Issue
Block a user