2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-10-02 20:46:29 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
package checker_test
|
2018-10-09 17:09:33 +01:00
|
|
|
|
|
|
|
import (
|
2019-05-08 18:59:50 +01:00
|
|
|
"context"
|
2019-02-14 12:33:41 +00:00
|
|
|
"fmt"
|
2018-10-09 17:09:33 +01:00
|
|
|
"testing"
|
2018-10-30 19:16:40 +00:00
|
|
|
"time"
|
2018-10-09 17:09:33 +01:00
|
|
|
|
2019-02-14 12:33:41 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-11-29 14:57:00 +00:00
|
|
|
|
2018-10-09 17:09:33 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-11-29 18:39:27 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/private/testrand"
|
2019-02-06 13:03:38 +00:00
|
|
|
"storj.io/storj/storage"
|
2018-10-09 17:09:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIdentifyInjuredSegments(t *testing.T) {
|
2019-02-05 16:00:52 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-02-11 21:06:39 +00:00
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
2019-10-04 11:05:25 +01:00
|
|
|
repairQueue := planet.Satellites[0].DB.RepairQueue()
|
|
|
|
|
|
|
|
checker.Loop.Pause()
|
|
|
|
planet.Satellites[0].Repair.Repairer.Loop.Pause()
|
|
|
|
|
|
|
|
rs := &pb.RedundancyScheme{
|
|
|
|
MinReq: int32(2),
|
|
|
|
RepairThreshold: int32(3),
|
|
|
|
SuccessThreshold: int32(4),
|
|
|
|
Total: int32(5),
|
|
|
|
ErasureShareSize: int32(256),
|
|
|
|
}
|
2019-02-05 16:00:52 +00:00
|
|
|
|
2019-09-12 11:38:49 +01:00
|
|
|
projectID := testrand.UUID()
|
|
|
|
pointerPathPrefix := storj.JoinPaths(projectID.String(), "l", "bucket") + "/"
|
|
|
|
|
2019-10-04 11:05:25 +01:00
|
|
|
// add some valid pointers
|
2019-07-18 17:21:21 +01:00
|
|
|
for x := 0; x < 10; x++ {
|
2019-10-04 11:05:25 +01:00
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+fmt.Sprintf("a-%d", x), false)
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
2019-10-04 11:05:25 +01:00
|
|
|
|
|
|
|
// add pointer that needs repair
|
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+"b", true)
|
|
|
|
|
|
|
|
// add some valid pointers
|
2019-07-18 17:21:21 +01:00
|
|
|
for x := 0; x < 10; x++ {
|
2019-10-04 11:05:25 +01:00
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+fmt.Sprintf("c-%d", x), false)
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
2019-10-04 11:05:25 +01:00
|
|
|
|
|
|
|
checker.Loop.TriggerWait()
|
2019-02-05 16:00:52 +00:00
|
|
|
|
|
|
|
//check if the expected segments were added to the queue
|
2019-04-16 19:14:09 +01:00
|
|
|
injuredSegment, err := repairQueue.Select(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = repairQueue.Delete(ctx, injuredSegment)
|
|
|
|
require.NoError(t, err)
|
2018-12-06 18:51:23 +00:00
|
|
|
|
2019-09-12 11:38:49 +01:00
|
|
|
require.Equal(t, []byte(pointerPathPrefix+"b"), injuredSegment.Path)
|
2019-10-04 11:05:25 +01:00
|
|
|
require.Equal(t, int(rs.SuccessThreshold-rs.MinReq), len(injuredSegment.LostPieces))
|
2019-02-05 16:00:52 +00:00
|
|
|
for _, lostPiece := range injuredSegment.LostPieces {
|
2019-10-04 11:05:25 +01:00
|
|
|
require.True(t, rs.MinReq <= lostPiece && lostPiece < rs.SuccessThreshold, fmt.Sprintf("%v", lostPiece))
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
2019-10-04 11:05:25 +01:00
|
|
|
|
|
|
|
_, err = repairQueue.Select(ctx)
|
|
|
|
require.Error(t, err)
|
2019-02-05 16:00:52 +00:00
|
|
|
})
|
|
|
|
}
|
2018-10-09 17:09:33 +01:00
|
|
|
|
2019-02-06 13:03:38 +00:00
|
|
|
func TestIdentifyIrreparableSegments(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 3, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-02-11 21:06:39 +00:00
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
2019-02-14 12:33:41 +00:00
|
|
|
checker.Loop.Stop()
|
2019-08-01 19:44:32 +01:00
|
|
|
checker.IrreparableLoop.Stop()
|
2019-02-06 13:03:38 +00:00
|
|
|
|
|
|
|
const numberOfNodes = 10
|
|
|
|
pieces := make([]*pb.RemotePiece, 0, numberOfNodes)
|
|
|
|
// use online nodes
|
|
|
|
for i, storagenode := range planet.StorageNodes {
|
|
|
|
pieces = append(pieces, &pb.RemotePiece{
|
|
|
|
PieceNum: int32(i),
|
|
|
|
NodeId: storagenode.ID(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// simulate offline nodes
|
|
|
|
expectedLostPieces := make(map[int32]bool)
|
|
|
|
for i := len(pieces); i < numberOfNodes; i++ {
|
|
|
|
pieces = append(pieces, &pb.RemotePiece{
|
|
|
|
PieceNum: int32(i),
|
|
|
|
NodeId: storj.NodeID{byte(i)},
|
|
|
|
})
|
|
|
|
expectedLostPieces[int32(i)] = true
|
|
|
|
}
|
2019-09-06 20:20:36 +01:00
|
|
|
|
2019-09-12 11:38:49 +01:00
|
|
|
projectID := testrand.UUID()
|
|
|
|
pointerPath := storj.JoinPaths(projectID.String(), "l", "bucket", "piece")
|
|
|
|
pieceID := testrand.PieceID()
|
|
|
|
|
2019-09-06 20:20:36 +01:00
|
|
|
// when number of healthy piece is less than minimum required number of piece in redundancy,
|
|
|
|
// the piece is considered irreparable and will be put into irreparable DB
|
2019-02-06 13:03:38 +00:00
|
|
|
pointer := &pb.Pointer{
|
2019-09-19 00:18:14 +01:00
|
|
|
Type: pb.Pointer_REMOTE,
|
2019-07-08 23:16:50 +01:00
|
|
|
CreationDate: time.Now(),
|
2019-02-06 13:03:38 +00:00
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
2019-09-24 08:01:48 +01:00
|
|
|
ErasureShareSize: int32(256),
|
2019-09-06 20:20:36 +01:00
|
|
|
MinReq: int32(4),
|
2019-06-19 21:13:11 +01:00
|
|
|
RepairThreshold: int32(8),
|
|
|
|
SuccessThreshold: int32(9),
|
|
|
|
Total: int32(10),
|
2019-02-06 13:03:38 +00:00
|
|
|
},
|
2019-09-12 11:38:49 +01:00
|
|
|
RootPieceId: pieceID,
|
2019-02-06 13:03:38 +00:00
|
|
|
RemotePieces: pieces,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// put test pointer to db
|
2019-04-25 09:46:32 +01:00
|
|
|
metainfo := planet.Satellites[0].Metainfo.Service
|
2019-09-12 11:38:49 +01:00
|
|
|
err := metainfo.Put(ctx, pointerPath, pointer)
|
2019-04-16 19:14:09 +01:00
|
|
|
require.NoError(t, err)
|
2019-02-06 13:03:38 +00:00
|
|
|
|
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
2019-04-16 19:14:09 +01:00
|
|
|
require.NoError(t, err)
|
2019-02-06 13:03:38 +00:00
|
|
|
|
|
|
|
// check if nothing was added to repair queue
|
|
|
|
repairQueue := planet.Satellites[0].DB.RepairQueue()
|
2019-04-16 19:14:09 +01:00
|
|
|
_, err = repairQueue.Select(ctx)
|
|
|
|
require.True(t, storage.ErrEmptyQueue.Has(err))
|
2019-02-06 13:03:38 +00:00
|
|
|
|
|
|
|
//check if the expected segments were added to the irreparable DB
|
|
|
|
irreparable := planet.Satellites[0].DB.Irreparable()
|
2019-09-12 11:38:49 +01:00
|
|
|
remoteSegmentInfo, err := irreparable.Get(ctx, []byte(pointerPath))
|
2019-04-16 19:14:09 +01:00
|
|
|
require.NoError(t, err)
|
2019-02-06 13:03:38 +00:00
|
|
|
|
2019-04-16 19:14:09 +01:00
|
|
|
require.Equal(t, len(expectedLostPieces), int(remoteSegmentInfo.LostPieces))
|
|
|
|
require.Equal(t, 1, int(remoteSegmentInfo.RepairAttemptCount))
|
2019-03-15 20:21:52 +00:00
|
|
|
firstRepair := remoteSegmentInfo.LastRepairAttempt
|
2019-02-06 13:03:38 +00:00
|
|
|
|
|
|
|
// check irreparable once again but wait a second
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
2019-04-16 19:14:09 +01:00
|
|
|
require.NoError(t, err)
|
2019-02-06 13:03:38 +00:00
|
|
|
|
2019-09-12 11:38:49 +01:00
|
|
|
remoteSegmentInfo, err = irreparable.Get(ctx, []byte(pointerPath))
|
2019-04-16 19:14:09 +01:00
|
|
|
require.NoError(t, err)
|
2019-02-06 13:03:38 +00:00
|
|
|
|
2019-04-16 19:14:09 +01:00
|
|
|
require.Equal(t, len(expectedLostPieces), int(remoteSegmentInfo.LostPieces))
|
2019-02-06 13:03:38 +00:00
|
|
|
// check if repair attempt count was incremented
|
2019-04-16 19:14:09 +01:00
|
|
|
require.Equal(t, 2, int(remoteSegmentInfo.RepairAttemptCount))
|
|
|
|
require.True(t, firstRepair < remoteSegmentInfo.LastRepairAttempt)
|
2019-05-30 16:18:20 +01:00
|
|
|
|
2019-07-25 17:59:46 +01:00
|
|
|
// make the pointer repairable
|
2019-05-30 16:18:20 +01:00
|
|
|
pointer = &pb.Pointer{
|
2019-09-19 00:18:14 +01:00
|
|
|
Type: pb.Pointer_REMOTE,
|
2019-07-08 23:16:50 +01:00
|
|
|
CreationDate: time.Now(),
|
2019-05-30 16:18:20 +01:00
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
2019-09-24 08:01:48 +01:00
|
|
|
ErasureShareSize: int32(256),
|
2019-06-19 21:13:11 +01:00
|
|
|
MinReq: int32(2),
|
|
|
|
RepairThreshold: int32(8),
|
|
|
|
SuccessThreshold: int32(9),
|
|
|
|
Total: int32(10),
|
2019-05-30 16:18:20 +01:00
|
|
|
},
|
2019-09-12 11:38:49 +01:00
|
|
|
RootPieceId: pieceID,
|
2019-05-30 16:18:20 +01:00
|
|
|
RemotePieces: pieces,
|
|
|
|
},
|
|
|
|
}
|
2019-07-25 17:59:46 +01:00
|
|
|
// update test pointer in db
|
2019-11-06 17:02:14 +00:00
|
|
|
err = metainfo.UnsynchronizedDelete(ctx, pointerPath)
|
2019-07-25 17:59:46 +01:00
|
|
|
require.NoError(t, err)
|
2019-09-12 11:38:49 +01:00
|
|
|
err = metainfo.Put(ctx, pointerPath, pointer)
|
2019-05-30 16:18:20 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-12 11:38:49 +01:00
|
|
|
_, err = irreparable.Get(ctx, []byte(pointerPath))
|
2019-05-30 16:18:20 +01:00
|
|
|
require.Error(t, err)
|
2019-02-06 13:03:38 +00:00
|
|
|
})
|
|
|
|
}
|
2019-02-14 12:33:41 +00:00
|
|
|
|
2019-10-04 11:05:25 +01:00
|
|
|
func insertPointer(ctx context.Context, t *testing.T, planet *testplanet.Planet, rs *pb.RedundancyScheme, pointerPath string, createLost bool) {
|
|
|
|
pieces := make([]*pb.RemotePiece, rs.SuccessThreshold)
|
|
|
|
if !createLost {
|
|
|
|
for i := range pieces {
|
|
|
|
pieces[i] = &pb.RemotePiece{
|
|
|
|
PieceNum: int32(i),
|
|
|
|
NodeId: planet.StorageNodes[i].Identity.ID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for i := range pieces[:rs.MinReq] {
|
|
|
|
pieces[i] = &pb.RemotePiece{
|
|
|
|
PieceNum: int32(i),
|
|
|
|
NodeId: planet.StorageNodes[i].Identity.ID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := rs.MinReq; i < rs.SuccessThreshold; i++ {
|
|
|
|
pieces[i] = &pb.RemotePiece{
|
|
|
|
PieceNum: i,
|
|
|
|
NodeId: storj.NodeID{byte(0xFF)},
|
|
|
|
}
|
2019-02-14 12:33:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-04 11:05:25 +01:00
|
|
|
|
2019-02-14 12:33:41 +00:00
|
|
|
pointer := &pb.Pointer{
|
2019-09-19 00:18:14 +01:00
|
|
|
Type: pb.Pointer_REMOTE,
|
2019-07-08 23:16:50 +01:00
|
|
|
CreationDate: time.Now(),
|
2019-02-14 12:33:41 +00:00
|
|
|
Remote: &pb.RemoteSegment{
|
2019-10-04 11:05:25 +01:00
|
|
|
Redundancy: rs,
|
2019-09-12 11:38:49 +01:00
|
|
|
RootPieceId: testrand.PieceID(),
|
2019-02-14 12:33:41 +00:00
|
|
|
RemotePieces: pieces,
|
|
|
|
},
|
|
|
|
}
|
2019-10-04 11:05:25 +01:00
|
|
|
|
2019-02-14 12:33:41 +00:00
|
|
|
// put test pointer to db
|
|
|
|
pointerdb := planet.Satellites[0].Metainfo.Service
|
2019-09-12 11:38:49 +01:00
|
|
|
err := pointerdb.Put(ctx, pointerPath, pointer)
|
2019-02-14 12:33:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|