2019-10-07 21:38:05 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package gracefulexit_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-10-24 17:24:42 +01:00
|
|
|
"go.uber.org/zap"
|
2019-10-07 21:38:05 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"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"
|
2019-10-07 21:38:05 +01:00
|
|
|
"storj.io/storj/satellite"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2019-10-07 21:38:05 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestChore(t *testing.T) {
|
2019-10-24 17:24:42 +01:00
|
|
|
var maximumInactiveTimeFrame = time.Second * 1
|
2019-10-07 21:38:05 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 8,
|
|
|
|
UplinkCount: 1,
|
2019-10-24 17:24:42 +01:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
2020-11-10 11:56:30 +00:00
|
|
|
Satellite: testplanet.Combine(
|
|
|
|
func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.GracefulExit.MaxInactiveTimeFrame = maximumInactiveTimeFrame
|
|
|
|
},
|
|
|
|
testplanet.ReconfigureRS(4, 6, 8, 8),
|
|
|
|
),
|
2019-10-24 17:24:42 +01:00
|
|
|
},
|
2019-10-07 21:38:05 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
uplinkPeer := planet.Uplinks[0]
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
exitingNode := planet.StorageNodes[1]
|
|
|
|
|
2021-02-10 10:15:19 +00:00
|
|
|
project, err := uplinkPeer.GetProject(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() { require.NoError(t, project.Close()) }()
|
|
|
|
|
|
|
|
err = uplinkPeer.Upload(ctx, satellite, "testbucket", "test/path1", testrand.Bytes(5*memory.KiB))
|
2019-10-07 21:38:05 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
err = uplinkPeer.Upload(ctx, satellite, "testbucket", "test/path2", testrand.Bytes(5*memory.KiB))
|
2019-10-07 21:38:05 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-20 09:06:56 +01:00
|
|
|
info, err := project.BeginUpload(ctx, "testbucket", "test/path3", nil)
|
2021-02-10 10:15:19 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-20 09:06:56 +01:00
|
|
|
upload, err := project.UploadPart(ctx, "testbucket", "test/path3", info.UploadID, 1)
|
2021-02-10 10:15:19 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-20 09:06:56 +01:00
|
|
|
_, err = upload.Write(testrand.Bytes(5 * memory.KiB))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, upload.Commit())
|
|
|
|
|
2019-10-24 17:24:42 +01:00
|
|
|
exitStatusRequest := overlay.ExitStatusRequest{
|
2019-10-07 21:38:05 +01:00
|
|
|
NodeID: exitingNode.ID(),
|
2020-03-10 22:05:01 +00:00
|
|
|
ExitInitiatedAt: time.Now(),
|
2019-10-07 21:38:05 +01:00
|
|
|
}
|
|
|
|
|
2019-10-24 17:24:42 +01:00
|
|
|
_, err = satellite.Overlay.DB.UpdateExitStatus(ctx, &exitStatusRequest)
|
2019-10-07 21:38:05 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-24 17:24:42 +01:00
|
|
|
exitingNodes, err := satellite.Overlay.DB.GetExitingNodes(ctx)
|
2019-10-07 21:38:05 +01:00
|
|
|
require.NoError(t, err)
|
2019-10-24 17:24:42 +01:00
|
|
|
nodeIDs := make(storj.NodeIDList, 0, len(exitingNodes))
|
|
|
|
for _, exitingNode := range exitingNodes {
|
|
|
|
if exitingNode.ExitLoopCompletedAt == nil {
|
|
|
|
nodeIDs = append(nodeIDs, exitingNode.NodeID)
|
|
|
|
}
|
|
|
|
}
|
2019-10-07 21:38:05 +01:00
|
|
|
require.Len(t, nodeIDs, 1)
|
|
|
|
|
2023-04-24 10:10:00 +01:00
|
|
|
// run the satellite ranged loop to build the transfer queue.
|
|
|
|
_, err = satellite.RangedLoop.RangedLoop.Service.RunOnce(ctx)
|
|
|
|
require.NoError(t, err)
|
2019-10-07 21:38:05 +01:00
|
|
|
|
2021-09-05 22:29:22 +01:00
|
|
|
incompleteTransfers, err := satellite.DB.GracefulExit().GetIncomplete(ctx, exitingNode.ID(), 20, 0)
|
2019-10-07 21:38:05 +01:00
|
|
|
require.NoError(t, err)
|
2021-02-10 10:15:19 +00:00
|
|
|
require.Len(t, incompleteTransfers, 3)
|
2019-10-07 21:38:05 +01:00
|
|
|
for _, incomplete := range incompleteTransfers {
|
|
|
|
require.True(t, incomplete.DurabilityRatio > 0)
|
2019-11-07 16:13:05 +00:00
|
|
|
require.NotNil(t, incomplete.RootPieceID)
|
2019-10-07 21:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// test the other nodes don't have anything to transfer
|
2020-05-07 09:23:40 +01:00
|
|
|
for _, node := range planet.StorageNodes {
|
|
|
|
if node.ID() == exitingNode.ID() {
|
2019-10-07 21:38:05 +01:00
|
|
|
continue
|
|
|
|
}
|
2021-09-05 22:29:22 +01:00
|
|
|
incompleteTransfers, err := satellite.DB.GracefulExit().GetIncomplete(ctx, node.ID(), 20, 0)
|
2019-10-07 21:38:05 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, incompleteTransfers, 0)
|
|
|
|
}
|
|
|
|
|
2019-10-24 17:24:42 +01:00
|
|
|
exitingNodes, err = satellite.Overlay.DB.GetExitingNodes(ctx)
|
2019-10-07 21:38:05 +01:00
|
|
|
require.NoError(t, err)
|
2019-10-24 17:24:42 +01:00
|
|
|
nodeIDs = make(storj.NodeIDList, 0, len(exitingNodes))
|
|
|
|
for _, exitingNode := range exitingNodes {
|
|
|
|
if exitingNode.ExitLoopCompletedAt == nil {
|
|
|
|
nodeIDs = append(nodeIDs, exitingNode.NodeID)
|
|
|
|
}
|
|
|
|
}
|
2019-10-07 21:38:05 +01:00
|
|
|
require.Len(t, nodeIDs, 0)
|
2019-10-24 17:24:42 +01:00
|
|
|
|
|
|
|
err = satellite.DB.GracefulExit().IncrementProgress(ctx, exitingNode.ID(), 0, 0, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-05 22:29:22 +01:00
|
|
|
incompleteTransfers, err = satellite.DB.GracefulExit().GetIncomplete(ctx, exitingNode.ID(), 20, 0)
|
2019-10-24 17:24:42 +01:00
|
|
|
require.NoError(t, err)
|
2021-02-10 10:15:19 +00:00
|
|
|
require.Len(t, incompleteTransfers, 3)
|
2019-10-24 17:24:42 +01:00
|
|
|
|
|
|
|
// node should fail graceful exit if it has been inactive for maximum inactive time frame since last activity
|
|
|
|
time.Sleep(maximumInactiveTimeFrame + time.Second*1)
|
2023-04-24 10:10:00 +01:00
|
|
|
// run the satellite ranged loop to build the transfer queue.
|
|
|
|
_, err = satellite.RangedLoop.RangedLoop.Service.RunOnce(ctx)
|
|
|
|
require.NoError(t, err)
|
2019-10-24 17:24:42 +01:00
|
|
|
|
|
|
|
exitStatus, err := satellite.Overlay.DB.GetExitStatus(ctx, exitingNode.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, exitStatus.ExitSuccess)
|
|
|
|
require.NotNil(t, exitStatus.ExitFinishedAt)
|
|
|
|
|
2021-09-05 22:29:22 +01:00
|
|
|
incompleteTransfers, err = satellite.DB.GracefulExit().GetIncomplete(ctx, exitingNode.ID(), 20, 0)
|
2019-10-24 17:24:42 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, incompleteTransfers, 0)
|
|
|
|
|
2019-10-07 21:38:05 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-09 21:28:05 +00:00
|
|
|
func TestChoreDurabilityRatio(t *testing.T) {
|
2020-01-21 10:38:41 +00:00
|
|
|
const (
|
|
|
|
maximumInactiveTimeFrame = time.Second * 1
|
|
|
|
successThreshold = 4
|
|
|
|
)
|
2019-11-26 17:04:48 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 4,
|
|
|
|
UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
2020-11-10 11:56:30 +00:00
|
|
|
Satellite: testplanet.Combine(
|
|
|
|
func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.GracefulExit.MaxInactiveTimeFrame = maximumInactiveTimeFrame
|
|
|
|
},
|
|
|
|
testplanet.ReconfigureRS(2, 3, successThreshold, 4),
|
|
|
|
),
|
2019-11-26 17:04:48 +00:00
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
uplinkPeer := planet.Uplinks[0]
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
nodeToRemove := planet.StorageNodes[0]
|
|
|
|
exitingNode := planet.StorageNodes[1]
|
|
|
|
|
2021-02-10 10:15:19 +00:00
|
|
|
project, err := uplinkPeer.GetProject(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() { require.NoError(t, project.Close()) }()
|
2019-11-26 17:04:48 +00:00
|
|
|
|
2021-02-10 10:15:19 +00:00
|
|
|
err = uplinkPeer.Upload(ctx, satellite, "testbucket", "test/path1", testrand.Bytes(5*memory.KiB))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-20 09:06:56 +01:00
|
|
|
info, err := project.BeginUpload(ctx, "testbucket", "test/path2", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
upload, err := project.UploadPart(ctx, "testbucket", "test/path2", info.UploadID, 1)
|
2021-02-10 10:15:19 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-20 09:06:56 +01:00
|
|
|
_, err = upload.Write(testrand.Bytes(5 * memory.KiB))
|
2019-11-26 17:04:48 +00:00
|
|
|
require.NoError(t, err)
|
2021-04-20 09:06:56 +01:00
|
|
|
require.NoError(t, upload.Commit())
|
2019-11-26 17:04:48 +00:00
|
|
|
|
|
|
|
exitStatusRequest := overlay.ExitStatusRequest{
|
|
|
|
NodeID: exitingNode.ID(),
|
2020-03-10 22:05:01 +00:00
|
|
|
ExitInitiatedAt: time.Now(),
|
2019-11-26 17:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = satellite.Overlay.DB.UpdateExitStatus(ctx, &exitStatusRequest)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
exitingNodes, err := satellite.Overlay.DB.GetExitingNodes(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
nodeIDs := make(storj.NodeIDList, 0, len(exitingNodes))
|
|
|
|
for _, exitingNode := range exitingNodes {
|
|
|
|
if exitingNode.ExitLoopCompletedAt == nil {
|
|
|
|
nodeIDs = append(nodeIDs, exitingNode.NodeID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.Len(t, nodeIDs, 1)
|
|
|
|
|
|
|
|
// retrieve remote segment
|
2021-09-07 09:15:47 +01:00
|
|
|
segments, err := satellite.Metabase.DB.TestingAllSegments(ctx)
|
2019-11-26 17:04:48 +00:00
|
|
|
require.NoError(t, err)
|
2021-02-10 10:15:19 +00:00
|
|
|
require.Len(t, segments, 2)
|
|
|
|
|
|
|
|
for _, segment := range segments {
|
|
|
|
remotePieces := segment.Pieces
|
|
|
|
var newPieces metabase.Pieces = make(metabase.Pieces, len(remotePieces)-1)
|
|
|
|
idx := 0
|
|
|
|
for _, p := range remotePieces {
|
|
|
|
if p.StorageNode != nodeToRemove.ID() {
|
|
|
|
newPieces[idx] = p
|
|
|
|
idx++
|
|
|
|
}
|
2019-11-26 17:04:48 +00:00
|
|
|
}
|
2021-09-07 09:15:47 +01:00
|
|
|
err = satellite.Metabase.DB.UpdateSegmentPieces(ctx, metabase.UpdateSegmentPieces{
|
2021-02-10 10:15:19 +00:00
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
2020-12-16 16:47:31 +00:00
|
|
|
|
2021-03-12 11:23:44 +00:00
|
|
|
OldPieces: segment.Pieces,
|
|
|
|
NewPieces: newPieces,
|
|
|
|
NewRedundancy: segment.Redundancy,
|
2021-02-10 10:15:19 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2019-11-26 17:04:48 +00:00
|
|
|
|
2023-04-24 10:10:00 +01:00
|
|
|
// run the satellite ranged loop to build the transfer queue.
|
|
|
|
_, err = satellite.RangedLoop.RangedLoop.Service.RunOnce(ctx)
|
|
|
|
require.NoError(t, err)
|
2019-11-26 17:04:48 +00:00
|
|
|
|
2021-09-05 22:29:22 +01:00
|
|
|
incompleteTransfers, err := satellite.DB.GracefulExit().GetIncomplete(ctx, exitingNode.ID(), 20, 0)
|
2019-11-26 17:04:48 +00:00
|
|
|
require.NoError(t, err)
|
2021-02-10 10:15:19 +00:00
|
|
|
require.Len(t, incompleteTransfers, 2)
|
2019-11-26 17:04:48 +00:00
|
|
|
for _, incomplete := range incompleteTransfers {
|
2020-01-21 10:38:41 +00:00
|
|
|
require.Equal(t, float64(successThreshold-1)/float64(successThreshold), incomplete.DurabilityRatio)
|
2019-11-26 17:04:48 +00:00
|
|
|
require.NotNil(t, incomplete.RootPieceID)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|