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 (
|
|
|
|
"testing"
|
2018-10-30 19:16:40 +00:00
|
|
|
"time"
|
2018-10-09 17:09:33 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-11-29 14:57:00 +00:00
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
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-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-01-30 18:34:44 +00:00
|
|
|
// TODO note satellite's: own sub-systems need to be disabled
|
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) {
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
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.Identity.ID,
|
|
|
|
})
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
pointer := &pb.Pointer{
|
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
|
|
|
MinReq: int32(4),
|
|
|
|
RepairThreshold: int32(8),
|
|
|
|
},
|
|
|
|
PieceId: "fake-piece-id",
|
|
|
|
RemotePieces: pieces,
|
2018-10-09 17:09:33 +01:00
|
|
|
},
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
2018-10-09 17:09:33 +01:00
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
// put test pointer to db
|
|
|
|
pointerdb := planet.Satellites[0].Metainfo.Service
|
|
|
|
err := pointerdb.Put(pointer.Remote.PieceId, pointer)
|
|
|
|
assert.NoError(t, err)
|
2018-10-09 17:09:33 +01:00
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
//check if the expected segments were added to the queue
|
|
|
|
repairQueue := planet.Satellites[0].DB.RepairQueue()
|
|
|
|
injuredSegment, err := repairQueue.Dequeue(ctx)
|
|
|
|
assert.NoError(t, err)
|
2018-12-06 18:51:23 +00:00
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
assert.Equal(t, "fake-piece-id", injuredSegment.Path)
|
|
|
|
assert.Equal(t, len(expectedLostPieces), len(injuredSegment.LostPieces))
|
|
|
|
for _, lostPiece := range injuredSegment.LostPieces {
|
|
|
|
if !expectedLostPieces[lostPiece] {
|
|
|
|
t.Error("should be lost: ", lostPiece)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-10-09 17:09:33 +01:00
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
func TestOfflineNodes(t *testing.T) {
|
2019-02-06 13:03:38 +00:00
|
|
|
// TODO note satellite's: own sub-systems need to be disabled
|
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) {
|
|
|
|
time.Sleep(2 * time.Second)
|
2018-10-09 17:09:33 +01:00
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
const numberOfNodes = 10
|
|
|
|
nodeIDs := storj.NodeIDList{}
|
2018-12-06 18:51:23 +00:00
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
// use online nodes
|
|
|
|
for _, storagenode := range planet.StorageNodes {
|
|
|
|
nodeIDs = append(nodeIDs, storagenode.Identity.ID)
|
|
|
|
}
|
2018-10-09 17:09:33 +01:00
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
// simulate offline nodes
|
|
|
|
expectedOffline := make([]int32, 0)
|
|
|
|
for i := len(nodeIDs); i < numberOfNodes; i++ {
|
|
|
|
nodeIDs = append(nodeIDs, storj.NodeID{byte(i)})
|
|
|
|
expectedOffline = append(expectedOffline, int32(i))
|
2018-10-09 17:09:33 +01:00
|
|
|
}
|
2019-02-05 16:00:52 +00:00
|
|
|
|
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
|
|
|
offline, err := checker.OfflineNodes(ctx, nodeIDs)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expectedOffline, offline)
|
|
|
|
})
|
2018-10-09 17:09:33 +01:00
|
|
|
}
|
2019-02-06 13:03:38 +00:00
|
|
|
|
|
|
|
func TestIdentifyIrreparableSegments(t *testing.T) {
|
|
|
|
// TODO note satellite's: own sub-systems need to be disabled
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 3, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
pointer := &pb.Pointer{
|
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
|
|
|
MinReq: int32(4),
|
|
|
|
RepairThreshold: int32(8),
|
|
|
|
},
|
|
|
|
PieceId: "fake-piece-id",
|
|
|
|
RemotePieces: pieces,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// put test pointer to db
|
|
|
|
pointerdb := planet.Satellites[0].Metainfo.Service
|
|
|
|
err := pointerdb.Put(pointer.Remote.PieceId, pointer)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// check if nothing was added to repair queue
|
|
|
|
repairQueue := planet.Satellites[0].DB.RepairQueue()
|
|
|
|
_, err = repairQueue.Dequeue(ctx)
|
|
|
|
assert.True(t, storage.ErrEmptyQueue.Has(err))
|
|
|
|
|
|
|
|
//check if the expected segments were added to the irreparable DB
|
|
|
|
irreparable := planet.Satellites[0].DB.Irreparable()
|
|
|
|
remoteSegmentInfo, err := irreparable.Get(ctx, []byte("fake-piece-id"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, len(expectedLostPieces), int(remoteSegmentInfo.LostPiecesCount))
|
|
|
|
assert.Equal(t, 1, int(remoteSegmentInfo.RepairAttemptCount))
|
|
|
|
firstRepair := remoteSegmentInfo.RepairUnixSec
|
|
|
|
|
|
|
|
// check irreparable once again but wait a second
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
remoteSegmentInfo, err = irreparable.Get(ctx, []byte("fake-piece-id"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, len(expectedLostPieces), int(remoteSegmentInfo.LostPiecesCount))
|
|
|
|
// check if repair attempt count was incremented
|
|
|
|
assert.Equal(t, 2, int(remoteSegmentInfo.RepairAttemptCount))
|
|
|
|
assert.True(t, firstRepair < remoteSegmentInfo.RepairUnixSec)
|
|
|
|
})
|
|
|
|
}
|