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
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/testcontext"
|
2020-11-10 11:56:30 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2018-12-27 09:56:25 +00:00
|
|
|
"storj.io/storj/satellite"
|
2020-10-30 11:12:01 +00:00
|
|
|
"storj.io/storj/satellite/internalpb"
|
2020-11-10 11:56:30 +00:00
|
|
|
"storj.io/storj/satellite/metainfo/metabase"
|
2018-12-10 19:08:45 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIrreparable(t *testing.T) {
|
2020-01-19 16:29:15 +00:00
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
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
|
2020-10-30 11:12:01 +00:00
|
|
|
var segments []*internalpb.IrreparableSegment
|
2019-03-15 20:21:52 +00:00
|
|
|
for i := 0; i < 3; i++ {
|
2020-10-30 11:12:01 +00:00
|
|
|
segments = append(segments, &internalpb.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
|
|
|
}
|
|
|
|
|
2020-10-13 13:47:55 +01: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
|
|
|
})
|
|
|
|
}
|
2020-11-10 11:56:30 +00:00
|
|
|
|
|
|
|
func TestIrreparableProcess(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 3, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
|
|
|
checker.Loop.Stop()
|
|
|
|
checker.IrreparableLoop.Stop()
|
|
|
|
irreparabledb := planet.Satellites[0].DB.Irreparable()
|
|
|
|
queue := planet.Satellites[0].DB.RepairQueue()
|
|
|
|
|
|
|
|
seg := &internalpb.IrreparableSegment{
|
|
|
|
Path: []byte{1},
|
|
|
|
SegmentDetail: &pb.Pointer{
|
|
|
|
Type: pb.Pointer_REMOTE,
|
|
|
|
CreationDate: time.Now(),
|
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
|
|
|
MinReq: 1,
|
|
|
|
RepairThreshold: 2,
|
|
|
|
SuccessThreshold: 3,
|
|
|
|
Total: 4,
|
|
|
|
},
|
|
|
|
RemotePieces: []*pb.RemotePiece{
|
|
|
|
{
|
|
|
|
NodeId: planet.StorageNodes[0].ID(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NodeId: planet.StorageNodes[1].ID(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NodeId: planet.StorageNodes[2].ID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LostPieces: int32(4),
|
|
|
|
LastRepairAttempt: time.Now().Unix(),
|
|
|
|
RepairAttemptCount: int64(10),
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, irreparabledb.IncrementRepairAttempts(ctx, seg))
|
|
|
|
|
|
|
|
result, err := irreparabledb.Get(ctx, metabase.SegmentKey(seg.GetPath()))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, result)
|
|
|
|
|
|
|
|
// test healthy segment is removed from irreparable DB
|
|
|
|
require.NoError(t, checker.IrreparableProcess(ctx))
|
|
|
|
|
|
|
|
result, err = irreparabledb.Get(ctx, metabase.SegmentKey(seg.GetPath()))
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, result)
|
|
|
|
|
|
|
|
// test unhealthy repairable segment is removed from irreparable DB and inserted into repair queue
|
|
|
|
seg.SegmentDetail.Remote.RemotePieces[0] = &pb.RemotePiece{}
|
|
|
|
seg.SegmentDetail.Remote.RemotePieces[1] = &pb.RemotePiece{}
|
|
|
|
|
|
|
|
require.NoError(t, irreparabledb.IncrementRepairAttempts(ctx, seg))
|
|
|
|
require.NoError(t, checker.IrreparableProcess(ctx))
|
|
|
|
|
|
|
|
result, err = irreparabledb.Get(ctx, metabase.SegmentKey(seg.GetPath()))
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, result)
|
|
|
|
|
|
|
|
injured, err := queue.Select(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, seg.GetPath(), injured.GetPath())
|
|
|
|
|
|
|
|
n, err := queue.Clean(ctx, time.Now())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, 1, n)
|
|
|
|
|
|
|
|
// test irreparable segment remains in irreparable DB and repair_attempt_count is incremented
|
|
|
|
seg.SegmentDetail.Remote.RemotePieces[2] = &pb.RemotePiece{}
|
|
|
|
|
|
|
|
require.NoError(t, irreparabledb.IncrementRepairAttempts(ctx, seg))
|
|
|
|
require.NoError(t, checker.IrreparableProcess(ctx))
|
|
|
|
|
|
|
|
result, err = irreparabledb.Get(ctx, metabase.SegmentKey(seg.GetPath()))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, seg.GetPath(), result.Path)
|
|
|
|
require.Equal(t, seg.RepairAttemptCount+1, result.RepairAttemptCount)
|
|
|
|
})
|
|
|
|
}
|