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 (
|
2020-09-09 21:52:22 +01:00
|
|
|
"bytes"
|
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
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2020-09-03 14:54:56 +01:00
|
|
|
"storj.io/storj/satellite/metainfo/metabase"
|
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
|
|
|
|
2020-04-02 15:18:08 +01:00
|
|
|
projectID := testrand.UUID()
|
2019-09-12 11:38:49 +01:00
|
|
|
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++ {
|
2020-04-15 20:20:16 +01:00
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+fmt.Sprintf("a-%d", x), false, time.Time{})
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
2019-10-04 11:05:25 +01:00
|
|
|
|
|
|
|
// add pointer that needs repair
|
2020-04-15 20:20:16 +01:00
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+"b-0", true, time.Time{})
|
|
|
|
|
|
|
|
// add pointer that is unhealthy, but is expired
|
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+"b-1", true, time.Now().Add(-time.Hour))
|
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++ {
|
2020-04-15 20:20:16 +01:00
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+fmt.Sprintf("c-%d", x), false, time.Time{})
|
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
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
// check that the unhealthy, non-expired segment was added to the queue
|
|
|
|
// and that the expired segment was ignored
|
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
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
require.Equal(t, []byte(pointerPathPrefix+"b-0"), 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
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-09-08 11:13:18 +01:00
|
|
|
projectID := testrand.UUID()
|
|
|
|
pointerLocation := metabase.SegmentLocation{
|
|
|
|
ProjectID: projectID,
|
|
|
|
BucketName: "bucket",
|
|
|
|
Index: metabase.LastSegmentIndex,
|
|
|
|
ObjectKey: "piece",
|
|
|
|
}
|
|
|
|
|
|
|
|
pointerKey := pointerLocation.Encode()
|
|
|
|
pointerLocation.ObjectKey += "-expired"
|
|
|
|
pointerExpiredKey := pointerLocation.Encode()
|
2019-02-06 13:03:38 +00:00
|
|
|
// put test pointer to db
|
2019-04-25 09:46:32 +01:00
|
|
|
metainfo := planet.Satellites[0].Metainfo.Service
|
2020-09-08 11:13:18 +01:00
|
|
|
err := metainfo.Put(ctx, pointerKey, pointer)
|
2019-04-16 19:14:09 +01:00
|
|
|
require.NoError(t, err)
|
2020-04-15 20:20:16 +01:00
|
|
|
// modify pointer to make it expired and put to db
|
|
|
|
pointer.ExpirationDate = time.Now().Add(-time.Hour)
|
2020-09-08 11:13:18 +01:00
|
|
|
err = metainfo.Put(ctx, pointerExpiredKey, pointer)
|
2020-04-15 20:20:16 +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()
|
2020-09-08 11:13:18 +01:00
|
|
|
remoteSegmentInfo, err := irreparable.Get(ctx, pointerKey)
|
2019-04-16 19:14:09 +01:00
|
|
|
require.NoError(t, err)
|
2020-04-15 20:20:16 +01:00
|
|
|
// check that the expired segment was not added to the irreparable DB
|
2020-09-08 11:13:18 +01:00
|
|
|
_, err = irreparable.Get(ctx, pointerExpiredKey)
|
2020-04-15 20:20:16 +01:00
|
|
|
require.Error(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
|
|
|
|
2020-09-08 11:13:18 +01:00
|
|
|
remoteSegmentInfo, err = irreparable.Get(ctx, pointerKey)
|
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
|
2020-09-08 11:13:18 +01:00
|
|
|
err = metainfo.UnsynchronizedDelete(ctx, pointerKey)
|
2019-07-25 17:59:46 +01:00
|
|
|
require.NoError(t, err)
|
2020-09-08 11:13:18 +01:00
|
|
|
err = metainfo.Put(ctx, pointerKey, pointer)
|
2019-05-30 16:18:20 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-08 11:13:18 +01:00
|
|
|
_, err = irreparable.Get(ctx, pointerKey)
|
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
|
|
|
|
2020-09-09 21:52:22 +01:00
|
|
|
func TestCleanRepairQueue(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
|
|
|
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(4),
|
|
|
|
ErasureShareSize: int32(256),
|
|
|
|
}
|
|
|
|
|
|
|
|
projectID := testrand.UUID()
|
|
|
|
pointerPathPrefix := storj.JoinPaths(projectID.String(), "l", "bucket") + "/"
|
|
|
|
|
|
|
|
healthyCount := 5
|
|
|
|
for i := 0; i < healthyCount; i++ {
|
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+fmt.Sprintf("healthy-%d", i), false, time.Time{})
|
|
|
|
}
|
|
|
|
unhealthyCount := 5
|
|
|
|
for i := 0; i < unhealthyCount; i++ {
|
|
|
|
insertPointer(ctx, t, planet, rs, pointerPathPrefix+fmt.Sprintf("unhealthy-%d", i), true, time.Time{})
|
|
|
|
}
|
|
|
|
|
|
|
|
// suspend enough nodes to make healthy pointers unhealthy
|
|
|
|
for i := rs.MinReq; i < rs.SuccessThreshold; i++ {
|
|
|
|
require.NoError(t, planet.Satellites[0].Overlay.DB.SuspendNodeUnknownAudit(ctx, planet.StorageNodes[i].ID(), time.Now()))
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, planet.Satellites[0].Repair.Checker.RefreshReliabilityCache(ctx))
|
|
|
|
|
|
|
|
// check that repair queue is empty to avoid false positive
|
|
|
|
count, err := repairQueue.Count(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 0, count)
|
|
|
|
|
|
|
|
checker.Loop.TriggerWait()
|
|
|
|
|
|
|
|
// check that the pointers were put into the repair queue
|
|
|
|
// and not cleaned up at the end of the checker iteration
|
|
|
|
count, err = repairQueue.Count(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, healthyCount+unhealthyCount, count)
|
|
|
|
|
|
|
|
// unsuspend nodes to make the previously healthy pointers healthy again
|
|
|
|
for i := rs.MinReq; i < rs.SuccessThreshold; i++ {
|
|
|
|
require.NoError(t, planet.Satellites[0].Overlay.DB.UnsuspendNodeUnknownAudit(ctx, planet.StorageNodes[i].ID()))
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, planet.Satellites[0].Repair.Checker.RefreshReliabilityCache(ctx))
|
|
|
|
|
|
|
|
// The checker will not insert/update the now healthy segments causing
|
|
|
|
// them to be removed from the queue at the end of the checker iteration
|
|
|
|
checker.Loop.TriggerWait()
|
|
|
|
|
|
|
|
// only unhealthy segments should remain
|
|
|
|
count, err = repairQueue.Count(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, unhealthyCount, count)
|
|
|
|
|
|
|
|
segs, err := repairQueue.SelectN(ctx, count)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for _, s := range segs {
|
|
|
|
require.True(t, bytes.Contains(s.GetPath(), []byte("unhealthy")))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
func insertPointer(ctx context.Context, t *testing.T, planet *testplanet.Planet, rs *pb.RedundancyScheme, pointerPath string, createLost bool, expire time.Time) {
|
2019-10-04 11:05:25 +01:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
2020-04-15 20:20:16 +01:00
|
|
|
if !expire.IsZero() {
|
|
|
|
pointer.ExpirationDate = expire
|
|
|
|
}
|
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
|
2020-09-03 14:54:56 +01:00
|
|
|
err := pointerdb.Put(ctx, metabase.SegmentKey(pointerPath), pointer)
|
2019-02-14 12:33:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|