2019-12-11 17:44:13 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metainfo_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-16 19:12:09 +00:00
|
|
|
"strconv"
|
2019-12-11 17:44:13 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2020-01-01 18:33:12 +00:00
|
|
|
"storj.io/storj/cmd/uplink/cmd"
|
2019-12-11 17:44:13 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEndpoint_DeleteObjectPieces(t *testing.T) {
|
|
|
|
t.Run("all nodes up", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.ReconfigureRS(2, 2, 4, 4),
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
var (
|
|
|
|
uplnk = planet.Uplinks[0]
|
|
|
|
satelliteSys = planet.Satellites[0]
|
|
|
|
)
|
|
|
|
|
|
|
|
var testCases = []struct {
|
|
|
|
caseDescription string
|
|
|
|
objData []byte
|
|
|
|
}{
|
|
|
|
{caseDescription: "one remote segment", objData: testrand.Bytes(10 * memory.KiB)},
|
|
|
|
{caseDescription: "one inline segment", objData: testrand.Bytes(3 * memory.KiB)},
|
|
|
|
{caseDescription: "several segments (all remote)", objData: testrand.Bytes(50 * memory.KiB)},
|
|
|
|
{caseDescription: "several segments (remote + inline)", objData: testrand.Bytes(33 * memory.KiB)},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
|
|
|
i := i
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.caseDescription, func(t *testing.T) {
|
|
|
|
var (
|
|
|
|
bucketName = "a-bucket"
|
|
|
|
objectName = "object-filename" + strconv.Itoa(i)
|
|
|
|
)
|
|
|
|
|
|
|
|
// Use RSConfig for ensuring that we don't have long-tail cancellations and the
|
|
|
|
// upload doesn't leave garbage in the SNs
|
|
|
|
err := uplnk.UploadWithClientConfig(ctx, satelliteSys, cmd.Config{
|
|
|
|
Client: cmd.ClientConfig{
|
|
|
|
SegmentSize: 10 * memory.KiB,
|
|
|
|
},
|
2019-12-11 17:44:13 +00:00
|
|
|
},
|
2020-01-21 10:38:41 +00:00
|
|
|
bucketName, objectName, tc.objData,
|
|
|
|
)
|
2020-01-07 18:34:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
// calculate the SNs total used space after data upload
|
|
|
|
var totalUsedSpace int64
|
|
|
|
for _, sn := range planet.StorageNodes {
|
|
|
|
usedSpace, err := sn.Storage2.Store.SpaceUsedForPieces(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
totalUsedSpace += usedSpace
|
|
|
|
}
|
|
|
|
|
|
|
|
projectID, encryptedPath := getProjectIDAndEncPathFirstObject(ctx, t, satelliteSys)
|
|
|
|
err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(
|
|
|
|
ctx, *projectID, []byte(bucketName), encryptedPath,
|
|
|
|
)
|
2019-12-11 17:44:13 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-21 10:38:41 +00:00
|
|
|
|
|
|
|
// calculate the SNs used space after delete the pieces
|
|
|
|
var totalUsedSpaceAfterDelete int64
|
|
|
|
for _, sn := range planet.StorageNodes {
|
|
|
|
usedSpace, err := sn.Storage2.Store.SpaceUsedForPieces(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
totalUsedSpaceAfterDelete += usedSpace
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point we can only guarantee that the 75% of the SNs pieces
|
|
|
|
// are delete due to the success threshold
|
|
|
|
deletedUsedSpace := float64(totalUsedSpace-totalUsedSpaceAfterDelete) / float64(totalUsedSpace)
|
|
|
|
if deletedUsedSpace < 0.75 {
|
|
|
|
t.Fatalf("deleted used space is less than 0.75%%. Got %f", deletedUsedSpace)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-12-11 17:44:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("some nodes down", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var testCases = []struct {
|
|
|
|
caseDescription string
|
|
|
|
objData []byte
|
|
|
|
}{
|
|
|
|
{caseDescription: "one remote segment", objData: testrand.Bytes(10 * memory.KiB)},
|
|
|
|
{caseDescription: "several segments (all remote)", objData: testrand.Bytes(50 * memory.KiB)},
|
|
|
|
{caseDescription: "several segments (remote + inline)", objData: testrand.Bytes(33 * memory.KiB)},
|
|
|
|
}
|
|
|
|
|
2020-01-16 19:12:09 +00:00
|
|
|
for i, tc := range testCases {
|
|
|
|
i := i
|
2019-12-11 17:44:13 +00:00
|
|
|
tc := tc
|
|
|
|
t.Run(tc.caseDescription, func(t *testing.T) {
|
|
|
|
|
2020-01-16 19:12:09 +00:00
|
|
|
var (
|
2019-12-11 17:44:13 +00:00
|
|
|
bucketName = "a-bucket"
|
2020-01-16 19:12:09 +00:00
|
|
|
objectName = "object-filename" + strconv.Itoa(i)
|
2019-12-11 17:44:13 +00:00
|
|
|
)
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.ReconfigureRS(2, 2, 4, 4),
|
2019-12-11 17:44:13 +00:00
|
|
|
},
|
2020-01-21 10:38:41 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
var (
|
|
|
|
uplnk = planet.Uplinks[0]
|
|
|
|
satelliteSys = planet.Satellites[0]
|
|
|
|
)
|
|
|
|
// Use RSConfig for ensuring that we don't have long-tail cancellations and the
|
|
|
|
// upload doesn't leave garbage in the SNs
|
|
|
|
err := uplnk.UploadWithClientConfig(ctx, satelliteSys, cmd.Config{
|
|
|
|
Client: cmd.ClientConfig{
|
|
|
|
SegmentSize: 10 * memory.KiB,
|
|
|
|
},
|
|
|
|
}, bucketName, objectName, tc.objData)
|
2019-12-11 17:44:13 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
// Shutdown the first 2 storage nodes before we delete the pieces
|
|
|
|
require.NoError(t, planet.StopPeer(planet.StorageNodes[0]))
|
|
|
|
require.NoError(t, planet.StopPeer(planet.StorageNodes[1]))
|
2019-12-11 17:44:13 +00:00
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
projectID, encryptedPath := getProjectIDAndEncPathFirstObject(ctx, t, satelliteSys)
|
|
|
|
err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(
|
|
|
|
ctx, *projectID, []byte(bucketName), encryptedPath,
|
|
|
|
)
|
2019-12-11 17:44:13 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
// Check that storage nodes that were offline when deleting the pieces
|
|
|
|
// they are still holding data
|
|
|
|
var totalUsedSpace int64
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
usedSpace, err := planet.StorageNodes[i].Storage2.Store.SpaceUsedForPieces(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
totalUsedSpace += usedSpace
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NotZero(t, totalUsedSpace, "totalUsedSpace offline nodes")
|
|
|
|
|
|
|
|
// Check that storage nodes which are online when deleting pieces don't
|
|
|
|
// hold any piece
|
|
|
|
totalUsedSpace = 0
|
|
|
|
for i := 2; i < len(planet.StorageNodes); i++ {
|
|
|
|
usedSpace, err := planet.StorageNodes[i].Storage2.Store.SpaceUsedForPieces(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
totalUsedSpace += usedSpace
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Zero(t, totalUsedSpace, "totalUsedSpace online nodes")
|
|
|
|
})
|
2019-12-11 17:44:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("all nodes down", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var testCases = []struct {
|
|
|
|
caseDescription string
|
|
|
|
objData []byte
|
|
|
|
}{
|
|
|
|
{caseDescription: "one remote segment", objData: testrand.Bytes(10 * memory.KiB)},
|
|
|
|
{caseDescription: "several segments (all remote)", objData: testrand.Bytes(50 * memory.KiB)},
|
|
|
|
{caseDescription: "several segments (remote + inline)", objData: testrand.Bytes(33 * memory.KiB)},
|
|
|
|
}
|
|
|
|
|
2020-01-16 19:12:09 +00:00
|
|
|
for i, tc := range testCases {
|
|
|
|
i := i
|
2019-12-11 17:44:13 +00:00
|
|
|
tc := tc
|
|
|
|
t.Run(tc.caseDescription, func(t *testing.T) {
|
2020-01-16 19:12:09 +00:00
|
|
|
var (
|
2019-12-11 17:44:13 +00:00
|
|
|
bucketName = "a-bucket"
|
2020-01-16 19:12:09 +00:00
|
|
|
objectName = "object-filename" + strconv.Itoa(i)
|
2019-12-11 17:44:13 +00:00
|
|
|
)
|
2020-01-21 10:38:41 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: testplanet.ReconfigureRS(2, 2, 4, 4),
|
2019-12-11 17:44:13 +00:00
|
|
|
},
|
2020-01-21 10:38:41 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
var (
|
|
|
|
uplnk = planet.Uplinks[0]
|
|
|
|
satelliteSys = planet.Satellites[0]
|
|
|
|
)
|
|
|
|
|
|
|
|
// Use RSConfig for ensuring that we don't have long-tail cancellations and the
|
|
|
|
// upload doesn't leave garbage in the SNs
|
|
|
|
err := uplnk.UploadWithClientConfig(ctx, satelliteSys, cmd.Config{
|
|
|
|
Client: cmd.ClientConfig{
|
|
|
|
SegmentSize: 10 * memory.KiB,
|
|
|
|
},
|
|
|
|
}, bucketName, objectName, tc.objData)
|
|
|
|
require.NoError(t, err)
|
2019-12-11 17:44:13 +00:00
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
// Shutdown all the storage nodes before we delete the pieces
|
|
|
|
for _, sn := range planet.StorageNodes {
|
|
|
|
require.NoError(t, planet.StopPeer(sn))
|
|
|
|
}
|
2019-12-11 17:44:13 +00:00
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
projectID, encryptedPath := getProjectIDAndEncPathFirstObject(ctx, t, satelliteSys)
|
|
|
|
err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(
|
|
|
|
ctx, *projectID, []byte(bucketName), encryptedPath,
|
|
|
|
)
|
2019-12-11 17:44:13 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-01-21 10:38:41 +00:00
|
|
|
// Check that storage nodes that were offline when deleting the pieces
|
|
|
|
// they are still holding data
|
|
|
|
var totalUsedSpace int64
|
|
|
|
for _, sn := range planet.StorageNodes {
|
|
|
|
usedSpace, err := sn.Storage2.Store.SpaceUsedForPieces(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
totalUsedSpace += usedSpace
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NotZero(t, totalUsedSpace, "totalUsedSpace")
|
|
|
|
})
|
2019-12-11 17:44:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func getProjectIDAndEncPathFirstObject(
|
|
|
|
ctx context.Context, t *testing.T, satellite *testplanet.SatelliteSystem,
|
|
|
|
) (projectID *uuid.UUID, encryptedPath []byte) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
keys, err := satellite.Metainfo.Database.List(ctx, storage.Key{}, 1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
keyParts := storj.SplitPath(keys[0].String())
|
|
|
|
require.Len(t, keyParts, 4)
|
|
|
|
projectID, err = uuid.Parse(keyParts[0])
|
|
|
|
require.NoError(t, err)
|
|
|
|
encryptedPath = []byte(keyParts[3])
|
|
|
|
|
|
|
|
return projectID, encryptedPath
|
|
|
|
}
|