2019-10-30 17:40:57 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package gracefulexit_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
|
2020-01-08 02:33:41 +00:00
|
|
|
"storj.io/common/errs2"
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
2020-01-08 02:33:41 +00:00
|
|
|
"storj.io/common/rpc/rpcstatus"
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testblobs"
|
|
|
|
"storj.io/storj/private/testplanet"
|
2020-01-08 02:33:41 +00:00
|
|
|
"storj.io/storj/satellite"
|
2019-10-30 17:40:57 +00:00
|
|
|
"storj.io/storj/satellite/overlay"
|
|
|
|
"storj.io/storj/storagenode"
|
|
|
|
"storj.io/storj/storagenode/gracefulexit"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWorkerSuccess(t *testing.T) {
|
2020-01-21 10:38:41 +00:00
|
|
|
const successThreshold = 4
|
2019-10-30 17:40:57 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
2019-10-31 14:57:54 +00:00
|
|
|
StorageNodeCount: successThreshold + 1,
|
2019-10-30 17:40:57 +00:00
|
|
|
UplinkCount: 1,
|
2020-01-21 10:38:41 +00:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.ReconfigureRS(2, 3, successThreshold, successThreshold),
|
2020-10-20 20:58:54 +01:00
|
|
|
StorageNode: func(index int, config *storagenode.Config) {
|
|
|
|
config.GracefulExit.NumWorkers = 2
|
|
|
|
config.GracefulExit.NumConcurrentTransfers = 2
|
|
|
|
config.GracefulExit.MinBytesPerSecond = 128
|
|
|
|
config.GracefulExit.MinDownloadTimeout = 2 * time.Minute
|
|
|
|
},
|
2020-01-21 10:38:41 +00:00
|
|
|
},
|
2019-10-30 17:40:57 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
|
|
|
|
satellite.GracefulExit.Chore.Loop.Pause()
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path1", testrand.Bytes(5*memory.KiB))
|
2019-10-30 17:40:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-16 16:47:31 +00:00
|
|
|
exitingNode, err := findNodeToExit(ctx, planet)
|
2019-10-30 17:40:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
exitingNode.GracefulExit.Chore.Loop.Pause()
|
|
|
|
|
|
|
|
exitStatusReq := overlay.ExitStatusRequest{
|
|
|
|
NodeID: exitingNode.ID(),
|
|
|
|
ExitInitiatedAt: time.Now(),
|
|
|
|
}
|
|
|
|
_, err = satellite.Overlay.DB.UpdateExitStatus(ctx, &exitStatusReq)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// run the satellite chore to build the transfer queue.
|
|
|
|
satellite.GracefulExit.Chore.Loop.TriggerWait()
|
|
|
|
satellite.GracefulExit.Chore.Loop.Pause()
|
|
|
|
|
|
|
|
// check that the satellite knows the storage node is exiting.
|
|
|
|
exitingNodes, err := satellite.DB.OverlayCache().GetExitingNodes(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, exitingNodes, 1)
|
|
|
|
require.Equal(t, exitingNode.ID(), exitingNodes[0].NodeID)
|
|
|
|
|
2021-09-05 22:29:22 +01:00
|
|
|
queueItems, err := satellite.DB.GracefulExit().GetIncomplete(ctx, exitingNode.ID(), 10, 0)
|
2019-10-30 17:40:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, queueItems, 1)
|
|
|
|
|
|
|
|
// run the SN chore again to start processing transfers.
|
2020-10-20 20:58:54 +01:00
|
|
|
worker := gracefulexit.NewWorker(zaptest.NewLogger(t), exitingNode.GracefulExit.Service, exitingNode.PieceTransfer.Service, exitingNode.Dialer, satellite.NodeURL(), exitingNode.Config.GracefulExit)
|
2019-12-17 15:06:47 +00:00
|
|
|
defer ctx.Check(worker.Close)
|
|
|
|
|
2019-10-30 17:40:57 +00:00
|
|
|
err = worker.Run(ctx, func() {})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
progress, err := satellite.DB.GracefulExit().GetProgress(ctx, exitingNode.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, progress.PiecesFailed, 0)
|
|
|
|
require.EqualValues(t, progress.PiecesTransferred, 1)
|
|
|
|
|
|
|
|
exitStatus, err := satellite.DB.OverlayCache().GetExitStatus(ctx, exitingNode.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, exitStatus.ExitFinishedAt)
|
|
|
|
require.True(t, exitStatus.ExitSuccess)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWorkerTimeout(t *testing.T) {
|
2020-01-21 10:38:41 +00:00
|
|
|
const successThreshold = 4
|
2019-10-30 17:40:57 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
2019-10-31 14:57:54 +00:00
|
|
|
StorageNodeCount: successThreshold + 1,
|
2019-10-30 17:40:57 +00:00
|
|
|
UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
2020-03-27 16:18:19 +00:00
|
|
|
StorageNodeDB: func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error) {
|
2019-10-30 17:40:57 +00:00
|
|
|
return testblobs.NewSlowDB(log.Named("slowdb"), db), nil
|
|
|
|
},
|
2020-01-21 10:38:41 +00:00
|
|
|
Satellite: testplanet.ReconfigureRS(2, 3, successThreshold, successThreshold),
|
2020-10-20 20:58:54 +01:00
|
|
|
StorageNode: func(index int, config *storagenode.Config) {
|
|
|
|
config.GracefulExit.NumWorkers = 2
|
|
|
|
config.GracefulExit.NumConcurrentTransfers = 2
|
|
|
|
// This config value will create a very short timeframe allowed for receiving
|
|
|
|
// data from storage nodes. This will cause context to cancel with timeout.
|
|
|
|
config.GracefulExit.MinBytesPerSecond = 10 * memory.MiB
|
|
|
|
config.GracefulExit.MinDownloadTimeout = 2 * time.Millisecond
|
|
|
|
},
|
2019-10-30 17:40:57 +00:00
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
|
|
|
|
satellite.GracefulExit.Chore.Loop.Pause()
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path1", testrand.Bytes(5*memory.KiB))
|
2019-10-30 17:40:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-16 16:47:31 +00:00
|
|
|
exitingNode, err := findNodeToExit(ctx, planet)
|
2019-10-30 17:40:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
exitingNode.GracefulExit.Chore.Loop.Pause()
|
|
|
|
|
|
|
|
exitStatusReq := overlay.ExitStatusRequest{
|
|
|
|
NodeID: exitingNode.ID(),
|
|
|
|
ExitInitiatedAt: time.Now(),
|
|
|
|
}
|
|
|
|
_, err = satellite.Overlay.DB.UpdateExitStatus(ctx, &exitStatusReq)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// run the satellite chore to build the transfer queue.
|
|
|
|
satellite.GracefulExit.Chore.Loop.TriggerWait()
|
|
|
|
satellite.GracefulExit.Chore.Loop.Pause()
|
|
|
|
|
|
|
|
// check that the satellite knows the storage node is exiting.
|
|
|
|
exitingNodes, err := satellite.DB.OverlayCache().GetExitingNodes(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, exitingNodes, 1)
|
|
|
|
require.Equal(t, exitingNode.ID(), exitingNodes[0].NodeID)
|
|
|
|
|
2021-09-05 22:29:22 +01:00
|
|
|
queueItems, err := satellite.DB.GracefulExit().GetIncomplete(ctx, exitingNode.ID(), 10, 0)
|
2019-10-30 17:40:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, queueItems, 1)
|
|
|
|
|
|
|
|
storageNodeDB := exitingNode.DB.(*testblobs.SlowDB)
|
|
|
|
// make uploads on storage node slower than the timeout for transferring bytes to another node
|
|
|
|
delay := 200 * time.Millisecond
|
|
|
|
storageNodeDB.SetLatency(delay)
|
|
|
|
|
|
|
|
// run the SN chore again to start processing transfers.
|
2020-10-20 20:58:54 +01:00
|
|
|
worker := gracefulexit.NewWorker(zaptest.NewLogger(t), exitingNode.GracefulExit.Service, exitingNode.PieceTransfer.Service, exitingNode.Dialer, satellite.NodeURL(), exitingNode.Config.GracefulExit)
|
2019-12-17 15:06:47 +00:00
|
|
|
defer ctx.Check(worker.Close)
|
|
|
|
|
2019-10-30 17:40:57 +00:00
|
|
|
err = worker.Run(ctx, func() {})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
progress, err := satellite.DB.GracefulExit().GetProgress(ctx, exitingNode.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, progress.PiecesFailed, 1)
|
|
|
|
require.EqualValues(t, progress.PiecesTransferred, 0)
|
|
|
|
|
|
|
|
exitStatus, err := satellite.DB.OverlayCache().GetExitStatus(ctx, exitingNode.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, exitStatus.ExitFinishedAt)
|
|
|
|
require.False(t, exitStatus.ExitSuccess)
|
|
|
|
})
|
|
|
|
}
|
2020-01-08 02:33:41 +00:00
|
|
|
|
|
|
|
func TestWorkerFailure_IneligibleNodeAge(t *testing.T) {
|
2020-01-21 10:38:41 +00:00
|
|
|
const successThreshold = 4
|
2020-01-08 02:33:41 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 5,
|
|
|
|
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) {
|
|
|
|
// Set the required node age to 1 month.
|
|
|
|
config.GracefulExit.NodeMinAgeInMonths = 1
|
|
|
|
},
|
|
|
|
testplanet.ReconfigureRS(2, 3, successThreshold, successThreshold),
|
|
|
|
),
|
|
|
|
|
2020-10-20 20:58:54 +01:00
|
|
|
StorageNode: func(index int, config *storagenode.Config) {
|
|
|
|
config.GracefulExit.NumWorkers = 2
|
|
|
|
config.GracefulExit.NumConcurrentTransfers = 2
|
|
|
|
config.GracefulExit.MinBytesPerSecond = 128
|
|
|
|
config.GracefulExit.MinDownloadTimeout = 2 * time.Minute
|
|
|
|
},
|
2020-01-08 02:33:41 +00:00
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
|
|
|
|
satellite.GracefulExit.Chore.Loop.Pause()
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path1", testrand.Bytes(5*memory.KiB))
|
2020-01-08 02:33:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-16 16:47:31 +00:00
|
|
|
exitingNode, err := findNodeToExit(ctx, planet)
|
2020-01-08 02:33:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
exitingNode.GracefulExit.Chore.Loop.Pause()
|
|
|
|
|
2020-01-23 17:47:20 +00:00
|
|
|
_, piecesContentSize, err := exitingNode.Storage2.BlobsCache.SpaceUsedForPieces(ctx)
|
2020-01-08 02:33:41 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-23 17:47:20 +00:00
|
|
|
err = exitingNode.DB.Satellites().InitiateGracefulExit(ctx, satellite.ID(), time.Now(), piecesContentSize)
|
2020-01-08 02:33:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-10-20 20:58:54 +01:00
|
|
|
worker := gracefulexit.NewWorker(zaptest.NewLogger(t), exitingNode.GracefulExit.Service, exitingNode.PieceTransfer.Service, exitingNode.Dialer, satellite.NodeURL(), exitingNode.Config.GracefulExit)
|
2020-01-08 02:33:41 +00:00
|
|
|
defer ctx.Check(worker.Close)
|
|
|
|
|
|
|
|
err = worker.Run(ctx, func() {})
|
|
|
|
require.Error(t, err)
|
|
|
|
require.True(t, errs2.IsRPC(err, rpcstatus.FailedPrecondition))
|
|
|
|
|
|
|
|
result, err := exitingNode.DB.Satellites().ListGracefulExits(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, result, 0)
|
|
|
|
})
|
|
|
|
}
|