2018-10-02 20:46:29 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
//TODO: reenable
|
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
package checker_test
|
2018-10-09 17:09:33 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"sort"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2018-10-30 19:16:40 +00:00
|
|
|
"time"
|
2018-10-09 17:09:33 +01:00
|
|
|
|
2018-11-20 18:29:07 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2018-10-09 17:09:33 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-01-18 13:54:08 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
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-11-29 18:39:27 +00:00
|
|
|
"storj.io/storj/internal/teststorj"
|
2018-10-11 21:25:54 +01:00
|
|
|
"storj.io/storj/pkg/auth"
|
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"
|
2018-12-10 19:08:45 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb"
|
2018-10-09 17:09:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIdentifyInjuredSegments(t *testing.T) {
|
2019-01-18 13:54:08 +00:00
|
|
|
t.Skip("needs update")
|
|
|
|
|
|
|
|
// logic should be roughly:
|
|
|
|
// use storagenodes as the valid and
|
|
|
|
// generate invalid ids
|
|
|
|
// identify should then find the invalid ones
|
|
|
|
// note satellite's: own sub-systems need to be disabled
|
|
|
|
|
|
|
|
tctx := testcontext.New(t)
|
|
|
|
defer tctx.Cleanup()
|
|
|
|
|
|
|
|
planet, err := testplanet.New(t, 1, 4, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer tctx.Check(planet.Shutdown)
|
|
|
|
|
|
|
|
planet.Start(tctx)
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
|
|
|
pointerdb := planet.Satellites[0].Metainfo.Endpoint
|
|
|
|
repairQueue := planet.Satellites[0].DB.RepairQueue()
|
2018-12-06 18:51:23 +00:00
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
ctx := auth.WithAPIKey(tctx, nil)
|
2018-10-09 17:09:33 +01:00
|
|
|
|
|
|
|
const N = 25
|
|
|
|
nodes := []*pb.Node{}
|
|
|
|
segs := []*pb.InjuredSegment{}
|
|
|
|
//fill a pointerdb
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
s := strconv.Itoa(i)
|
2018-11-29 18:39:27 +00:00
|
|
|
ids := teststorj.NodeIDsFromStrings([]string{s + "a", s + "b", s + "c", s + "d"}...)
|
2018-10-09 17:09:33 +01:00
|
|
|
|
|
|
|
p := &pb.Pointer{
|
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
|
|
|
RepairThreshold: int32(2),
|
|
|
|
},
|
|
|
|
PieceId: strconv.Itoa(i),
|
|
|
|
RemotePieces: []*pb.RemotePiece{
|
|
|
|
{PieceNum: 0, NodeId: ids[0]},
|
|
|
|
{PieceNum: 1, NodeId: ids[1]},
|
|
|
|
{PieceNum: 2, NodeId: ids[2]},
|
|
|
|
{PieceNum: 3, NodeId: ids[3]},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2018-10-09 17:09:33 +01:00
|
|
|
req := &pb.PutRequest{
|
|
|
|
Path: p.Remote.PieceId,
|
|
|
|
Pointer: p,
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2018-10-09 17:09:33 +01:00
|
|
|
resp, err := pointerdb.Put(ctx, req)
|
|
|
|
assert.NotNil(t, resp)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
//nodes for cache
|
|
|
|
selection := rand.Intn(4)
|
|
|
|
for _, v := range ids[:selection] {
|
2018-11-29 18:39:27 +00:00
|
|
|
n := &pb.Node{Id: v, Type: pb.NodeType_STORAGE, Address: &pb.NodeAddress{Address: ""}}
|
2018-10-09 17:09:33 +01:00
|
|
|
nodes = append(nodes, n)
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2018-10-09 17:09:33 +01:00
|
|
|
pieces := []int32{0, 1, 2, 3}
|
|
|
|
//expected injured segments
|
|
|
|
if len(ids[:selection]) < int(p.Remote.Redundancy.RepairThreshold) {
|
|
|
|
seg := &pb.InjuredSegment{
|
|
|
|
Path: p.Remote.PieceId,
|
|
|
|
LostPieces: pieces[selection:],
|
|
|
|
}
|
|
|
|
segs = append(segs, seg)
|
|
|
|
}
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
|
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
2018-12-04 16:26:30 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-18 13:54:08 +00:00
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
2018-10-09 17:09:33 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
expected := map[string]*pb.InjuredSegment{}
|
|
|
|
for _, seg := range segs {
|
|
|
|
expected[seg.Path] = seg
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:09:33 +01:00
|
|
|
//check if the expected segments were added to the queue
|
|
|
|
dequeued := []*pb.InjuredSegment{}
|
|
|
|
for i := 0; i < len(segs); i++ {
|
2018-12-27 09:56:25 +00:00
|
|
|
injSeg, err := repairQueue.Dequeue(ctx)
|
2018-10-09 17:09:33 +01:00
|
|
|
assert.NoError(t, err)
|
2019-01-18 13:54:08 +00:00
|
|
|
|
|
|
|
if _, ok := expected[injSeg.Path]; ok {
|
|
|
|
t.Log("got", injSeg.Path)
|
|
|
|
delete(expected, injSeg.Path)
|
|
|
|
} else {
|
|
|
|
t.Error("unexpected", injSeg)
|
|
|
|
}
|
2018-10-09 17:09:33 +01:00
|
|
|
dequeued = append(dequeued, &injSeg)
|
|
|
|
}
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
for _, missing := range expected {
|
|
|
|
t.Error("did not get", missing)
|
2018-10-09 17:09:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 16:18:28 +00:00
|
|
|
func TestOfflineNodes(t *testing.T) {
|
2019-01-18 13:54:08 +00:00
|
|
|
t.Skip("needs update")
|
|
|
|
|
|
|
|
tctx := testcontext.New(t)
|
|
|
|
defer tctx.Cleanup()
|
|
|
|
|
|
|
|
planet, err := testplanet.New(t, 1, 0, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer tctx.Check(planet.Shutdown)
|
|
|
|
|
|
|
|
planet.Start(tctx)
|
|
|
|
time.Sleep(2 * time.Second)
|
2018-12-06 18:51:23 +00:00
|
|
|
|
2018-10-09 17:09:33 +01:00
|
|
|
const N = 50
|
|
|
|
nodes := []*pb.Node{}
|
2018-11-29 18:39:27 +00:00
|
|
|
nodeIDs := storj.NodeIDList{}
|
2018-10-09 17:09:33 +01:00
|
|
|
expectedOffline := []int32{}
|
|
|
|
for i := 0; i < N; i++ {
|
2018-11-29 18:39:27 +00:00
|
|
|
id := teststorj.NodeIDFromString(strconv.Itoa(i))
|
|
|
|
n := &pb.Node{Id: id, Type: pb.NodeType_STORAGE, Address: &pb.NodeAddress{Address: ""}}
|
2018-10-09 17:09:33 +01:00
|
|
|
nodes = append(nodes, n)
|
|
|
|
if i%(rand.Intn(5)+2) == 0 {
|
2018-11-29 18:39:27 +00:00
|
|
|
nodeIDs = append(nodeIDs, teststorj.NodeIDFromString("id"+id.String()))
|
2018-10-09 17:09:33 +01:00
|
|
|
expectedOffline = append(expectedOffline, int32(i))
|
|
|
|
} else {
|
|
|
|
nodeIDs = append(nodeIDs, id)
|
|
|
|
}
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
|
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
2018-12-04 16:26:30 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-18 13:54:08 +00:00
|
|
|
offline, err := checker.OfflineNodes(tctx, nodeIDs)
|
2018-10-09 17:09:33 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expectedOffline, offline)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIdentifyInjuredSegments(b *testing.B) {
|
2019-01-18 13:54:08 +00:00
|
|
|
b.Skip("needs update")
|
|
|
|
|
|
|
|
tctx := testcontext.New(b)
|
|
|
|
defer tctx.Cleanup()
|
|
|
|
|
|
|
|
planet, err := testplanet.New(b, 1, 0, 0)
|
|
|
|
require.NoError(b, err)
|
|
|
|
defer tctx.Check(planet.Shutdown)
|
|
|
|
|
|
|
|
planet.Start(tctx)
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
|
|
|
pointerdb := planet.Satellites[0].Metainfo.Endpoint
|
|
|
|
repairQueue := planet.Satellites[0].DB.RepairQueue()
|
|
|
|
|
|
|
|
ctx := auth.WithAPIKey(tctx, nil)
|
2018-12-06 18:51:23 +00:00
|
|
|
|
2018-12-10 19:08:45 +00:00
|
|
|
// creating in-memory db and opening connection
|
2018-12-11 09:30:09 +00:00
|
|
|
db, err := satellitedb.NewInMemory()
|
2018-12-04 16:26:30 +00:00
|
|
|
defer func() {
|
2018-12-10 19:08:45 +00:00
|
|
|
err = db.Close()
|
2018-12-04 16:26:30 +00:00
|
|
|
assert.NoError(b, err)
|
|
|
|
}()
|
2018-12-10 19:08:45 +00:00
|
|
|
err = db.CreateTables()
|
|
|
|
assert.NoError(b, err)
|
2018-10-09 17:09:33 +01:00
|
|
|
|
|
|
|
const N = 25
|
|
|
|
nodes := []*pb.Node{}
|
|
|
|
segs := []*pb.InjuredSegment{}
|
|
|
|
//fill a pointerdb
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
s := strconv.Itoa(i)
|
2018-11-29 18:39:27 +00:00
|
|
|
ids := teststorj.NodeIDsFromStrings([]string{s + "a", s + "b", s + "c", s + "d"}...)
|
2018-10-09 17:09:33 +01:00
|
|
|
|
|
|
|
p := &pb.Pointer{
|
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
|
|
|
RepairThreshold: int32(2),
|
|
|
|
},
|
|
|
|
PieceId: strconv.Itoa(i),
|
|
|
|
RemotePieces: []*pb.RemotePiece{
|
|
|
|
{PieceNum: 0, NodeId: ids[0]},
|
|
|
|
{PieceNum: 1, NodeId: ids[1]},
|
|
|
|
{PieceNum: 2, NodeId: ids[2]},
|
|
|
|
{PieceNum: 3, NodeId: ids[3]},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
req := &pb.PutRequest{
|
|
|
|
Path: p.Remote.PieceId,
|
|
|
|
Pointer: p,
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2018-10-09 17:09:33 +01:00
|
|
|
resp, err := pointerdb.Put(ctx, req)
|
|
|
|
assert.NotNil(b, resp)
|
|
|
|
assert.NoError(b, err)
|
|
|
|
|
|
|
|
//nodes for cache
|
|
|
|
selection := rand.Intn(4)
|
|
|
|
for _, v := range ids[:selection] {
|
2018-11-29 18:39:27 +00:00
|
|
|
n := &pb.Node{Id: v, Type: pb.NodeType_STORAGE, Address: &pb.NodeAddress{Address: ""}}
|
2018-10-09 17:09:33 +01:00
|
|
|
nodes = append(nodes, n)
|
|
|
|
}
|
|
|
|
pieces := []int32{0, 1, 2, 3}
|
|
|
|
//expected injured segments
|
|
|
|
if len(ids[:selection]) < int(p.Remote.Redundancy.RepairThreshold) {
|
|
|
|
seg := &pb.InjuredSegment{
|
|
|
|
Path: p.Remote.PieceId,
|
|
|
|
LostPieces: pieces[selection:],
|
|
|
|
}
|
|
|
|
segs = append(segs, seg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//fill a overlay cache
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2019-01-18 13:54:08 +00:00
|
|
|
checker := planet.Satellites[0].Repair.Checker
|
2018-12-04 16:26:30 +00:00
|
|
|
assert.NoError(b, err)
|
2018-12-06 18:51:23 +00:00
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
err = checker.IdentifyInjuredSegments(ctx)
|
2018-10-09 17:09:33 +01:00
|
|
|
assert.NoError(b, err)
|
|
|
|
|
|
|
|
//check if the expected segments were added to the queue
|
|
|
|
dequeued := []*pb.InjuredSegment{}
|
|
|
|
for i := 0; i < len(segs); i++ {
|
2018-12-27 09:56:25 +00:00
|
|
|
injSeg, err := repairQueue.Dequeue(ctx)
|
2018-10-09 17:09:33 +01:00
|
|
|
assert.NoError(b, err)
|
|
|
|
dequeued = append(dequeued, &injSeg)
|
|
|
|
}
|
|
|
|
sort.Slice(segs, func(i, k int) bool { return segs[i].Path < segs[k].Path })
|
|
|
|
sort.Slice(dequeued, func(i, k int) bool { return dequeued[i].Path < dequeued[k].Path })
|
|
|
|
|
|
|
|
for i := 0; i < len(segs); i++ {
|
|
|
|
assert.True(b, proto.Equal(segs[i], dequeued[i]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|