diff --git a/pkg/audit/newverifier_test.go b/pkg/audit/newverifier_test.go index b5ee93256..d63548ccf 100644 --- a/pkg/audit/newverifier_test.go +++ b/pkg/audit/newverifier_test.go @@ -66,7 +66,7 @@ func TestVerifierHappyPath(t *testing.T) { verifiedNodes, err := verifier.Verify(ctx, stripe) require.NoError(t, err) - require.Len(t, verifiedNodes.SuccessNodeIDs, 4) - require.Len(t, verifiedNodes.FailNodeIDs, 0) + require.Len(t, verifiedNodes.Successes, 4) + require.Len(t, verifiedNodes.Fails, 0) }) } diff --git a/pkg/audit/reporter.go b/pkg/audit/reporter.go index 1924e4c90..ea92edcde 100644 --- a/pkg/audit/reporter.go +++ b/pkg/audit/reporter.go @@ -13,7 +13,7 @@ import ( ) type reporter interface { - RecordAudits(ctx context.Context, req *RecordAuditsInfo) (failed *RecordAuditsInfo, err error) + RecordAudits(ctx context.Context, req *Report) (failed *Report, err error) } // Reporter records audit reports in overlay and implements the reporter interface @@ -23,12 +23,12 @@ type Reporter struct { maxRetries int } -// RecordAuditsInfo is a struct containing arguments/return values for RecordAudits() -type RecordAuditsInfo struct { - SuccessNodeIDs storj.NodeIDList - FailNodeIDs storj.NodeIDList - OfflineNodeIDs storj.NodeIDList - PendingAudits []*PendingAudit +// Report contains audit result lists for nodes that succeeded, failed, were offline, or have pending audits +type Report struct { + Successes storj.NodeIDList + Fails storj.NodeIDList + Offlines storj.NodeIDList + PendingAudits []*PendingAudit } // NewReporter instantiates a reporter @@ -36,37 +36,37 @@ func NewReporter(overlay *overlay.Cache, containment Containment, maxRetries int return &Reporter{overlay: overlay, containment: containment, maxRetries: maxRetries} } -// RecordAudits saves failed audit details to overlay -func (reporter *Reporter) RecordAudits(ctx context.Context, req *RecordAuditsInfo) (failed *RecordAuditsInfo, err error) { - successNodeIDs := req.SuccessNodeIDs - failNodeIDs := req.FailNodeIDs - offlineNodeIDs := req.OfflineNodeIDs +// RecordAudits saves audit details to overlay +func (reporter *Reporter) RecordAudits(ctx context.Context, req *Report) (failed *Report, err error) { + successes := req.Successes + fails := req.Fails + offlines := req.Offlines pendingAudits := req.PendingAudits var errlist errs.Group retries := 0 for retries < reporter.maxRetries { - if len(successNodeIDs) == 0 && len(failNodeIDs) == 0 && len(offlineNodeIDs) == 0 { + if len(successes) == 0 && len(fails) == 0 && len(offlines) == 0 { return nil, nil } errlist = errs.Group{} - if len(successNodeIDs) > 0 { - successNodeIDs, err = reporter.recordAuditSuccessStatus(ctx, successNodeIDs) + if len(successes) > 0 { + successes, err = reporter.recordAuditSuccessStatus(ctx, successes) if err != nil { errlist.Add(err) } } - if len(failNodeIDs) > 0 { - failNodeIDs, err = reporter.recordAuditFailStatus(ctx, failNodeIDs) + if len(fails) > 0 { + fails, err = reporter.recordAuditFailStatus(ctx, fails) if err != nil { errlist.Add(err) } } - if len(offlineNodeIDs) > 0 { - offlineNodeIDs, err = reporter.recordOfflineStatus(ctx, offlineNodeIDs) + if len(offlines) > 0 { + offlines, err = reporter.recordOfflineStatus(ctx, offlines) if err != nil { errlist.Add(err) } @@ -83,11 +83,11 @@ func (reporter *Reporter) RecordAudits(ctx context.Context, req *RecordAuditsInf err = errlist.Err() if retries >= reporter.maxRetries && err != nil { - return &RecordAuditsInfo{ - SuccessNodeIDs: successNodeIDs, - FailNodeIDs: failNodeIDs, - OfflineNodeIDs: offlineNodeIDs, - PendingAudits: pendingAudits, + return &Report{ + Successes: successes, + Fails: fails, + Offlines: offlines, + PendingAudits: pendingAudits, }, errs.Combine(Error.New("some nodes failed to be updated in overlay"), err) } return nil, nil diff --git a/pkg/audit/timeout_test.go b/pkg/audit/timeout_test.go index 41ecf329a..52ba21c3a 100644 --- a/pkg/audit/timeout_test.go +++ b/pkg/audit/timeout_test.go @@ -82,7 +82,7 @@ func TestGetShareTimeout(t *testing.T) { assert.Error(t, err) assert.NotNil(t, verifiedNodes) for i := 0; i < k; i++ { - assert.True(t, contains(verifiedNodes.OfflineNodeIDs, pieces[i].NodeId)) + assert.True(t, contains(verifiedNodes.Offlines, pieces[i].NodeId)) } }) } diff --git a/pkg/audit/verifier.go b/pkg/audit/verifier.go index a2efb5e7c..1ce23ea5b 100644 --- a/pkg/audit/verifier.go +++ b/pkg/audit/verifier.go @@ -53,7 +53,7 @@ func NewVerifier(log *zap.Logger, transport transport.Client, overlay *overlay.C } // Verify downloads shares then verifies the data correctness at the given stripe -func (verifier *Verifier) Verify(ctx context.Context, stripe *Stripe) (verifiedNodes *RecordAuditsInfo, err error) { +func (verifier *Verifier) Verify(ctx context.Context, stripe *Stripe) (verifiedNodes *Report, err error) { defer mon.Task()(&ctx)(&err) pointer := stripe.Segment @@ -92,15 +92,15 @@ func (verifier *Verifier) Verify(ctx context.Context, stripe *Stripe) (verifiedN total := int(pointer.Remote.Redundancy.GetTotal()) if len(sharesToAudit) < required { - return &RecordAuditsInfo{ - OfflineNodeIDs: offlineNodes, + return &Report{ + Offlines: offlineNodes, }, Error.New("not enough shares for successful audit: got %d, required %d", len(sharesToAudit), required) } pieceNums, correctedShares, err := auditShares(ctx, required, total, sharesToAudit) if err != nil { - return &RecordAuditsInfo{ - OfflineNodeIDs: offlineNodes, + return &Report{ + Offlines: offlineNodes, }, err } @@ -112,18 +112,18 @@ func (verifier *Verifier) Verify(ctx context.Context, stripe *Stripe) (verifiedN pendingAudits, err := createPendingAudits(containedNodes, correctedShares, stripe) if err != nil { - return &RecordAuditsInfo{ - SuccessNodeIDs: successNodes, - FailNodeIDs: failedNodes, - OfflineNodeIDs: offlineNodes, + return &Report{ + Successes: successNodes, + Fails: failedNodes, + Offlines: offlineNodes, }, err } - return &RecordAuditsInfo{ - SuccessNodeIDs: successNodes, - FailNodeIDs: failedNodes, - OfflineNodeIDs: offlineNodes, - PendingAudits: pendingAudits, + return &Report{ + Successes: successNodes, + Fails: failedNodes, + Offlines: offlineNodes, + PendingAudits: pendingAudits, }, nil }