2019-02-04 16:56:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package testplanet_test
|
|
|
|
|
|
|
|
import (
|
2019-06-21 17:41:39 +01:00
|
|
|
"bytes"
|
2019-04-25 09:17:26 +01:00
|
|
|
"context"
|
2019-06-21 17:41:39 +01:00
|
|
|
"fmt"
|
2019-04-25 09:17:26 +01:00
|
|
|
"path/filepath"
|
2019-02-04 16:56:10 +00:00
|
|
|
"testing"
|
2019-04-25 09:17:26 +01:00
|
|
|
"time"
|
2019-02-04 16:56:10 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-04-10 18:35:43 +01:00
|
|
|
"golang.org/x/sync/errgroup"
|
2019-02-04 16:56:10 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/memory"
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
2019-06-26 11:38:51 +01:00
|
|
|
"storj.io/storj/internal/testrand"
|
2019-03-26 18:09:44 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2019-04-25 09:17:26 +01:00
|
|
|
"storj.io/storj/pkg/peertls/extensions"
|
|
|
|
"storj.io/storj/pkg/peertls/tlsopts"
|
2019-08-19 23:10:38 +01:00
|
|
|
"storj.io/storj/pkg/revocation"
|
2019-04-25 09:17:26 +01:00
|
|
|
"storj.io/storj/pkg/server"
|
2019-03-26 18:09:44 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
"storj.io/storj/uplink"
|
2019-02-04 16:56:10 +00:00
|
|
|
)
|
|
|
|
|
2019-06-21 17:41:39 +01:00
|
|
|
func TestUplinksParallel(t *testing.T) {
|
2019-06-25 17:30:39 +01:00
|
|
|
t.Skip("flaky")
|
|
|
|
|
2019-06-21 17:41:39 +01:00
|
|
|
const uplinkCount = 3
|
|
|
|
const parallelCount = 2
|
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-06-21 17:41:39 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: uplinkCount,
|
2019-04-22 10:07:50 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-06-21 17:41:39 +01:00
|
|
|
satellite := planet.Satellites[0]
|
2019-02-04 16:56:10 +00:00
|
|
|
|
2019-06-21 17:41:39 +01:00
|
|
|
var group errgroup.Group
|
|
|
|
for i := range planet.Uplinks {
|
|
|
|
uplink := planet.Uplinks[i]
|
2019-02-04 16:56:10 +00:00
|
|
|
|
2019-06-21 17:41:39 +01:00
|
|
|
for p := 0; p < parallelCount; p++ {
|
|
|
|
suffix := fmt.Sprintf("-%d-%d", i, p)
|
|
|
|
group.Go(func() error {
|
2019-06-26 11:38:51 +01:00
|
|
|
data := testrand.Bytes(memory.Size(100+testrand.Intn(500)) * memory.KiB)
|
2019-06-21 17:41:39 +01:00
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
err := uplink.Upload(ctx, satellite, "testbucket"+suffix, "test/path"+suffix, data)
|
2019-06-21 17:41:39 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
downloaded, err := uplink.Download(ctx, satellite, "testbucket"+suffix, "test/path"+suffix)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(data, downloaded) {
|
|
|
|
return fmt.Errorf("upload != download data: %s", suffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err := group.Wait()
|
|
|
|
require.NoError(t, err)
|
2019-04-22 10:07:50 +01:00
|
|
|
})
|
|
|
|
}
|
2019-02-04 16:56:10 +00:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
func TestDownloadWithSomeNodesOffline(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 5, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
// first, upload some remote data
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
satellite := planet.Satellites[0]
|
2019-02-04 16:56:10 +00:00
|
|
|
|
2019-08-06 17:35:59 +01:00
|
|
|
// stop discovery service so that we do not get a race condition when we delete nodes from overlay
|
2019-04-22 10:07:50 +01:00
|
|
|
satellite.Discovery.Service.Discovery.Stop()
|
2019-02-04 16:56:10 +00:00
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
testData := testrand.Bytes(memory.MiB)
|
2019-03-26 18:09:44 +00:00
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
err := ul.UploadWithConfig(ctx, satellite, &uplink.RSConfig{
|
2019-04-22 10:07:50 +01:00
|
|
|
MinThreshold: 2,
|
|
|
|
RepairThreshold: 3,
|
|
|
|
SuccessThreshold: 4,
|
|
|
|
MaxThreshold: 5,
|
|
|
|
}, "testbucket", "test/path", testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// get a remote segment from pointerdb
|
|
|
|
pdb := satellite.Metainfo.Service
|
2019-06-05 15:23:10 +01:00
|
|
|
listResponse, _, err := pdb.List(ctx, "", "", "", true, 0, 0)
|
2019-04-10 13:10:08 +01:00
|
|
|
require.NoError(t, err)
|
2019-04-22 10:07:50 +01:00
|
|
|
|
|
|
|
var path string
|
|
|
|
var pointer *pb.Pointer
|
|
|
|
for _, v := range listResponse {
|
|
|
|
path = v.GetPath()
|
2019-06-05 15:23:10 +01:00
|
|
|
pointer, err = pdb.Get(ctx, path)
|
2019-04-22 10:07:50 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
if pointer.GetType() == pb.Pointer_REMOTE {
|
|
|
|
break
|
|
|
|
}
|
2019-03-26 18:09:44 +00:00
|
|
|
}
|
2019-04-22 10:07:50 +01:00
|
|
|
|
|
|
|
// calculate how many storagenodes to kill
|
|
|
|
redundancy := pointer.GetRemote().GetRedundancy()
|
|
|
|
remotePieces := pointer.GetRemote().GetRemotePieces()
|
|
|
|
minReq := redundancy.GetMinReq()
|
|
|
|
numPieces := len(remotePieces)
|
|
|
|
toKill := numPieces - int(minReq)
|
|
|
|
|
|
|
|
nodesToKill := make(map[storj.NodeID]bool)
|
|
|
|
for i, piece := range remotePieces {
|
|
|
|
if i >= toKill {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
nodesToKill[piece.NodeId] = true
|
2019-04-10 13:10:08 +01:00
|
|
|
}
|
2019-03-26 18:09:44 +00:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
for _, node := range planet.StorageNodes {
|
|
|
|
if nodesToKill[node.ID()] {
|
|
|
|
err = planet.StopPeer(node)
|
|
|
|
require.NoError(t, err)
|
2019-03-26 18:09:44 +00:00
|
|
|
|
2019-08-06 17:35:59 +01:00
|
|
|
// mark node as offline in overlay
|
2019-04-22 10:07:50 +01:00
|
|
|
_, err = satellite.Overlay.Service.UpdateUptime(ctx, node.ID(), false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2019-03-26 18:09:44 +00:00
|
|
|
}
|
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
// we should be able to download data without any of the original nodes
|
|
|
|
newData, err := ul.Download(ctx, satellite, "testbucket", "test/path")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, testData, newData)
|
|
|
|
})
|
2019-03-26 18:09:44 +00:00
|
|
|
}
|
2019-04-10 18:35:43 +01:00
|
|
|
|
2019-04-25 09:17:26 +01:00
|
|
|
type piecestoreMock struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mock *piecestoreMock) Upload(server pb.Piecestore_UploadServer) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (mock *piecestoreMock) Download(server pb.Piecestore_DownloadServer) error {
|
|
|
|
timoutTicker := time.NewTicker(30 * time.Second)
|
|
|
|
defer timoutTicker.Stop()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-timoutTicker.C:
|
|
|
|
return nil
|
|
|
|
case <-server.Context().Done():
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (mock *piecestoreMock) Delete(ctx context.Context, delete *pb.PieceDeleteRequest) (_ *pb.PieceDeleteResponse, err error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2019-07-11 21:04:22 +01:00
|
|
|
func (mock *piecestoreMock) Retain(ctx context.Context, retain *pb.RetainRequest) (_ *pb.RetainResponse, err error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2019-04-25 09:17:26 +01:00
|
|
|
|
|
|
|
func TestDownloadFromUnresponsiveNode(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 5, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-06-26 11:38:51 +01:00
|
|
|
expectedData := testrand.Bytes(memory.MiB)
|
2019-04-25 09:17:26 +01:00
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
err := planet.Uplinks[0].UploadWithConfig(ctx, planet.Satellites[0], &uplink.RSConfig{
|
2019-04-25 09:17:26 +01:00
|
|
|
MinThreshold: 2,
|
|
|
|
RepairThreshold: 3,
|
|
|
|
SuccessThreshold: 4,
|
|
|
|
MaxThreshold: 5,
|
|
|
|
}, "testbucket", "test/path", expectedData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// get a remote segment from pointerdb
|
|
|
|
pdb := planet.Satellites[0].Metainfo.Service
|
2019-06-05 15:23:10 +01:00
|
|
|
listResponse, _, err := pdb.List(ctx, "", "", "", true, 0, 0)
|
2019-04-25 09:17:26 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var path string
|
|
|
|
var pointer *pb.Pointer
|
|
|
|
for _, v := range listResponse {
|
|
|
|
path = v.GetPath()
|
2019-06-05 15:23:10 +01:00
|
|
|
pointer, err = pdb.Get(ctx, path)
|
2019-04-25 09:17:26 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
if pointer.GetType() == pb.Pointer_REMOTE {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stopped := false
|
|
|
|
// choose used storage node and replace it with fake listener
|
|
|
|
unresponsiveNode := pointer.Remote.RemotePieces[0].NodeId
|
|
|
|
for _, storageNode := range planet.StorageNodes {
|
|
|
|
if storageNode.ID() == unresponsiveNode {
|
|
|
|
err = planet.StopPeer(storageNode)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
wl, err := planet.WriteWhitelist(storj.LatestIDVersion())
|
|
|
|
require.NoError(t, err)
|
2019-08-19 23:10:38 +01:00
|
|
|
tlscfg := tlsopts.Config{
|
2019-04-25 09:17:26 +01:00
|
|
|
RevocationDBURL: "bolt://" + filepath.Join(ctx.Dir("fakestoragenode"), "revocation.db"),
|
|
|
|
UsePeerCAWhitelist: true,
|
|
|
|
PeerCAWhitelistPath: wl,
|
|
|
|
PeerIDVersions: "*",
|
|
|
|
Extensions: extensions.Config{
|
|
|
|
Revocation: false,
|
|
|
|
WhitelistSignedLeaf: false,
|
|
|
|
},
|
2019-08-19 23:10:38 +01:00
|
|
|
}
|
2019-08-20 16:04:17 +01:00
|
|
|
|
|
|
|
revocationDB, err := revocation.NewDBFromCfg(tlscfg)
|
2019-08-19 23:10:38 +01:00
|
|
|
require.NoError(t, err)
|
2019-08-20 16:04:17 +01:00
|
|
|
|
|
|
|
options, err := tlsopts.NewOptions(storageNode.Identity, tlscfg, revocationDB)
|
2019-04-25 09:17:26 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-07-31 13:09:45 +01:00
|
|
|
server, err := server.New(storageNode.Log.Named("mock-server"), options, storageNode.Addr(), storageNode.PrivateAddr(), nil)
|
2019-04-25 09:17:26 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
pb.RegisterPiecestoreServer(server.GRPC(), &piecestoreMock{})
|
|
|
|
go func() {
|
2019-08-20 16:04:17 +01:00
|
|
|
// TODO: get goroutine under control
|
2019-04-25 09:17:26 +01:00
|
|
|
err := server.Run(ctx)
|
|
|
|
require.NoError(t, err)
|
2019-08-20 16:04:17 +01:00
|
|
|
|
|
|
|
err = revocationDB.Close()
|
|
|
|
require.NoError(t, err)
|
2019-04-25 09:17:26 +01:00
|
|
|
}()
|
|
|
|
stopped = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert.True(t, stopped, "no storage node was altered")
|
|
|
|
|
|
|
|
data, err := planet.Uplinks[0].Download(ctx, planet.Satellites[0], "testbucket", "test/path")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, expectedData, data)
|
|
|
|
})
|
|
|
|
}
|