mirror of
https://github.com/pgsty/minio.git
synced 2026-12-03 20:36:37 +03:00
Merge pull request #360 from ScaleCommerce/fix/heal-checkparts-nil-response
fix(heal): do not panic when CheckParts returns no result
This commit is contained in:
@@ -420,6 +420,12 @@ func checkObjectWithAllParts(ctx context.Context, onlineDisks []StorageAPI, part
|
||||
default:
|
||||
verifyResp, verifyErr = onlineDisk.CheckParts(ctx, bucket, object, meta)
|
||||
}
|
||||
if verifyErr == nil && (verifyResp == nil || len(verifyResp.Results) < len(latestMeta.Parts)) {
|
||||
// A drive that returned no usable per-part result cannot vouch
|
||||
// for its parts; treat it like an unreachable drive instead of
|
||||
// dereferencing a nil or short response.
|
||||
verifyErr = errDiskNotFound
|
||||
}
|
||||
|
||||
for p := range latestMeta.Parts {
|
||||
if verifyErr != nil {
|
||||
|
||||
@@ -772,3 +772,53 @@ func TestCommonParities(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checkPartsResultDisk returns a programmed CheckParts/VerifyFile result.
|
||||
// All other StorageAPI methods are unimplemented and panic if called.
|
||||
type checkPartsResultDisk struct {
|
||||
StorageAPI
|
||||
resp *CheckPartsResp
|
||||
err error
|
||||
}
|
||||
|
||||
func (d *checkPartsResultDisk) CheckParts(context.Context, string, string, FileInfo) (*CheckPartsResp, error) {
|
||||
return d.resp, d.err
|
||||
}
|
||||
|
||||
func (d *checkPartsResultDisk) VerifyFile(context.Context, string, string, FileInfo) (*CheckPartsResp, error) {
|
||||
return d.resp, d.err
|
||||
}
|
||||
|
||||
// A drive whose CheckParts/VerifyFile returns no error but also no (or a
|
||||
// short) per-part result, e.g. a remote stream that ended without a response,
|
||||
// must be reported as unreachable instead of crashing the heal.
|
||||
func TestCheckObjectWithAllPartsMissingResult(t *testing.T) {
|
||||
for _, scanMode := range []madmin.HealScanMode{madmin.HealNormalScan, madmin.HealDeepScan} {
|
||||
t.Run(fmt.Sprintf("scanMode=%d", scanMode), func(t *testing.T) {
|
||||
meta := nativeAuditMetadata()
|
||||
full := &CheckPartsResp{Results: []int{checkPartSuccess, checkPartSuccess}}
|
||||
disks := []StorageAPI{
|
||||
&checkPartsResultDisk{resp: nil}, // (nil, nil)
|
||||
&checkPartsResultDisk{resp: &CheckPartsResp{Results: []int{checkPartSuccess}}}, // short result
|
||||
&checkPartsResultDisk{resp: full},
|
||||
&checkPartsResultDisk{resp: full},
|
||||
}
|
||||
errs := make([]error, len(disks))
|
||||
|
||||
dataErrsByDisk, _ := checkObjectWithAllParts(t.Context(), disks, meta, errs, meta[0],
|
||||
false, "bucket", "object", scanMode)
|
||||
|
||||
for i := range disks {
|
||||
for p, got := range dataErrsByDisk[i] {
|
||||
want := checkPartSuccess
|
||||
if i < 2 {
|
||||
want = checkPartDiskNotFound
|
||||
}
|
||||
if got != want {
|
||||
t.Errorf("disk %d part %d: got %d, want %d", i, p, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,6 +480,12 @@ func (client *storageRESTClient) CheckParts(ctx context.Context, volume string,
|
||||
resp = r
|
||||
return nil
|
||||
})
|
||||
if err == nil && resp == nil {
|
||||
// The stream ended without a response and without an error,
|
||||
// e.g. when the mux was closed during a disconnect. Never
|
||||
// return (nil, nil): callers rely on resp being set on success.
|
||||
err = grid.ErrDisconnected
|
||||
}
|
||||
return resp, toStorageErr(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user