2019-06-11 21:14:40 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package audit_test
|
|
|
|
|
|
|
|
import (
|
2022-11-22 23:18:01 +00:00
|
|
|
"context"
|
2019-06-11 21:14:40 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-11-19 16:30:28 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
2022-11-22 23:18:01 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/peertls/tlsopts"
|
|
|
|
"storj.io/common/rpc"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-11-19 16:30:28 +00:00
|
|
|
"storj.io/storj/private/testblobs"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-11-19 16:30:28 +00:00
|
|
|
"storj.io/storj/satellite"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2019-11-19 16:30:28 +00:00
|
|
|
"storj.io/storj/storagenode"
|
2019-06-11 21:14:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReverifySuccess(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2019-06-11 21:14:40 +01:00
|
|
|
// This is a bulky test but all it's doing is:
|
|
|
|
// - uploads random data
|
|
|
|
// - uses the cursor to get a stripe
|
2022-11-22 23:18:01 +00:00
|
|
|
// - calls reverify on that stripe
|
2019-06-11 21:14:40 +01:00
|
|
|
// - expects one storage node to be marked as a success in the audit report
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
2019-07-01 15:02:00 +01:00
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pieceIndex := testrand.Intn(len(segment.Pieces))
|
|
|
|
piece := segment.Pieces[pieceIndex]
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: piece.StorageNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(piece.Number),
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.ReportReverificationNeeded(ctx, pending)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeSuccess, outcome)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
|
|
|
require.NoError(t, err)
|
2020-03-04 23:09:18 +00:00
|
|
|
|
2021-05-25 20:45:39 +01:00
|
|
|
// make sure that pending audit is removed
|
2020-03-04 23:09:18 +00:00
|
|
|
_, err = containment.Get(ctx, pending.NodeID)
|
|
|
|
require.True(t, audit.ErrContainedNotFound.Has(err))
|
2019-06-11 21:14:40 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverifyFailMissingShare(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2019-06-11 21:14:40 +01:00
|
|
|
// - uploads random data
|
|
|
|
// - uses the cursor to get a stripe
|
|
|
|
// - creates one pending audit for a node holding a piece for that stripe
|
|
|
|
// - delete piece from node
|
2022-11-22 23:18:01 +00:00
|
|
|
// - calls reverify on that piece
|
2019-06-11 21:14:40 +01:00
|
|
|
// - expects one storage node to be marked as a fail in the audit report
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
2022-11-22 23:18:01 +00:00
|
|
|
reporter := audits.Reporter
|
2019-09-11 23:37:01 +01:00
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
2019-07-01 15:02:00 +01:00
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pieceIndex := testrand.Intn(len(segment.Pieces))
|
|
|
|
piece := segment.Pieces[pieceIndex]
|
2020-12-14 12:54:22 +00:00
|
|
|
rootPieceID := segment.RootPieceID
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: piece.StorageNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(piece.Number),
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = reporter.ReportReverificationNeeded(ctx, pending)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// delete the piece from the first node
|
2020-12-14 12:54:22 +00:00
|
|
|
pieceID := rootPieceID.Derive(piece.StorageNode, int32(piece.Number))
|
|
|
|
node := planet.FindNode(piece.StorageNode)
|
2019-09-11 23:37:01 +01:00
|
|
|
err = node.Storage2.Store.Delete(ctx, satellite.ID(), pieceID)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeFailure, outcome)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-25 20:45:39 +01:00
|
|
|
// make sure that pending audit is removed
|
2020-03-04 23:09:18 +00:00
|
|
|
_, err = containment.Get(ctx, pending.NodeID)
|
|
|
|
require.True(t, audit.ErrContainedNotFound.Has(err))
|
2019-06-11 21:14:40 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverifyOffline(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2019-06-11 21:14:40 +01:00
|
|
|
// - uploads random data
|
|
|
|
// - uses the cursor to get a stripe
|
|
|
|
// - creates pending audits for one node holding a piece for that stripe
|
|
|
|
// - stop the node that has the pending audit
|
|
|
|
// - calls reverify on that same stripe
|
|
|
|
// - expects one storage node to be marked as offline in the audit report
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
2022-11-22 23:18:01 +00:00
|
|
|
reporter := audits.Reporter
|
2019-09-11 23:37:01 +01:00
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
2019-07-01 15:02:00 +01:00
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pieceIndex := testrand.Intn(len(segment.Pieces))
|
|
|
|
piece := segment.Pieces[pieceIndex]
|
2019-09-11 23:37:01 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: piece.StorageNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(piece.Number),
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = reporter.ReportReverificationNeeded(ctx, pending)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = planet.StopNodeAndUpdate(ctx, planet.FindNode(piece.StorageNode))
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeNodeOffline, outcome)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
|
|
|
require.NoError(t, err)
|
2020-03-04 23:09:18 +00:00
|
|
|
|
|
|
|
// make sure that pending audit is not removed
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2020-03-04 23:09:18 +00:00
|
|
|
_, err = containment.Get(ctx, pending.NodeID)
|
|
|
|
require.NoError(t, err)
|
2019-06-11 21:14:40 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverifyOfflineDialTimeout(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2019-06-11 21:14:40 +01:00
|
|
|
// - uploads random data
|
|
|
|
// - uses the cursor to get a stripe
|
|
|
|
// - creates pending audit for one node holding a piece for that stripe
|
|
|
|
// - uses a slow transport client so that dial timeout will happen (an offline case)
|
|
|
|
// - calls reverify on that same stripe
|
2022-11-22 23:18:01 +00:00
|
|
|
// - expects the reverification to be alive still
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
2019-07-01 15:02:00 +01:00
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
tlsOptions, err := tlsopts.NewOptions(satellite.Identity, tlsopts.Config{}, nil)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
dialer := rpc.NewDefaultDialer(tlsOptions)
|
|
|
|
dialer.DialTimeout = 20 * time.Millisecond
|
|
|
|
dialer.DialLatency = 200 * time.Second
|
2020-09-30 18:39:47 +01:00
|
|
|
|
2022-02-16 15:56:01 +00:00
|
|
|
connector := rpc.NewHybridConnector()
|
|
|
|
connector.SetTransferRate(1 * memory.KB)
|
2020-09-30 18:39:47 +01:00
|
|
|
dialer.Connector = connector
|
2019-06-11 21:14:40 +01:00
|
|
|
|
|
|
|
// This config value will create a very short timeframe allowed for receiving
|
|
|
|
// data from storage nodes. This will cause context to cancel and start
|
|
|
|
// downloading from new nodes.
|
|
|
|
minBytesPerSecond := 100 * memory.KiB
|
|
|
|
|
2019-07-01 15:02:00 +01:00
|
|
|
verifier := audit.NewVerifier(
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite.Log.Named("verifier"),
|
2021-09-07 09:15:47 +01:00
|
|
|
satellite.Metabase.DB,
|
2019-09-19 05:46:39 +01:00
|
|
|
dialer,
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite.Overlay.Service,
|
2022-11-23 15:24:30 +00:00
|
|
|
satellite.DB.Containment(),
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite.Orders.Service,
|
|
|
|
satellite.Identity,
|
2019-06-11 21:14:40 +01:00
|
|
|
minBytesPerSecond,
|
|
|
|
5*time.Second)
|
2022-11-22 23:18:01 +00:00
|
|
|
reverifier := audit.NewReverifier(
|
|
|
|
satellite.Log.Named("reverifier"),
|
|
|
|
verifier,
|
|
|
|
satellite.DB.ReverifyQueue(),
|
|
|
|
audit.Config{})
|
|
|
|
|
|
|
|
pieceIndex := testrand.Intn(len(segment.Pieces))
|
|
|
|
piece := segment.Pieces[pieceIndex]
|
|
|
|
|
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: piece.StorageNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(piece.Number),
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.ReportReverificationNeeded(ctx, pending)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
outcome, reputation := reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeTimedOut, outcome)
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
|
|
|
require.NoError(t, err)
|
2020-03-04 23:09:18 +00:00
|
|
|
|
|
|
|
// make sure that pending audit is not removed
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2020-03-04 23:09:18 +00:00
|
|
|
_, err = containment.Get(ctx, pending.NodeID)
|
|
|
|
require.NoError(t, err)
|
2019-06-11 21:14:40 +01:00
|
|
|
})
|
|
|
|
}
|
2019-06-19 10:02:25 +01:00
|
|
|
|
|
|
|
func TestReverifyDeletedSegment(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-06-19 10:02:25 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2020-01-21 10:38:41 +00:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.ReconfigureRS(1, 2, 4, 4),
|
|
|
|
},
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2019-09-29 03:03:15 +01:00
|
|
|
// - uploads random data to all nodes
|
2020-12-14 12:54:22 +00:00
|
|
|
// - gets a segment from the audit queue
|
2019-09-11 23:37:01 +01:00
|
|
|
// - creates one pending audit for a node holding a piece for that segment
|
2019-06-19 10:02:25 +01:00
|
|
|
// - deletes the file
|
2019-09-29 03:03:15 +01:00
|
|
|
// - calls reverify on the deleted file
|
2022-11-22 23:18:01 +00:00
|
|
|
// - expects reverification to pass successfully and the storage node to be not in containment mode
|
2019-06-19 10:02:25 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-06-19 10:02:25 +01:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
2019-09-29 03:03:15 +01:00
|
|
|
testData1 := testrand.Bytes(8 * memory.KiB)
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path1", testData1)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pieceIndex := testrand.Intn(len(segment.Pieces))
|
|
|
|
piece := segment.Pieces[pieceIndex]
|
2019-09-11 23:37:01 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: piece.StorageNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(piece.Number),
|
2019-06-19 10:02:25 +01:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.ReportReverificationNeeded(ctx, pending)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// delete the file
|
2020-02-10 12:18:18 +00:00
|
|
|
err = ul.DeleteObject(ctx, satellite, "testbucket", "test/path1")
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// call reverify on the deleted file and expect OutcomeNotNecessary
|
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeNotNecessary, outcome)
|
2019-09-29 03:03:15 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
2019-09-29 03:03:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// expect that the node was removed from containment since the segment it was contained for has been deleted
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2022-11-22 23:18:01 +00:00
|
|
|
_, err = containment.Get(ctx, piece.StorageNode)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.True(t, audit.ErrContainedNotFound.Has(err))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
func cloneAndDropPiece(ctx context.Context, metabaseDB *metabase.DB, segment *metabase.Segment, pieceNum int) error {
|
|
|
|
newPieces := make([]metabase.Piece, len(segment.Pieces))
|
|
|
|
copy(newPieces, segment.Pieces)
|
|
|
|
return metabaseDB.UpdateSegmentPieces(ctx, metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
OldPieces: segment.Pieces,
|
|
|
|
NewPieces: append(newPieces[:pieceNum], newPieces[pieceNum+1:]...),
|
|
|
|
NewRedundancy: segment.Redundancy,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-19 10:02:25 +01:00
|
|
|
func TestReverifyModifiedSegment(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2020-03-04 23:09:18 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.ReconfigureRS(1, 2, 4, 4),
|
|
|
|
},
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2022-11-22 23:18:01 +00:00
|
|
|
// - uploads random data to an object on all nodes
|
|
|
|
// - creates a pending audit for a particular piece of that object
|
|
|
|
// - removes a (different) piece from the object so that the segment is modified
|
|
|
|
// - expects reverification to pass with OutcomeNotNecessary and the storage node to be not in containment mode
|
2020-03-04 23:09:18 +00:00
|
|
|
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2020-03-04 23:09:18 +00:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData1 := testrand.Bytes(8 * memory.KiB)
|
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path1", testData1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2020-03-04 23:09:18 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2020-03-04 23:09:18 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pieceIndex := testrand.Intn(len(segment.Pieces))
|
|
|
|
piece := segment.Pieces[pieceIndex]
|
2020-03-04 23:09:18 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: piece.StorageNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(piece.Number),
|
2020-03-04 23:09:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2020-03-04 23:09:18 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.ReportReverificationNeeded(ctx, pending)
|
2020-03-04 23:09:18 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
otherPiece := (pieceIndex + 1) % len(segment.Pieces)
|
|
|
|
|
2020-03-04 23:09:18 +00:00
|
|
|
// remove a piece from the file (a piece that the contained node isn't holding)
|
|
|
|
audits.Verifier.OnTestingCheckSegmentAlteredHook = func() {
|
2022-11-22 23:18:01 +00:00
|
|
|
err := cloneAndDropPiece(ctx, satellite.Metabase.DB, &segment, otherPiece)
|
2020-03-04 23:09:18 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// try reverifying the piece we just removed
|
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), &audit.PieceLocator{
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
NodeID: segment.Pieces[otherPiece].StorageNode,
|
|
|
|
PieceNum: int(segment.Pieces[otherPiece].Number),
|
|
|
|
})
|
|
|
|
require.Equal(t, audit.OutcomeNotNecessary, outcome)
|
2020-03-04 23:09:18 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
2020-03-04 23:09:18 +00:00
|
|
|
require.NoError(t, err)
|
2022-10-12 21:33:31 +01:00
|
|
|
require.Equal(t, audit.OutcomeNotNecessary, outcome)
|
2020-03-04 23:09:18 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// expect that the node was removed from containment since the piece it was contained for is no longer part of the segment
|
|
|
|
_, err = containment.Get(ctx, segment.Pieces[otherPiece].StorageNode)
|
2020-03-04 23:09:18 +00:00
|
|
|
require.True(t, audit.ErrContainedNotFound.Has(err))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverifyReplacedSegment(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-06-19 10:02:25 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2020-01-21 10:38:41 +00:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.ReconfigureRS(1, 2, 4, 4),
|
|
|
|
},
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2022-11-22 23:18:01 +00:00
|
|
|
// - uploads random data to an object on all nodes
|
|
|
|
// - creates a pending audit for a particular piece of that object
|
|
|
|
// - re-uploads the object (with the same contents) so that the segment is modified
|
|
|
|
// - expects reverification to pass with OutcomeNotNecessary and the storage node to be not in containment
|
2019-06-19 10:02:25 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-06-19 10:02:25 +01:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
2019-09-29 03:03:15 +01:00
|
|
|
testData1 := testrand.Bytes(8 * memory.KiB)
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path1", testData1)
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pieceIndex := testrand.Intn(len(segment.Pieces))
|
|
|
|
piece := segment.Pieces[pieceIndex]
|
2019-06-19 10:02:25 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: piece.StorageNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(piece.Number),
|
2019-06-19 10:02:25 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2019-06-19 10:02:25 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.ReportReverificationNeeded(ctx, pending)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// replace the file
|
2019-09-29 03:03:15 +01:00
|
|
|
err = ul.Upload(ctx, satellite, "testbucket", "test/path1", testData1)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-14 12:54:22 +00:00
|
|
|
// reverify the segment that was not modified
|
2022-11-22 23:18:01 +00:00
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeNotNecessary, outcome)
|
2019-06-19 10:02:25 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
2019-09-19 00:45:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// expect that the node was removed from containment since the segment it was contained for has been changed
|
|
|
|
_, err = containment.Get(ctx, piece.StorageNode)
|
2020-03-04 23:09:18 +00:00
|
|
|
require.True(t, audit.ErrContainedNotFound.Has(err))
|
2019-09-19 00:45:15 +01:00
|
|
|
})
|
|
|
|
}
|
2019-11-05 19:41:48 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// TestReverifyExpired tests the case where the segment passed into Reverify is expired.
|
|
|
|
func TestReverifyExpired(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-11-05 19:41:48 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2019-11-05 19:41:48 +00:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-11-05 19:41:48 +00:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
|
|
|
|
2020-12-14 12:54:22 +00:00
|
|
|
err := ul.UploadWithExpiration(ctx, satellite, "testbucket", "test/path", testData, time.Now().Add(1*time.Hour))
|
2019-11-05 19:41:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-11-05 19:41:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
2020-12-14 12:54:22 +00:00
|
|
|
})
|
2019-11-05 19:41:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-12-14 12:54:22 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// move time into the future so the segment is expired
|
|
|
|
audits.Reverifier.SetNow(func() time.Time {
|
|
|
|
return time.Now().Add(2 * time.Hour)
|
2020-12-14 12:54:22 +00:00
|
|
|
})
|
2019-11-05 19:41:48 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pieceIndex := testrand.Intn(len(segment.Pieces))
|
|
|
|
piece := segment.Pieces[pieceIndex]
|
2019-11-05 19:41:48 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
NodeID: piece.StorageNode,
|
|
|
|
PieceNum: int(piece.Number),
|
2019-11-05 19:41:48 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// Reverify should not return an error
|
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeNotNecessary, outcome)
|
2019-11-05 19:41:48 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
2019-11-05 19:41:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// expect that the node was removed from containment since the segment it was
|
|
|
|
// contained for has expired
|
2022-11-23 15:24:30 +00:00
|
|
|
_, err = satellite.DB.Containment().Get(ctx, piece.StorageNode)
|
2020-12-14 12:54:22 +00:00
|
|
|
require.True(t, audit.ErrContainedNotFound.Has(err))
|
2019-11-05 19:41:48 +00:00
|
|
|
})
|
|
|
|
}
|
2019-11-19 16:30:28 +00:00
|
|
|
|
|
|
|
// TestReverifySlowDownload checks that a node that times out while sending data to the
|
2020-07-16 15:18:02 +01:00
|
|
|
// audit service gets put into containment mode.
|
2019-11-19 16:30:28 +00:00
|
|
|
func TestReverifySlowDownload(t *testing.T) {
|
2021-11-09 12:37:05 +00:00
|
|
|
const auditTimeout = time.Second
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-11-19 16:30:28 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, 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-11-19 16:30:28 +00:00
|
|
|
return testblobs.NewSlowDB(log.Named("slowdb"), db), nil
|
|
|
|
},
|
2020-10-27 17:34:59 +00:00
|
|
|
Satellite: testplanet.Combine(
|
|
|
|
func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
// These config values are chosen to force the slow node to time out without timing out on the three normal nodes
|
|
|
|
config.Audit.MinBytesPerSecond = 100 * memory.KiB
|
2021-11-09 12:37:05 +00:00
|
|
|
config.Audit.MinDownloadTimeout = auditTimeout
|
2020-10-27 17:34:59 +00:00
|
|
|
},
|
|
|
|
testplanet.ReconfigureRS(2, 2, 4, 4),
|
|
|
|
),
|
2019-11-19 16:30:28 +00:00
|
|
|
},
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2019-11-19 16:30:28 +00:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-11-19 16:30:28 +00:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
2019-11-19 16:30:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-11-19 16:30:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2019-11-19 16:30:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-14 12:54:22 +00:00
|
|
|
slowPiece := segment.Pieces[0]
|
|
|
|
slowNode := slowPiece.StorageNode
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2019-11-19 16:30:28 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: slowNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(slowPiece.Number),
|
2019-11-19 16:30:28 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.ReportReverificationNeeded(ctx, pending)
|
2019-11-19 16:30:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-05-07 09:23:40 +01:00
|
|
|
node := planet.FindNode(slowNode)
|
|
|
|
slowNodeDB := node.DB.(*testblobs.SlowDB)
|
|
|
|
// make downloads on storage node slower than the timeout on the satellite for downloading shares
|
2021-11-09 12:37:05 +00:00
|
|
|
delay := 10 * auditTimeout
|
2020-05-07 09:23:40 +01:00
|
|
|
slowNodeDB.SetLatency(delay)
|
2019-11-19 16:30:28 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeTimedOut, outcome)
|
2020-03-04 23:09:18 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
|
|
|
require.NoError(t, err)
|
2022-10-12 21:33:31 +01:00
|
|
|
require.Equal(t, audit.OutcomeTimedOut, outcome)
|
2021-04-28 15:12:54 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// expect that the node is still in containment
|
2020-03-04 23:09:18 +00:00
|
|
|
_, err = containment.Get(ctx, slowNode)
|
2022-11-22 23:18:01 +00:00
|
|
|
require.NoError(t, err)
|
2019-11-19 16:30:28 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestReverifyUnknownError checks that a node that returns an unknown error during an audit does not get marked as successful, failed, or contained.
|
|
|
|
func TestReverifyUnknownError(t *testing.T) {
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2019-11-19 16:30:28 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, 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-11-19 16:30:28 +00:00
|
|
|
return testblobs.NewBadDB(log.Named("baddb"), db), nil
|
|
|
|
},
|
2020-01-21 10:38:41 +00:00
|
|
|
Satellite: testplanet.ReconfigureRS(2, 2, 4, 4),
|
2019-11-19 16:30:28 +00:00
|
|
|
},
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2019-11-19 16:30:28 +00:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2019-11-19 16:30:28 +00:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
2019-11-19 16:30:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2019-11-19 16:30:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2020-12-14 12:54:22 +00:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
2019-11-19 16:30:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-14 12:54:22 +00:00
|
|
|
badPiece := segment.Pieces[0]
|
|
|
|
badNode := badPiece.StorageNode
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2019-11-19 16:30:28 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: badNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(badPiece.Number),
|
2019-11-19 16:30:28 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.ReportReverificationNeeded(ctx, pending)
|
2019-11-19 16:30:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-05-07 09:23:40 +01:00
|
|
|
node := planet.FindNode(badNode)
|
|
|
|
badNodeDB := node.DB.(*testblobs.BadDB)
|
|
|
|
// return an error when the satellite requests a share
|
|
|
|
badNodeDB.SetError(errs.New("unknown error"))
|
2019-11-19 16:30:28 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
outcome, reputation := audits.Reverifier.ReverifyPiece(ctx, zaptest.NewLogger(t), pending)
|
|
|
|
require.Equal(t, audit.OutcomeUnknownError, outcome)
|
2019-11-19 16:30:28 +00:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.RecordReverificationResult(ctx, &audit.ReverificationJob{Locator: *pending}, outcome, reputation)
|
|
|
|
require.NoError(t, err)
|
2020-03-04 23:09:18 +00:00
|
|
|
|
2021-05-25 20:45:39 +01:00
|
|
|
// make sure that pending audit is removed
|
2020-03-09 15:35:54 +00:00
|
|
|
_, err = containment.Get(ctx, pending.NodeID)
|
2022-11-22 23:18:01 +00:00
|
|
|
require.Truef(t, audit.ErrContainedNotFound.Has(err), "expected ErrContainedNotFound but got error %+v", err)
|
2019-11-19 16:30:28 +00:00
|
|
|
})
|
|
|
|
}
|
2021-08-18 18:21:52 +01:00
|
|
|
|
|
|
|
func TestMaxReverifyCount(t *testing.T) {
|
2021-11-09 12:37:05 +00:00
|
|
|
const auditTimeout = time.Second
|
2022-12-15 00:37:37 +00:00
|
|
|
testWithChoreAndObserver(t, testplanet.Config{
|
2021-08-18 18:21:52 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
StorageNodeDB: func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error) {
|
|
|
|
return testblobs.NewSlowDB(log.Named("slowdb"), db), nil
|
|
|
|
},
|
|
|
|
Satellite: testplanet.Combine(
|
|
|
|
func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
// These config values are chosen to force the slow node to time out without timing out on the three normal nodes
|
|
|
|
config.Audit.MinBytesPerSecond = 100 * memory.KiB
|
2021-11-09 12:37:05 +00:00
|
|
|
config.Audit.MinDownloadTimeout = auditTimeout
|
2022-10-12 21:33:31 +01:00
|
|
|
// disable reputation write cache so changes are immediate
|
|
|
|
config.Reputation.FlushInterval = 0
|
2021-08-18 18:21:52 +01:00
|
|
|
},
|
|
|
|
testplanet.ReconfigureRS(2, 2, 4, 4),
|
|
|
|
),
|
|
|
|
},
|
2022-12-15 00:37:37 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
|
2021-08-18 18:21:52 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
2022-11-22 23:18:01 +00:00
|
|
|
audits.ReverifyWorker.Loop.Pause()
|
2022-12-15 00:37:37 +00:00
|
|
|
pauseQueueing(satellite)
|
2021-08-18 18:21:52 +01:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
err = runQueueingOnce(ctx, satellite)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
|
|
|
queueSegment, err := queue.Next(ctx)
|
2021-08-18 18:21:52 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
segment, err := satellite.Metabase.DB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
2021-08-18 18:21:52 +01:00
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
slowPiece := segment.Pieces[0]
|
|
|
|
slowNode := slowPiece.StorageNode
|
2022-11-23 15:24:30 +00:00
|
|
|
containment := satellite.DB.Containment()
|
2021-08-18 18:21:52 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
pending := &audit.PieceLocator{
|
|
|
|
NodeID: slowNode,
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
|
|
|
PieceNum: int(slowPiece.Number),
|
2021-08-18 18:21:52 +01:00
|
|
|
}
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = audits.Reporter.ReportReverificationNeeded(ctx, pending)
|
2021-08-18 18:21:52 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node := planet.FindNode(slowNode)
|
|
|
|
slowNodeDB := node.DB.(*testblobs.SlowDB)
|
|
|
|
// make downloads on storage node slower than the timeout on the satellite for downloading shares
|
2021-11-09 12:37:05 +00:00
|
|
|
delay := 10 * auditTimeout
|
2021-08-18 18:21:52 +01:00
|
|
|
slowNodeDB.SetLatency(delay)
|
|
|
|
|
|
|
|
oldRep, err := satellite.Reputation.Service.Get(ctx, slowNode)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
rq := audits.ReverifyQueue.(interface {
|
|
|
|
TestingFudgeUpdateTime(ctx context.Context, pendingAudit *audit.PieceLocator, updateTime time.Time) error
|
|
|
|
})
|
|
|
|
|
2021-08-18 18:21:52 +01:00
|
|
|
// give node enough timeouts to reach max
|
2022-11-22 23:18:01 +00:00
|
|
|
for i := 0; i < satellite.Config.Audit.MaxReverifyCount-1; i++ {
|
|
|
|
// run the reverify worker; each loop should complete once there are
|
|
|
|
// no more reverifications to do in the queue
|
|
|
|
audits.ReverifyWorker.Loop.TriggerWait()
|
2021-08-18 18:21:52 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
// make sure the node is still contained
|
|
|
|
info, err := containment.Get(ctx, slowNode)
|
|
|
|
require.NoError(t, err)
|
2021-08-18 18:21:52 +01:00
|
|
|
|
2022-11-22 23:18:01 +00:00
|
|
|
err = rq.TestingFudgeUpdateTime(ctx, pending, info.LastAttempt.Add(-satellite.Config.Audit.ReverificationRetryInterval))
|
|
|
|
require.NoError(t, err)
|
2021-08-18 18:21:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// final timeout should trigger failure and removal from containment
|
2022-11-22 23:18:01 +00:00
|
|
|
audits.ReverifyWorker.Loop.TriggerWait()
|
2021-08-18 18:21:52 +01:00
|
|
|
|
|
|
|
_, err = containment.Get(ctx, slowNode)
|
2022-11-22 23:18:01 +00:00
|
|
|
require.Truef(t, audit.ErrContainedNotFound.Has(err), "expected ErrContainedNotFound but got error %+v", err)
|
2021-08-18 18:21:52 +01:00
|
|
|
|
|
|
|
newRep, err := satellite.Reputation.Service.Get(ctx, slowNode)
|
|
|
|
require.NoError(t, err)
|
2022-11-22 23:18:01 +00:00
|
|
|
require.Less(t, oldRep.AuditReputationBeta, newRep.AuditReputationBeta)
|
2021-08-18 18:21:52 +01:00
|
|
|
})
|
|
|
|
}
|