do not return error if no stripe in audit selection (#1867)
This commit is contained in:
parent
891780990f
commit
900ede151a
@ -42,18 +42,17 @@ func NewCursor(metainfo *metainfo.Service) *Cursor {
|
||||
}
|
||||
}
|
||||
|
||||
// NextStripe returns a random stripe to be audited
|
||||
func (cursor *Cursor) NextStripe(ctx context.Context) (stripe *Stripe, err error) {
|
||||
// NextStripe returns a random stripe to be audited. "more" is true except when we have completed iterating over metainfo. It can be disregarded if there is an error or stripe returned
|
||||
func (cursor *Cursor) NextStripe(ctx context.Context) (stripe *Stripe, more bool, err error) {
|
||||
cursor.mutex.Lock()
|
||||
defer cursor.mutex.Unlock()
|
||||
|
||||
var pointerItems []*pb.ListResponse_Item
|
||||
var path storj.Path
|
||||
var more bool
|
||||
|
||||
pointerItems, more, err = cursor.metainfo.List("", cursor.lastPath, "", true, 0, meta.None)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, more, err
|
||||
}
|
||||
|
||||
// keep track of last path listed
|
||||
@ -65,19 +64,22 @@ func (cursor *Cursor) NextStripe(ctx context.Context) (stripe *Stripe, err error
|
||||
|
||||
pointer, path, err := cursor.getRandomValidPointer(pointerItems)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, more, err
|
||||
}
|
||||
if pointer == nil {
|
||||
return nil, more, nil
|
||||
}
|
||||
|
||||
index, err := getRandomStripe(pointer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, more, err
|
||||
}
|
||||
|
||||
return &Stripe{
|
||||
Index: index,
|
||||
Segment: pointer,
|
||||
SegmentPath: path,
|
||||
}, nil
|
||||
}, more, nil
|
||||
}
|
||||
|
||||
func getRandomStripe(pointer *pb.Pointer) (index int64, err error) {
|
||||
@ -140,7 +142,6 @@ func (cursor *Cursor) getRandomValidPointer(pointerItems []*pb.ListResponse_Item
|
||||
return pointer, path, nil
|
||||
}
|
||||
|
||||
errGroup.Add(Error.New("no valid node found in selection"))
|
||||
return nil, "", errGroup.Err()
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func TestAuditSegment(t *testing.T) {
|
||||
t.Run("NextStripe", func(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.bm, func(t *testing.T) {
|
||||
stripe, err := cursor.NextStripe(ctx)
|
||||
stripe, _, err := cursor.NextStripe(ctx)
|
||||
if err != nil {
|
||||
require.Error(t, err)
|
||||
require.Nil(t, stripe)
|
||||
@ -124,8 +124,8 @@ func TestDeleteExpired(t *testing.T) {
|
||||
require.Len(t, list, 10)
|
||||
// make sure an error and no pointer is returned
|
||||
t.Run("NextStripe", func(t *testing.T) {
|
||||
stripe, err := cursor.NextStripe(ctx)
|
||||
require.Error(t, err)
|
||||
stripe, _, err := cursor.NextStripe(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, stripe)
|
||||
})
|
||||
//make sure it they're not in there anymore
|
||||
|
@ -35,7 +35,7 @@ func TestVerifierHappyPath(t *testing.T) {
|
||||
overlay := planet.Satellites[0].Overlay.Service
|
||||
cursor := audit.NewCursor(metainfo)
|
||||
|
||||
stripe, err := cursor.NextStripe(ctx)
|
||||
stripe, _, err := cursor.NextStripe(ctx)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, stripe)
|
||||
|
||||
|
@ -73,9 +73,19 @@ func (service *Service) Close() error {
|
||||
|
||||
// process picks a random stripe and verifies correctness
|
||||
func (service *Service) process(ctx context.Context) error {
|
||||
stripe, err := service.Cursor.NextStripe(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
var stripe *Stripe
|
||||
for {
|
||||
s, more, err := service.Cursor.NextStripe(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if s != nil {
|
||||
stripe = s
|
||||
break
|
||||
}
|
||||
if !more {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
verifiedNodes, err := service.Verifier.Verify(ctx, stripe)
|
||||
|
@ -44,7 +44,7 @@ func TestGetShareTimeout(t *testing.T) {
|
||||
cursor := audit.NewCursor(metainfo)
|
||||
|
||||
var stripe *audit.Stripe
|
||||
stripe, err = cursor.NextStripe(ctx)
|
||||
stripe, _, err = cursor.NextStripe(ctx)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, stripe)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user