From 91721f63ba80797d4d0f9def14e3338d72b078fe Mon Sep 17 00:00:00 2001 From: Bill Thorp Date: Fri, 17 May 2019 15:02:40 -0400 Subject: [PATCH] Bt/repair no nodes (#1974) * handle cases where repair is equal to total --- pkg/datarepair/checker/checker.go | 13 ++++++++++--- satellite/metainfo/metainfo.go | 6 ++++-- satellite/metainfo/metainfo_test.go | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/datarepair/checker/checker.go b/pkg/datarepair/checker/checker.go index d94ea692d..42d44d2e8 100644 --- a/pkg/datarepair/checker/checker.go +++ b/pkg/datarepair/checker/checker.go @@ -127,8 +127,15 @@ func (checker *Checker) IdentifyInjuredSegments(ctx context.Context) (err error) } remoteSegmentsChecked++ - numHealthy := len(pieces) - len(missingPieces) - if (int32(numHealthy) >= pointer.Remote.Redundancy.MinReq) && (int32(numHealthy) <= pointer.Remote.Redundancy.RepairThreshold) { + numHealthy := int32(len(pieces) - len(missingPieces)) + redundancy := pointer.Remote.Redundancy + // we repair when the number of healthy files is less than or equal to the repair threshold + // except for the case when the repair and success thresholds are the same (a case usually seen during testing) + if numHealthy >= redundancy.MinReq && numHealthy <= redundancy.RepairThreshold && redundancy.RepairThreshold != redundancy.SuccessThreshold { + if len(missingPieces) == 0 { + checker.logger.Warn("Missing pieces is zero in checker, but this should be impossible -- bad redundancy scheme.") + continue + } remoteSegmentsNeedingRepair++ err = checker.repairQueue.Insert(ctx, &pb.InjuredSegment{ Path: string(item.Key), @@ -137,7 +144,7 @@ func (checker *Checker) IdentifyInjuredSegments(ctx context.Context) (err error) if err != nil { return Error.New("error adding injured segment to queue %s", err) } - } else if int32(numHealthy) < pointer.Remote.Redundancy.MinReq { + } else if numHealthy < redundancy.MinReq { pathElements := storj.SplitPath(storj.Path(item.Key)) // check to make sure there are at least *4* path elements. the first three // are project, segment, and bucket name, but we want to make sure we're talking diff --git a/satellite/metainfo/metainfo.go b/satellite/metainfo/metainfo.go index 3f3a11697..5dcee9d17 100644 --- a/satellite/metainfo/metainfo.go +++ b/satellite/metainfo/metainfo.go @@ -457,8 +457,10 @@ func (endpoint *Endpoint) filterValidPieces(pointer *pb.Pointer) error { remotePieces = append(remotePieces, piece) } - if int32(len(remotePieces)) < remote.Redundancy.RepairThreshold { - return Error.New("Number of valid pieces is lower then repair threshold: %v < %v", + // we repair when the number of healthy files is less than or equal to the repair threshold + // except for the case when the repair and success thresholds are the same (a case usually seen during testing) + if int32(len(remotePieces)) <= remote.Redundancy.RepairThreshold && remote.Redundancy.RepairThreshold != remote.Redundancy.SuccessThreshold { + return Error.New("Number of valid pieces is less than or equal to the repair threshold: %v < %v", len(remotePieces), remote.Redundancy.RepairThreshold, ) diff --git a/satellite/metainfo/metainfo_test.go b/satellite/metainfo/metainfo_test.go index f577e8bee..762b6b4d5 100644 --- a/satellite/metainfo/metainfo_test.go +++ b/satellite/metainfo/metainfo_test.go @@ -216,7 +216,7 @@ func TestCommitSegment(t *testing.T) { } _, err = metainfo.CommitSegment(ctx, "bucket", "path", -1, pointer, limits) require.Error(t, err) - require.Contains(t, err.Error(), "Number of valid pieces is lower then repair threshold") + require.Contains(t, err.Error(), "Number of valid pieces is less than or equal to the repair threshold") } }) }