2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-10 19:08:45 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-12-12 15:39:16 +00:00
|
|
|
package irreparable_test
|
2018-12-10 19:08:45 +00:00
|
|
|
|
|
|
|
import (
|
2019-03-15 20:21:52 +00:00
|
|
|
"strconv"
|
2018-12-10 19:08:45 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-07-08 23:16:50 +01:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/stretchr/testify/require"
|
2018-12-10 19:08:45 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
2019-03-15 20:21:52 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-12-27 09:56:25 +00:00
|
|
|
"storj.io/storj/satellite"
|
2018-12-10 19:08:45 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIrreparable(t *testing.T) {
|
2018-12-27 09:56:25 +00:00
|
|
|
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
2018-12-10 19:08:45 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
irrdb := db.Irreparable()
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
// Create and insert test segment infos into DB
|
|
|
|
var segments []*pb.IrreparableSegment
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
segments = append(segments, &pb.IrreparableSegment{
|
2019-07-08 23:16:50 +01:00
|
|
|
Path: []byte(strconv.Itoa(i)),
|
|
|
|
SegmentDetail: &pb.Pointer{
|
|
|
|
CreationDate: time.Now(),
|
|
|
|
},
|
2019-03-15 20:21:52 +00:00
|
|
|
LostPieces: int32(i),
|
|
|
|
LastRepairAttempt: time.Now().Unix(),
|
|
|
|
RepairAttemptCount: int64(10),
|
|
|
|
})
|
2019-07-08 23:16:50 +01:00
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
err := irrdb.IncrementRepairAttempts(ctx, segments[i])
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-15 20:21:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
{ // GetLimited limit 1, starting from the beginning
|
|
|
|
lastSeenSegmentPath := []byte{}
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 1, lastSeenSegmentPath)
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(segs))
|
|
|
|
require.Empty(t, cmp.Diff(segments[0], segs[0], cmp.Comparer(pb.Equal)))
|
2019-03-15 20:21:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
{ // GetLimited limit 1, starting after the first item
|
|
|
|
lastSeenSegmentPath := []byte(strconv.Itoa(0))
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 1, lastSeenSegmentPath)
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(segs))
|
|
|
|
require.Empty(t, cmp.Diff(segments[1], segs[0], cmp.Comparer(pb.Equal)))
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
{ // GetLimited limit 2, starting from the beginning
|
|
|
|
lastSeenSegmentPath := []byte{}
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 2, lastSeenSegmentPath)
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(segs))
|
|
|
|
require.Empty(t, cmp.Diff(segments[0], segs[0], cmp.Comparer(pb.Equal)))
|
|
|
|
require.Empty(t, cmp.Diff(segments[1], segs[1], cmp.Comparer(pb.Equal)))
|
2019-03-15 20:21:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
{ // GetLimited limit 2, starting after the first item
|
|
|
|
lastSeenSegmentPath := []byte(strconv.Itoa(0))
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 2, lastSeenSegmentPath)
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(segs))
|
|
|
|
require.Empty(t, cmp.Diff(segments[1], segs[0], cmp.Comparer(pb.Equal)))
|
|
|
|
require.Empty(t, cmp.Diff(segments[2], segs[1], cmp.Comparer(pb.Equal)))
|
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
{ // GetLimited limit 3, starting after the first item
|
|
|
|
lastSeenSegmentPath := []byte(strconv.Itoa(0))
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 3, lastSeenSegmentPath)
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(segs))
|
|
|
|
require.Empty(t, cmp.Diff(segments[1], segs[0], cmp.Comparer(pb.Equal)))
|
|
|
|
require.Empty(t, cmp.Diff(segments[2], segs[1], cmp.Comparer(pb.Equal)))
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
{ // Test repair count incrementation
|
|
|
|
err := irrdb.IncrementRepairAttempts(ctx, segments[0])
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-15 20:21:52 +00:00
|
|
|
segments[0].RepairAttemptCount++
|
2019-02-05 16:00:52 +00:00
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
dbxInfo, err := irrdb.Get(ctx, segments[0].Path)
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, cmp.Diff(segments[0], dbxInfo, cmp.Comparer(pb.Equal)))
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ //Delete existing entry
|
2019-03-15 20:21:52 +00:00
|
|
|
err := irrdb.Delete(ctx, segments[0].Path)
|
2019-07-08 23:16:50 +01:00
|
|
|
require.NoError(t, err)
|
2019-02-05 16:00:52 +00:00
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
_, err = irrdb.Get(ctx, segments[0].Path)
|
2019-07-08 23:16:50 +01:00
|
|
|
require.Error(t, err)
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
2018-12-10 19:08:45 +00:00
|
|
|
})
|
|
|
|
}
|