2019-06-11 21:14:40 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package audit_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-11-05 19:41:48 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2019-06-19 10:02:25 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-06-11 21:14:40 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-11-19 16:30:28 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-11-05 19:41:48 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2019-06-11 21:14:40 +01:00
|
|
|
"storj.io/storj/pkg/peertls/tlsopts"
|
|
|
|
"storj.io/storj/pkg/pkcrypto"
|
2019-09-19 05:46:39 +01:00
|
|
|
"storj.io/storj/pkg/rpc"
|
2019-06-11 21:14:40 +01:00
|
|
|
"storj.io/storj/pkg/storj"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/memory"
|
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/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/private/testrand"
|
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"
|
2019-11-05 19:41:48 +00:00
|
|
|
"storj.io/storj/storage"
|
2019-11-19 16:30:28 +00:00
|
|
|
"storj.io/storj/storagenode"
|
2019-09-19 15:50:16 +01:00
|
|
|
"storj.io/storj/uplink"
|
2019-06-11 21:14:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReverifySuccess(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2019-06-11 21:14:40 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
// This is a bulky test but all it's doing is:
|
|
|
|
// - uploads random data
|
|
|
|
// - uses the cursor to get a stripe
|
|
|
|
// - creates one pending audit for a node holding a piece for that stripe
|
|
|
|
// - the actual share is downloaded to make sure ExpectedShareHash is correct
|
|
|
|
// - calls reverify on that same stripe
|
|
|
|
// - 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
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
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)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
orders := satellite.Orders.Service
|
|
|
|
containment := satellite.DB.Containment()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
bucketID := []byte(storj.JoinPaths(projects[0].ID.String(), "testbucket"))
|
2019-09-11 23:37:01 +01:00
|
|
|
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
pieces := pointer.GetRemote().GetRemotePieces()
|
|
|
|
rootPieceID := pointer.GetRemote().RootPieceId
|
2019-07-11 21:51:40 +01:00
|
|
|
limit, privateKey, err := orders.CreateAuditOrderLimit(ctx, bucketID, pieces[0].NodeId, pieces[0].PieceNum, rootPieceID, shareSize)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
share, err := audits.Verifier.GetShare(ctx, limit, privateKey, randomIndex, shareSize, int(pieces[0].PieceNum))
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: pieces[0].NodeId,
|
|
|
|
PieceID: rootPieceID,
|
2019-09-11 23:37:01 +01:00
|
|
|
StripeIndex: randomIndex,
|
2019-06-11 21:14:40 +01:00
|
|
|
ShareSize: shareSize,
|
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(share.Data),
|
|
|
|
ReverifyCount: 0,
|
2019-09-11 23:37:01 +01:00
|
|
|
Path: path,
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Fails, 0)
|
|
|
|
require.Len(t, report.Offlines, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
require.Len(t, report.Successes, 1)
|
|
|
|
require.Equal(t, report.Successes[0], pieces[0].NodeId)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverifyFailMissingShare(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2019-06-11 21:14:40 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
// - uploads random data
|
|
|
|
// - uses the cursor to get a stripe
|
|
|
|
// - creates one pending audit for a node holding a piece for that stripe
|
|
|
|
// - the actual share is downloaded to make sure ExpectedShareHash is correct
|
|
|
|
// - delete piece from node
|
|
|
|
// - calls reverify on that same stripe
|
|
|
|
// - 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
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
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)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
orders := satellite.Orders.Service
|
|
|
|
containment := satellite.DB.Containment()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
bucketID := []byte(storj.JoinPaths(projects[0].ID.String(), "testbucket"))
|
2019-09-11 23:37:01 +01:00
|
|
|
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
pieces := pointer.GetRemote().GetRemotePieces()
|
|
|
|
rootPieceID := pointer.GetRemote().RootPieceId
|
2019-07-11 21:51:40 +01:00
|
|
|
limit, privateKey, err := orders.CreateAuditOrderLimit(ctx, bucketID, pieces[0].NodeId, pieces[0].PieceNum, rootPieceID, shareSize)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
share, err := audits.Verifier.GetShare(ctx, limit, privateKey, randomIndex, shareSize, int(pieces[0].PieceNum))
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: pieces[0].NodeId,
|
|
|
|
PieceID: rootPieceID,
|
2019-09-11 23:37:01 +01:00
|
|
|
StripeIndex: randomIndex,
|
2019-06-11 21:14:40 +01:00
|
|
|
ShareSize: shareSize,
|
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(share.Data),
|
|
|
|
ReverifyCount: 0,
|
2019-09-11 23:37:01 +01:00
|
|
|
Path: path,
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// delete the piece from the first node
|
2019-09-11 23:37:01 +01:00
|
|
|
piece := pointer.GetRemote().GetRemotePieces()[0]
|
|
|
|
pieceID := pointer.GetRemote().RootPieceId.Derive(piece.NodeId, piece.PieceNum)
|
2019-07-03 17:53:15 +01:00
|
|
|
node := getStorageNode(planet, piece.NodeId)
|
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)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Offlines, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
require.Len(t, report.Fails, 1)
|
|
|
|
require.Equal(t, report.Fails[0], pieces[0].NodeId)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-07 21:06:10 +01:00
|
|
|
// TestReverifyFailMissingShareHashesNotVerified tests that if piece hashes were not verified for a pointer,
|
|
|
|
// a node that fails an audit for that pointer does not get marked as failing an audit, but is removed from
|
|
|
|
// the pointer.
|
|
|
|
func TestReverifyFailMissingShareNotVerified(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
|
|
|
|
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
orders := satellite.Orders.Service
|
|
|
|
containment := satellite.DB.Containment()
|
|
|
|
|
|
|
|
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
bucketID := []byte(storj.JoinPaths(projects[0].ID.String(), "testbucket"))
|
|
|
|
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
|
|
|
|
|
|
|
|
pieces := pointer.GetRemote().GetRemotePieces()
|
|
|
|
origNumPieces := len(pieces)
|
|
|
|
rootPieceID := pointer.GetRemote().RootPieceId
|
|
|
|
limit, privateKey, err := orders.CreateAuditOrderLimit(ctx, bucketID, pieces[0].NodeId, pieces[0].PieceNum, rootPieceID, shareSize)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
share, err := audits.Verifier.GetShare(ctx, limit, privateKey, randomIndex, shareSize, int(pieces[0].PieceNum))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: pieces[0].NodeId,
|
|
|
|
PieceID: rootPieceID,
|
|
|
|
StripeIndex: randomIndex,
|
|
|
|
ShareSize: shareSize,
|
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(share.Data),
|
|
|
|
ReverifyCount: 0,
|
|
|
|
Path: path,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// update pointer to have PieceHashesVerified false
|
2019-11-06 17:02:14 +00:00
|
|
|
err = satellite.Metainfo.Service.UnsynchronizedDelete(ctx, path)
|
2019-10-07 21:06:10 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
pointer.PieceHashesVerified = false
|
|
|
|
err = satellite.Metainfo.Service.Put(ctx, path, pointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// delete the piece from the first node
|
|
|
|
piece := pieces[0]
|
|
|
|
pieceID := pointer.GetRemote().RootPieceId.Derive(piece.NodeId, piece.PieceNum)
|
|
|
|
node := getStorageNode(planet, piece.NodeId)
|
|
|
|
err = node.Storage2.Store.Delete(ctx, satellite.ID(), pieceID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Offlines, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
// expect no failed audit
|
|
|
|
require.Len(t, report.Fails, 0)
|
|
|
|
|
|
|
|
// expect that bad node is no longer in the pointer
|
|
|
|
pointer, err = satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Len(t, pointer.GetRemote().GetRemotePieces(), origNumPieces-1)
|
|
|
|
for _, p := range pointer.GetRemote().GetRemotePieces() {
|
|
|
|
assert.NotEqual(t, p.NodeId, pieces[0].NodeId)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:14:40 +01:00
|
|
|
func TestReverifyFailBadData(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2019-06-11 21:14:40 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
// - uploads random data
|
|
|
|
// - uses the cursor to get a stripe
|
|
|
|
// - creates a pending audit for a node holding a piece for that stripe
|
|
|
|
// - makes ExpectedShareHash have random data
|
|
|
|
// - calls reverify on that same stripe
|
|
|
|
// - 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
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
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)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
pieces := pointer.GetRemote().GetRemotePieces()
|
|
|
|
rootPieceID := pointer.GetRemote().RootPieceId
|
|
|
|
redundancy := pointer.GetRemote().GetRedundancy()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: pieces[0].NodeId,
|
|
|
|
PieceID: rootPieceID,
|
2019-09-11 23:37:01 +01:00
|
|
|
StripeIndex: randomIndex,
|
2019-06-11 21:14:40 +01:00
|
|
|
ShareSize: redundancy.ErasureShareSize,
|
2019-07-01 15:02:00 +01:00
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(nil),
|
2019-06-11 21:14:40 +01:00
|
|
|
ReverifyCount: 0,
|
2019-09-11 23:37:01 +01:00
|
|
|
Path: path,
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
err = satellite.DB.Containment().IncrementPending(ctx, pending)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-07-18 19:08:15 +01:00
|
|
|
nodeID := pieces[0].NodeId
|
2019-09-11 23:37:01 +01:00
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Offlines, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
require.Len(t, report.Fails, 1)
|
2019-07-18 19:08:15 +01:00
|
|
|
require.Equal(t, report.Fails[0], nodeID)
|
2019-06-11 21:14:40 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverifyOffline(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2019-06-11 21:14:40 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
// - 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
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
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)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pieces := pointer.GetRemote().GetRemotePieces()
|
|
|
|
rootPieceID := pointer.GetRemote().RootPieceId
|
|
|
|
redundancy := pointer.GetRemote().GetRedundancy()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: pieces[0].NodeId,
|
|
|
|
PieceID: rootPieceID,
|
2019-09-11 23:37:01 +01:00
|
|
|
StripeIndex: randomIndex,
|
2019-06-11 21:14:40 +01:00
|
|
|
ShareSize: redundancy.ErasureShareSize,
|
2019-06-26 11:38:51 +01:00
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(testrand.Bytes(10)),
|
2019-06-11 21:14:40 +01:00
|
|
|
ReverifyCount: 0,
|
2019-09-11 23:37:01 +01:00
|
|
|
Path: path,
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
err = satellite.DB.Containment().IncrementPending(ctx, pending)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = stopStorageNode(ctx, planet, pieces[0].NodeId)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Fails, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
require.Len(t, report.Offlines, 1)
|
|
|
|
require.Equal(t, report.Offlines[0], pieces[0].NodeId)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverifyOfflineDialTimeout(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-07-01 15:02:00 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2019-06-11 21:14:40 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
// - 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
|
|
|
|
// - 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
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
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)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
2019-06-11 21:14:40 +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
|
|
|
|
dialer.TransferRate = 1 * memory.KB
|
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"),
|
|
|
|
satellite.Metainfo.Service,
|
2019-09-19 05:46:39 +01:00
|
|
|
dialer,
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite.Overlay.Service,
|
|
|
|
satellite.DB.Containment(),
|
|
|
|
satellite.Orders.Service,
|
|
|
|
satellite.Identity,
|
2019-06-11 21:14:40 +01:00
|
|
|
minBytesPerSecond,
|
|
|
|
5*time.Second)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
pieces := pointer.GetRemote().GetRemotePieces()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
rootPieceID := pointer.GetRemote().RootPieceId
|
|
|
|
redundancy := pointer.GetRemote().GetRedundancy()
|
2019-06-11 21:14:40 +01:00
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: pieces[0].NodeId,
|
|
|
|
PieceID: rootPieceID,
|
2019-09-11 23:37:01 +01:00
|
|
|
StripeIndex: randomIndex,
|
2019-06-11 21:14:40 +01:00
|
|
|
ShareSize: redundancy.ErasureShareSize,
|
2019-07-01 15:02:00 +01:00
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(nil),
|
2019-06-11 21:14:40 +01:00
|
|
|
ReverifyCount: 0,
|
2019-09-11 23:37:01 +01:00
|
|
|
Path: path,
|
2019-06-11 21:14:40 +01:00
|
|
|
}
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
err = satellite.DB.Containment().IncrementPending(ctx, pending)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
report, err := verifier.Reverify(ctx, path)
|
2019-06-11 21:14:40 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Fails, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
require.Len(t, report.Offlines, 1)
|
|
|
|
require.Equal(t, report.Offlines[0], pending.NodeID)
|
|
|
|
})
|
|
|
|
}
|
2019-06-19 10:02:25 +01:00
|
|
|
|
|
|
|
func TestReverifyDeletedSegment(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-09-29 03:03:15 +01:00
|
|
|
// - uploads random data to all nodes
|
2019-09-11 23:37:01 +01:00
|
|
|
// - gets a path from the audit queue
|
|
|
|
// - 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
|
|
|
|
// - expects reverification to return a segment deleted error, and expects the storage node to still be in containment
|
|
|
|
// - uploads a new file and calls reverify on it
|
2019-06-19 10:02:25 +01:00
|
|
|
// - expects reverification to pass successufully and the storage node to be not in containment mode
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
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)
|
|
|
|
rs := &uplink.RSConfig{
|
|
|
|
MinThreshold: 1,
|
|
|
|
RepairThreshold: 2,
|
|
|
|
SuccessThreshold: 4,
|
|
|
|
MaxThreshold: 4,
|
|
|
|
}
|
2019-06-19 10:02:25 +01:00
|
|
|
|
2019-09-29 03:03:15 +01:00
|
|
|
err := ul.UploadWithConfig(ctx, satellite, rs, "testbucket", "test/path1", testData1)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
nodeID := pointer.GetRemote().GetRemotePieces()[0].NodeId
|
2019-06-19 10:02:25 +01:00
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: nodeID,
|
2019-09-11 23:37:01 +01:00
|
|
|
PieceID: pointer.GetRemote().RootPieceId,
|
|
|
|
StripeIndex: randomIndex,
|
|
|
|
ShareSize: pointer.GetRemote().GetRedundancy().GetErasureShareSize(),
|
2019-06-19 10:02:25 +01:00
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(nil),
|
|
|
|
ReverifyCount: 0,
|
2019-09-11 23:37:01 +01:00
|
|
|
Path: path,
|
2019-06-19 10:02:25 +01:00
|
|
|
}
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
containment := satellite.DB.Containment()
|
2019-06-19 10:02:25 +01:00
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// delete the file
|
2019-09-29 03:03:15 +01:00
|
|
|
err = ul.Delete(ctx, satellite, "testbucket", "test/path1")
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-29 03:03:15 +01:00
|
|
|
// call reverify on the deleted file and expect a segment deleted error
|
|
|
|
// but expect that the node is still in containment
|
2019-09-11 23:37:01 +01:00
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
|
|
|
require.True(t, audit.ErrSegmentDeleted.Has(err))
|
2019-06-19 10:02:25 +01:00
|
|
|
assert.Empty(t, report)
|
|
|
|
|
2019-09-29 03:03:15 +01:00
|
|
|
_, err = containment.Get(ctx, nodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// upload a new file to call reverify on
|
|
|
|
testData2 := testrand.Bytes(8 * memory.KiB)
|
|
|
|
err = ul.UploadWithConfig(ctx, satellite, rs, "testbucket", "test/path2", testData2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err = queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// reverify the new path
|
|
|
|
report, err = audits.Verifier.Reverify(ctx, path)
|
|
|
|
require.NoError(t, err)
|
2019-10-07 21:06:10 +01:00
|
|
|
assert.Empty(t, report.Fails)
|
|
|
|
assert.Empty(t, report.Successes)
|
|
|
|
assert.Empty(t, report.PendingAudits)
|
2019-09-29 03:03:15 +01:00
|
|
|
|
|
|
|
// expect that the node was removed from containment since the segment it was contained for has been deleted
|
2019-06-19 10:02:25 +01:00
|
|
|
_, err = containment.Get(ctx, nodeID)
|
|
|
|
require.True(t, audit.ErrContainedNotFound.Has(err))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverifyModifiedSegment(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-09-29 03:03:15 +01:00
|
|
|
// - uploads random data to a file on all nodes
|
|
|
|
// - creates a pending audit for a particular node in that file
|
|
|
|
// - re-uploads the file so that the segment is modified
|
|
|
|
// - uploads a new file to all nodes and calls reverify on it
|
2019-06-19 10:02:25 +01:00
|
|
|
// - expects reverification to pass successufully and the storage node to be not in containment mode
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
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)
|
|
|
|
rs := &uplink.RSConfig{
|
|
|
|
MinThreshold: 1,
|
|
|
|
RepairThreshold: 2,
|
|
|
|
SuccessThreshold: 4,
|
|
|
|
MaxThreshold: 4,
|
|
|
|
}
|
|
|
|
err := ul.UploadWithConfig(ctx, satellite, rs, "testbucket", "test/path1", testData1)
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
2019-09-29 03:03:15 +01:00
|
|
|
pendingPath, err := queue.Next()
|
2019-09-11 23:37:01 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-29 03:03:15 +01:00
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, pendingPath)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
nodeID := pointer.GetRemote().GetRemotePieces()[0].NodeId
|
2019-06-19 10:02:25 +01:00
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: nodeID,
|
2019-09-11 23:37:01 +01:00
|
|
|
PieceID: pointer.GetRemote().RootPieceId,
|
|
|
|
StripeIndex: randomIndex,
|
|
|
|
ShareSize: pointer.GetRemote().GetRedundancy().GetErasureShareSize(),
|
2019-06-19 10:02:25 +01:00
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(nil),
|
|
|
|
ReverifyCount: 0,
|
2019-09-29 03:03:15 +01:00
|
|
|
Path: pendingPath,
|
2019-06-19 10:02:25 +01:00
|
|
|
}
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
containment := satellite.DB.Containment()
|
2019-06-19 10:02:25 +01:00
|
|
|
|
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
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)
|
|
|
|
|
2019-09-29 03:03:15 +01:00
|
|
|
// upload another file to call reverify on
|
|
|
|
testData2 := testrand.Bytes(8 * memory.KiB)
|
|
|
|
err = ul.UploadWithConfig(ctx, satellite, rs, "testbucket", "test/path2", testData2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// select the encrypted path that was not used for the pending audit
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path1, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
path2, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
reverifyPath := path1
|
|
|
|
if path1 == pendingPath {
|
|
|
|
reverifyPath = path2
|
|
|
|
}
|
|
|
|
|
|
|
|
// reverify the path that was not modified
|
|
|
|
report, err := audits.Verifier.Reverify(ctx, reverifyPath)
|
2019-06-19 10:02:25 +01:00
|
|
|
require.NoError(t, err)
|
2019-10-07 21:06:10 +01:00
|
|
|
assert.Empty(t, report.Fails)
|
|
|
|
assert.Empty(t, report.Successes)
|
|
|
|
assert.Empty(t, report.PendingAudits)
|
2019-06-19 10:02:25 +01:00
|
|
|
|
2019-09-29 03:03:15 +01:00
|
|
|
// expect that the node was removed from containment since the segment it was contained for has been changed
|
2019-06-19 10:02:25 +01:00
|
|
|
_, err = containment.Get(ctx, nodeID)
|
|
|
|
require.True(t, audit.ErrContainedNotFound.Has(err))
|
|
|
|
})
|
|
|
|
}
|
2019-09-19 00:45:15 +01:00
|
|
|
|
|
|
|
func TestReverifyDifferentShare(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
// - uploads random data to two files
|
|
|
|
// - get a random stripe to audit from file 1
|
|
|
|
// - creates one pending audit for a node holding a piece for that stripe
|
|
|
|
// - the actual share is downloaded to make sure ExpectedShareHash is correct
|
|
|
|
// - delete piece for file 1 from the selected node
|
|
|
|
// - calls reverify on some stripe from file 2
|
|
|
|
// - expects one storage node to be marked as a fail in the audit report
|
|
|
|
// - (if file 2 is used during reverify, the node will pass the audit and the test should fail)
|
|
|
|
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData1 := testrand.Bytes(8 * memory.KiB)
|
|
|
|
testData2 := testrand.Bytes(8 * memory.KiB)
|
2019-09-19 15:50:16 +01:00
|
|
|
// upload to three nodes so there is definitely at least one node overlap between the two files
|
|
|
|
rs := &uplink.RSConfig{
|
|
|
|
MinThreshold: 1,
|
|
|
|
RepairThreshold: 2,
|
|
|
|
SuccessThreshold: 3,
|
|
|
|
MaxThreshold: 3,
|
|
|
|
}
|
|
|
|
err := ul.UploadWithConfig(ctx, satellite, rs, "testbucket", "test/path1", testData1)
|
2019-09-19 00:45:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-09-19 15:50:16 +01:00
|
|
|
err = ul.UploadWithConfig(ctx, satellite, rs, "testbucket", "test/path2", testData2)
|
2019-09-19 00:45:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path1, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
path2, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEqual(t, path1, path2)
|
|
|
|
|
|
|
|
pointer1, err := satellite.Metainfo.Service.Get(ctx, path1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
pointer2, err := satellite.Metainfo.Service.Get(ctx, path2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// find a node that contains a piece for both files
|
|
|
|
// save that node ID and the piece number associated with it for pointer1
|
|
|
|
var selectedNode storj.NodeID
|
|
|
|
var selectedPieceNum int32
|
|
|
|
p1Nodes := make(map[storj.NodeID]int32)
|
|
|
|
for _, piece := range pointer1.GetRemote().GetRemotePieces() {
|
|
|
|
p1Nodes[piece.NodeId] = piece.PieceNum
|
|
|
|
}
|
|
|
|
for _, piece := range pointer2.GetRemote().GetRemotePieces() {
|
|
|
|
pieceNum, ok := p1Nodes[piece.NodeId]
|
|
|
|
if ok {
|
|
|
|
selectedNode = piece.NodeId
|
|
|
|
selectedPieceNum = pieceNum
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotEqual(t, selectedNode, storj.NodeID{})
|
|
|
|
|
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
orders := satellite.Orders.Service
|
|
|
|
containment := satellite.DB.Containment()
|
|
|
|
|
|
|
|
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
bucketID := []byte(storj.JoinPaths(projects[0].ID.String(), "testbucket"))
|
|
|
|
shareSize := pointer1.GetRemote().GetRedundancy().GetErasureShareSize()
|
|
|
|
|
|
|
|
rootPieceID := pointer1.GetRemote().RootPieceId
|
|
|
|
limit, privateKey, err := orders.CreateAuditOrderLimit(ctx, bucketID, selectedNode, selectedPieceNum, rootPieceID, shareSize)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
share, err := audits.Verifier.GetShare(ctx, limit, privateKey, randomIndex, shareSize, int(selectedPieceNum))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: selectedNode,
|
|
|
|
PieceID: rootPieceID,
|
|
|
|
StripeIndex: randomIndex,
|
|
|
|
ShareSize: shareSize,
|
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(share.Data),
|
|
|
|
ReverifyCount: 0,
|
|
|
|
Path: path1,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// delete the piece for pointer1 from the selected node
|
|
|
|
pieceID := pointer1.GetRemote().RootPieceId.Derive(selectedNode, selectedPieceNum)
|
|
|
|
node := getStorageNode(planet, selectedNode)
|
|
|
|
err = node.Storage2.Store.Delete(ctx, satellite.ID(), pieceID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// reverify with path 2. Since the selected node was put in containment for path1,
|
|
|
|
// it should be audited for path1 and fail
|
|
|
|
report, err := audits.Verifier.Reverify(ctx, path2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Offlines, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
require.Len(t, report.Fails, 1)
|
|
|
|
require.Equal(t, report.Fails[0], selectedNode)
|
|
|
|
})
|
|
|
|
}
|
2019-11-05 19:41:48 +00:00
|
|
|
|
|
|
|
// TestReverifyExpired1 tests the case where the segment passed into Reverify is expired
|
|
|
|
func TestReverifyExpired1(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
|
|
|
|
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// set pointer's expiration date to be already expired
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
oldPointerBytes, err := proto.Marshal(pointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
newPointer := &pb.Pointer{}
|
|
|
|
err = proto.Unmarshal(oldPointerBytes, newPointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
newPointer.ExpirationDate = time.Now().UTC().Add(-1 * time.Hour)
|
|
|
|
newPointerBytes, err := proto.Marshal(newPointer)
|
|
|
|
require.NoError(t, err)
|
2019-11-06 17:02:14 +00:00
|
|
|
err = satellite.Metainfo.Database.CompareAndSwap(ctx, storage.Key(path), oldPointerBytes, newPointerBytes)
|
2019-11-05 19:41:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.True(t, audit.ErrSegmentExpired.Has(err))
|
|
|
|
|
|
|
|
// Reverify should delete the expired segment
|
|
|
|
pointer, err = satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, pointer)
|
|
|
|
|
|
|
|
assert.Len(t, report.Successes, 0)
|
|
|
|
assert.Len(t, report.Fails, 0)
|
|
|
|
assert.Len(t, report.Offlines, 0)
|
|
|
|
assert.Len(t, report.PendingAudits, 0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestReverifyExpired2 tests the case where the segment passed into Reverify is not expired,
|
|
|
|
// but the segment a node is contained for has expired.
|
|
|
|
func TestReverifyExpired2(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData1 := testrand.Bytes(8 * memory.KiB)
|
|
|
|
testData2 := testrand.Bytes(8 * memory.KiB)
|
|
|
|
// upload to three nodes so there is definitely at least one node overlap between the two files
|
|
|
|
rs := &uplink.RSConfig{
|
|
|
|
MinThreshold: 1,
|
|
|
|
RepairThreshold: 2,
|
|
|
|
SuccessThreshold: 3,
|
|
|
|
MaxThreshold: 3,
|
|
|
|
}
|
|
|
|
err := ul.UploadWithConfig(ctx, satellite, rs, "testbucket", "test/path1", testData1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = ul.UploadWithConfig(ctx, satellite, rs, "testbucket", "test/path2", testData2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path1, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
path2, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEqual(t, path1, path2)
|
|
|
|
|
|
|
|
pointer1, err := satellite.Metainfo.Service.Get(ctx, path1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
pointer2, err := satellite.Metainfo.Service.Get(ctx, path2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// find a node that contains a piece for both files
|
|
|
|
// save that node ID and the piece number associated with it for pointer1
|
|
|
|
var selectedNode storj.NodeID
|
|
|
|
var selectedPieceNum int32
|
|
|
|
p1Nodes := make(map[storj.NodeID]int32)
|
|
|
|
for _, piece := range pointer1.GetRemote().GetRemotePieces() {
|
|
|
|
p1Nodes[piece.NodeId] = piece.PieceNum
|
|
|
|
}
|
|
|
|
for _, piece := range pointer2.GetRemote().GetRemotePieces() {
|
|
|
|
pieceNum, ok := p1Nodes[piece.NodeId]
|
|
|
|
if ok {
|
|
|
|
selectedNode = piece.NodeId
|
|
|
|
selectedPieceNum = pieceNum
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotEqual(t, selectedNode, storj.NodeID{})
|
|
|
|
|
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
orders := satellite.Orders.Service
|
|
|
|
containment := satellite.DB.Containment()
|
|
|
|
|
|
|
|
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
bucketID := []byte(storj.JoinPaths(projects[0].ID.String(), "testbucket"))
|
|
|
|
shareSize := pointer1.GetRemote().GetRedundancy().GetErasureShareSize()
|
|
|
|
|
|
|
|
rootPieceID := pointer1.GetRemote().RootPieceId
|
|
|
|
limit, privateKey, err := orders.CreateAuditOrderLimit(ctx, bucketID, selectedNode, selectedPieceNum, rootPieceID, shareSize)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
share, err := audits.Verifier.GetShare(ctx, limit, privateKey, randomIndex, shareSize, int(selectedPieceNum))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: selectedNode,
|
|
|
|
PieceID: rootPieceID,
|
|
|
|
StripeIndex: randomIndex,
|
|
|
|
ShareSize: shareSize,
|
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(share.Data),
|
|
|
|
ReverifyCount: 0,
|
|
|
|
Path: path1,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// update pointer1 to be expired
|
|
|
|
oldPointerBytes, err := proto.Marshal(pointer1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
newPointer := &pb.Pointer{}
|
|
|
|
err = proto.Unmarshal(oldPointerBytes, newPointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
newPointer.ExpirationDate = time.Now().UTC().Add(-1 * time.Hour)
|
|
|
|
newPointerBytes, err := proto.Marshal(newPointer)
|
|
|
|
require.NoError(t, err)
|
2019-11-06 17:02:14 +00:00
|
|
|
err = satellite.Metainfo.Database.CompareAndSwap(ctx, storage.Key(path1), oldPointerBytes, newPointerBytes)
|
2019-11-05 19:41:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// reverify with path 2. Since the selected node was put in containment for path1,
|
|
|
|
// it should be audited for path1
|
|
|
|
// since path1 has expired, we expect no failure and we expect that the pointer has been deleted
|
|
|
|
// and that the selected node has been removed from containment mode
|
|
|
|
report, err := audits.Verifier.Reverify(ctx, path2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Offlines, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
require.Len(t, report.Fails, 0)
|
|
|
|
|
|
|
|
// Reverify should delete the expired segment
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path1)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, pointer)
|
|
|
|
|
|
|
|
// Reverify should remove the node from containment mode
|
|
|
|
_, err = containment.Get(ctx, pending.NodeID)
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
2019-11-19 16:30:28 +00:00
|
|
|
|
|
|
|
// TestReverifySlowDownload checks that a node that times out while sending data to the
|
|
|
|
// audit service gets put into containment mode
|
|
|
|
func TestReverifySlowDownload(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
NewStorageNodeDB: func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error) {
|
|
|
|
return testblobs.NewSlowDB(log.Named("slowdb"), db), nil
|
|
|
|
},
|
|
|
|
Satellite: 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
|
|
|
|
config.Audit.MinDownloadTimeout = 500 * time.Millisecond
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
|
|
|
|
|
|
|
err := ul.UploadWithConfig(ctx, satellite, &uplink.RSConfig{
|
|
|
|
MinThreshold: 2,
|
|
|
|
RepairThreshold: 2,
|
|
|
|
SuccessThreshold: 4,
|
|
|
|
MaxThreshold: 4,
|
|
|
|
}, "testbucket", "test/path", testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
slowPiece := pointer.Remote.RemotePieces[0]
|
|
|
|
slowNode := slowPiece.NodeId
|
|
|
|
|
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
orders := satellite.Orders.Service
|
|
|
|
containment := satellite.DB.Containment()
|
|
|
|
|
|
|
|
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
bucketID := []byte(storj.JoinPaths(projects[0].ID.String(), "testbucket"))
|
|
|
|
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
|
|
|
|
|
|
|
|
pieces := pointer.GetRemote().GetRemotePieces()
|
|
|
|
rootPieceID := pointer.GetRemote().RootPieceId
|
|
|
|
limit, privateKey, err := orders.CreateAuditOrderLimit(ctx, bucketID, slowNode, slowPiece.PieceNum, rootPieceID, shareSize)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
share, err := audits.Verifier.GetShare(ctx, limit, privateKey, randomIndex, shareSize, int(pieces[0].PieceNum))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: slowNode,
|
|
|
|
PieceID: pointer.Remote.RootPieceId,
|
|
|
|
StripeIndex: randomIndex,
|
|
|
|
ShareSize: shareSize,
|
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(share.Data),
|
|
|
|
ReverifyCount: 0,
|
|
|
|
Path: path,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for _, node := range planet.StorageNodes {
|
|
|
|
if node.ID() == slowNode {
|
|
|
|
slowNodeDB := node.DB.(*testblobs.SlowDB)
|
|
|
|
// make downloads on storage node slower than the timeout on the satellite for downloading shares
|
|
|
|
delay := 1 * time.Second
|
|
|
|
slowNodeDB.SetLatency(delay)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Fails, 0)
|
|
|
|
require.Len(t, report.Offlines, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 1)
|
|
|
|
require.Len(t, report.Unknown, 0)
|
|
|
|
require.Equal(t, report.PendingAudits[0].NodeID, slowNode)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
NewStorageNodeDB: func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error) {
|
|
|
|
return testblobs.NewBadDB(log.Named("baddb"), db), nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
queue := audits.Queue
|
|
|
|
|
|
|
|
audits.Worker.Loop.Pause()
|
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
|
|
|
|
|
|
|
err := ul.UploadWithConfig(ctx, satellite, &uplink.RSConfig{
|
|
|
|
MinThreshold: 2,
|
|
|
|
RepairThreshold: 2,
|
|
|
|
SuccessThreshold: 4,
|
|
|
|
MaxThreshold: 4,
|
|
|
|
}, "testbucket", "test/path", testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
path, err := queue.Next()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pointer, err := satellite.Metainfo.Service.Get(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
badPiece := pointer.Remote.RemotePieces[0]
|
|
|
|
badNode := badPiece.NodeId
|
|
|
|
|
|
|
|
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
orders := satellite.Orders.Service
|
|
|
|
containment := satellite.DB.Containment()
|
|
|
|
|
|
|
|
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
bucketID := []byte(storj.JoinPaths(projects[0].ID.String(), "testbucket"))
|
|
|
|
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
|
|
|
|
|
|
|
|
pieces := pointer.GetRemote().GetRemotePieces()
|
|
|
|
rootPieceID := pointer.GetRemote().RootPieceId
|
|
|
|
limit, privateKey, err := orders.CreateAuditOrderLimit(ctx, bucketID, badNode, badPiece.PieceNum, rootPieceID, shareSize)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
share, err := audits.Verifier.GetShare(ctx, limit, privateKey, randomIndex, shareSize, int(pieces[0].PieceNum))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pending := &audit.PendingAudit{
|
|
|
|
NodeID: badNode,
|
|
|
|
PieceID: pointer.Remote.RootPieceId,
|
|
|
|
StripeIndex: randomIndex,
|
|
|
|
ShareSize: shareSize,
|
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash(share.Data),
|
|
|
|
ReverifyCount: 0,
|
|
|
|
Path: path,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = containment.IncrementPending(ctx, pending)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for _, node := range planet.StorageNodes {
|
|
|
|
if node.ID() == badNode {
|
|
|
|
badNodeDB := node.DB.(*testblobs.BadDB)
|
|
|
|
// return an error when the satellite requests a share
|
|
|
|
badNodeDB.SetError(errs.New("unknown error"))
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
report, err := audits.Verifier.Reverify(ctx, path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, report.Successes, 0)
|
|
|
|
require.Len(t, report.Fails, 0)
|
|
|
|
require.Len(t, report.Offlines, 0)
|
|
|
|
require.Len(t, report.PendingAudits, 0)
|
|
|
|
require.Len(t, report.Unknown, 1)
|
|
|
|
require.Equal(t, report.Unknown[0], badNode)
|
|
|
|
})
|
|
|
|
}
|