satellite/metainfo: fix TestEndpoint_DeleteObjectPieces tests
This also removes the TestEndpoint_DeleteObjectPieces_ObjectWithoutLastSegment test case as it does not seem relevant to metabase. Change-Id: I06a0ecaa8232c10c15e433517a7ba056933bf858
This commit is contained in:
parent
fb5244e8f1
commit
d0d0a192cd
@ -4,7 +4,6 @@
|
||||
package metainfo_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
@ -15,12 +14,7 @@ import (
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite/metainfo"
|
||||
"storj.io/storj/satellite/metainfo/metabase"
|
||||
"storj.io/storj/storage"
|
||||
"storj.io/uplink/private/testuplink"
|
||||
)
|
||||
|
||||
func TestEndpoint_DeleteObjectPieces(t *testing.T) {
|
||||
@ -75,8 +69,12 @@ func TestEndpoint_DeleteObjectPieces(t *testing.T) {
|
||||
totalUsedSpace += piecesTotal
|
||||
}
|
||||
|
||||
projectID, encryptedPath := getProjectIDAndEncPathFirstObject(ctx, t, satelliteSys)
|
||||
_, err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(ctx, projectID, []byte(bucketName), encryptedPath)
|
||||
projectID := uplnk.Projects[0].ID
|
||||
items, err := satelliteSys.Metainfo.Metabase.TestingAllCommittedObjects(ctx, projectID, bucketName)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 1)
|
||||
|
||||
_, err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(ctx, projectID, bucketName, items[0].ObjectKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
planet.WaitForStorageNodeDeleters(ctx)
|
||||
@ -148,10 +146,12 @@ func TestEndpoint_DeleteObjectPieces(t *testing.T) {
|
||||
require.NoError(t, planet.StopPeer(planet.StorageNodes[0]))
|
||||
require.NoError(t, planet.StopPeer(planet.StorageNodes[1]))
|
||||
|
||||
projectID, encryptedPath := getProjectIDAndEncPathFirstObject(ctx, t, satelliteSys)
|
||||
_, err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(
|
||||
ctx, projectID, []byte(bucketName), encryptedPath,
|
||||
)
|
||||
projectID := uplnk.Projects[0].ID
|
||||
items, err := satelliteSys.Metainfo.Metabase.TestingAllCommittedObjects(ctx, projectID, bucketName)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 1)
|
||||
|
||||
_, err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(ctx, projectID, bucketName, items[0].ObjectKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
planet.WaitForStorageNodeDeleters(ctx)
|
||||
@ -225,10 +225,12 @@ func TestEndpoint_DeleteObjectPieces(t *testing.T) {
|
||||
require.NoError(t, planet.StopPeer(sn))
|
||||
}
|
||||
|
||||
projectID, encryptedPath := getProjectIDAndEncPathFirstObject(ctx, t, satelliteSys)
|
||||
_, err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(
|
||||
ctx, projectID, []byte(bucketName), encryptedPath,
|
||||
)
|
||||
projectID := uplnk.Projects[0].ID
|
||||
items, err := satelliteSys.Metainfo.Metabase.TestingAllCommittedObjects(ctx, projectID, bucketName)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 1)
|
||||
|
||||
_, err = satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(ctx, projectID, bucketName, items[0].ObjectKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check that storage nodes that were offline when deleting the pieces
|
||||
@ -247,225 +249,6 @@ func TestEndpoint_DeleteObjectPieces(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestEndpoint_DeleteObjectPieces_ObjectWithoutLastSegment(t *testing.T) {
|
||||
t.Run("continuous segments", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
||||
Reconfigure: testplanet.Reconfigure{
|
||||
// Reconfigure RS for ensuring that we don't have long-tail cancellations
|
||||
// and the upload doesn't leave garbage in the SNs
|
||||
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]
|
||||
)
|
||||
|
||||
const segmentSize = 10 * memory.KiB
|
||||
|
||||
var testCases = []struct {
|
||||
caseDescription string
|
||||
objData []byte
|
||||
}{
|
||||
{
|
||||
caseDescription: "one segment",
|
||||
objData: testrand.Bytes(2 * segmentSize),
|
||||
},
|
||||
{
|
||||
caseDescription: "several segments",
|
||||
objData: testrand.Bytes(4 * segmentSize),
|
||||
},
|
||||
{
|
||||
caseDescription: "several segments last inline",
|
||||
objData: testrand.Bytes((2 * segmentSize) + (3 * memory.KiB)),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.caseDescription, func(t *testing.T) {
|
||||
const bucketName = "a-bucket"
|
||||
// Use a different name for avoid collisions without having to run
|
||||
// testplanet for each test cases. We cannot upload to the same path
|
||||
// because it fails due to the zombie segments left by previous test
|
||||
// cases
|
||||
var objectName = tc.caseDescription
|
||||
|
||||
projectID, encryptedPath := uploadFirstObjectWithoutLastSegmentPointer(
|
||||
ctx, t, uplnk, satelliteSys, segmentSize, bucketName, objectName, tc.objData,
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
_, err := satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(
|
||||
ctx, projectID, []byte(bucketName), encryptedPath,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// confirm that the object was deleted
|
||||
listResponse, more, err := satelliteSys.Metainfo.Service.List(ctx, metabase.SegmentKey{}, "", true, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.False(t, more)
|
||||
require.Len(t, listResponse, 0)
|
||||
|
||||
planet.WaitForStorageNodeDeleters(ctx)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
if totalUsedSpaceAfterDelete >= totalUsedSpace {
|
||||
t.Fatalf(
|
||||
"used space after deletion. want before > after, got %d <= %d",
|
||||
totalUsedSpace, totalUsedSpaceAfterDelete,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("sparse segments", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
||||
Reconfigure: testplanet.Reconfigure{
|
||||
// Reconfigure RS for ensuring that we don't have long-tail cancellations
|
||||
// and the upload doesn't leave garbage in the SNs
|
||||
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]
|
||||
)
|
||||
|
||||
const segmentSize = 10 * memory.KiB
|
||||
|
||||
var testCases = []struct {
|
||||
caseDescription string
|
||||
objData []byte
|
||||
noSegmentsIndexes []int64 // Witout the last segment which is always included
|
||||
expectedSegmentGarbage int
|
||||
expectedNotFound bool
|
||||
}{
|
||||
{
|
||||
caseDescription: "some firsts",
|
||||
objData: testrand.Bytes(10 * segmentSize),
|
||||
noSegmentsIndexes: []int64{3, 5, 6, 9}, // Object with no pointers: L, 3, 5, 6, 9
|
||||
expectedSegmentGarbage: 3,
|
||||
expectedNotFound: false,
|
||||
},
|
||||
{
|
||||
caseDescription: "some firsts inline",
|
||||
objData: testrand.Bytes((9 * segmentSize) + (3 * memory.KiB)),
|
||||
noSegmentsIndexes: []int64{4, 5, 6}, // Object with no pointers: L, 4, 5, 6
|
||||
expectedSegmentGarbage: 2,
|
||||
expectedNotFound: false,
|
||||
},
|
||||
{
|
||||
caseDescription: "no first",
|
||||
objData: testrand.Bytes(10 * segmentSize),
|
||||
noSegmentsIndexes: []int64{0}, // Object with no pointer to : L, 0
|
||||
expectedSegmentGarbage: 9,
|
||||
expectedNotFound: true,
|
||||
},
|
||||
{
|
||||
caseDescription: "no firsts",
|
||||
objData: testrand.Bytes(8 * segmentSize),
|
||||
noSegmentsIndexes: []int64{0, 2, 5}, // Object with no pointer to : L, 0, 2, 5
|
||||
expectedSegmentGarbage: 5,
|
||||
expectedNotFound: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.caseDescription, func(t *testing.T) {
|
||||
const bucketName = "a-bucket"
|
||||
// Use a different name for avoid collisions without having to run
|
||||
// testplanet for each test cases. We cannot upload to the same path
|
||||
// because it fails due to the zombie segments left by previous test
|
||||
// cases
|
||||
var objectName = tc.caseDescription
|
||||
|
||||
// add the last segment to the indicated no segments to upload
|
||||
noSegmentsIndexes := []int64{-1}
|
||||
noSegmentsIndexes = append(noSegmentsIndexes, tc.noSegmentsIndexes...)
|
||||
projectID, encryptedPath := uploadFirstObjectWithoutSomeSegmentsPointers(
|
||||
ctx, t, uplnk, satelliteSys, segmentSize, bucketName, objectName, tc.objData, noSegmentsIndexes,
|
||||
)
|
||||
|
||||
// calculate the SNs used space
|
||||
var totalUsedSpace int64
|
||||
for _, sn := range planet.StorageNodes {
|
||||
usedSpace, _, err := sn.Storage2.Store.SpaceUsedForPieces(ctx)
|
||||
require.NoError(t, err)
|
||||
totalUsedSpace += usedSpace
|
||||
}
|
||||
|
||||
_, err := satelliteSys.Metainfo.Endpoint2.DeleteObjectPieces(
|
||||
ctx, projectID, []byte(bucketName), encryptedPath,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// check segment state after deletion
|
||||
listResponse, more, err := satelliteSys.Metainfo.Service.List(ctx, metabase.SegmentKey{}, "", true, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.False(t, more)
|
||||
// since the segments are sparsed, we are only able to delete
|
||||
// up to the last continuous segment found in the db.
|
||||
numOfGarbageSegments := 0
|
||||
for _, l := range listResponse {
|
||||
_, path := parsePath(ctx, t, l.Path)
|
||||
if string(encryptedPath) == string(path) {
|
||||
numOfGarbageSegments++
|
||||
}
|
||||
}
|
||||
require.Equal(t, tc.expectedSegmentGarbage, numOfGarbageSegments)
|
||||
|
||||
if tc.expectedNotFound {
|
||||
// no pieces will be deleted since we can't find those
|
||||
// segments in the database.
|
||||
return
|
||||
}
|
||||
|
||||
planet.WaitForStorageNodeDeleters(ctx)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
if totalUsedSpaceAfterDelete >= totalUsedSpace {
|
||||
t.Fatalf(
|
||||
"used space after deletion. want before > after, got %d <= %d",
|
||||
totalUsedSpace, totalUsedSpaceAfterDelete,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestDeleteBucket(t *testing.T) {
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
Reconfigure: testplanet.Reconfigure{
|
||||
@ -519,63 +302,3 @@ func TestDeleteBucket(t *testing.T) {
|
||||
require.Len(t, buckets.GetItems(), 0)
|
||||
})
|
||||
}
|
||||
|
||||
func getProjectIDAndEncPathFirstObject(
|
||||
ctx context.Context, t *testing.T, satellite *testplanet.Satellite,
|
||||
) (projectID uuid.UUID, encryptedPath []byte) {
|
||||
t.Helper()
|
||||
|
||||
keys, err := satellite.Metainfo.Database.List(ctx, storage.Key{}, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
return parsePath(ctx, t, keys[0].String())
|
||||
}
|
||||
|
||||
func parsePath(ctx context.Context, t *testing.T, path string) (projectID uuid.UUID, encryptedPath []byte) {
|
||||
pathParts := storj.SplitPath(path)
|
||||
require.Len(t, pathParts, 4)
|
||||
|
||||
projectID, err := uuid.FromString(pathParts[0])
|
||||
require.NoError(t, err)
|
||||
encryptedPath = []byte(pathParts[3])
|
||||
|
||||
return projectID, encryptedPath
|
||||
}
|
||||
|
||||
func uploadFirstObjectWithoutLastSegmentPointer(
|
||||
ctx context.Context, t *testing.T, uplnk *testplanet.Uplink,
|
||||
satelliteSys *testplanet.Satellite, segmentSize memory.Size,
|
||||
bucketName string, objectName string, objectData []byte,
|
||||
) (projectID uuid.UUID, encryptedPath []byte) {
|
||||
t.Helper()
|
||||
|
||||
return uploadFirstObjectWithoutSomeSegmentsPointers(
|
||||
ctx, t, uplnk, satelliteSys, segmentSize, bucketName, objectName, objectData, []int64{-1},
|
||||
)
|
||||
}
|
||||
|
||||
func uploadFirstObjectWithoutSomeSegmentsPointers(
|
||||
ctx context.Context, t *testing.T, uplnk *testplanet.Uplink,
|
||||
satelliteSys *testplanet.Satellite, segmentSize memory.Size,
|
||||
bucketName string, objectName string, objectData []byte, noSegmentsIndexes []int64,
|
||||
) (projectID uuid.UUID, encryptedPath []byte) {
|
||||
t.Helper()
|
||||
|
||||
if len(noSegmentsIndexes) < 1 {
|
||||
t.Fatal("noSegments list must have at least one segment")
|
||||
}
|
||||
|
||||
uploadCtx := testuplink.WithMaxSegmentSize(ctx, segmentSize)
|
||||
err := uplnk.Upload(uploadCtx, satelliteSys, bucketName, objectName, objectData)
|
||||
require.NoError(t, err)
|
||||
|
||||
projectID, encryptedPath = getProjectIDAndEncPathFirstObject(ctx, t, satelliteSys)
|
||||
for _, segIndx := range noSegmentsIndexes {
|
||||
location, err := metainfo.CreatePath(ctx, projectID, segIndx, []byte(bucketName), encryptedPath)
|
||||
require.NoError(t, err)
|
||||
err = satelliteSys.Metainfo.Service.UnsynchronizedDelete(ctx, location.Encode())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
return projectID, encryptedPath
|
||||
}
|
||||
|
@ -649,7 +649,7 @@ func (endpoint *Endpoint) BeginObject(ctx context.Context, req *pb.ObjectBeginRe
|
||||
canDelete := err == nil
|
||||
|
||||
if canDelete {
|
||||
_, err = endpoint.DeleteObjectPieces(ctx, keyInfo.ProjectID, req.Bucket, req.EncryptedPath)
|
||||
_, err = endpoint.DeleteObjectPieces(ctx, keyInfo.ProjectID, string(req.Bucket), metabase.ObjectKey(req.EncryptedPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -980,7 +980,7 @@ func (endpoint *Endpoint) BeginDeleteObject(ctx context.Context, req *pb.ObjectB
|
||||
})
|
||||
canList := err == nil
|
||||
|
||||
deletedObjects, err := endpoint.DeleteObjectPieces(ctx, keyInfo.ProjectID, req.Bucket, req.EncryptedPath)
|
||||
deletedObjects, err := endpoint.DeleteObjectPieces(ctx, keyInfo.ProjectID, string(req.Bucket), metabase.ObjectKey(req.EncryptedPath))
|
||||
if err != nil {
|
||||
if !canRead && !canList {
|
||||
// No error info is returned if neither Read, nor List permission is granted
|
||||
@ -1773,22 +1773,22 @@ func (endpoint *Endpoint) unmarshalSatSegmentID(ctx context.Context, segmentID s
|
||||
// NOTE: this method is exported for being able to individually test it without
|
||||
// having import cycles.
|
||||
func (endpoint *Endpoint) DeleteObjectPieces(
|
||||
ctx context.Context, projectID uuid.UUID, bucket, encryptedPath []byte,
|
||||
ctx context.Context, projectID uuid.UUID, bucket string, object metabase.ObjectKey,
|
||||
) (deletedObjects []*pb.Object, err error) {
|
||||
defer mon.Task()(&ctx, projectID.String(), bucket, encryptedPath)(&err)
|
||||
defer mon.Task()(&ctx, projectID.String(), bucket, object)(&err)
|
||||
|
||||
req := metabase.ObjectLocation{
|
||||
ProjectID: projectID,
|
||||
BucketName: string(bucket),
|
||||
ObjectKey: metabase.ObjectKey(encryptedPath),
|
||||
BucketName: bucket,
|
||||
ObjectKey: object,
|
||||
}
|
||||
|
||||
deletedObjects, err = endpoint.deleteObjectsPieces(ctx, req)
|
||||
if err != nil {
|
||||
endpoint.log.Error("failed to delete pointers",
|
||||
zap.Stringer("project_id", projectID),
|
||||
zap.ByteString("bucket_name", bucket),
|
||||
zap.Binary("encrypted_path", encryptedPath),
|
||||
zap.Stringer("project", projectID),
|
||||
zap.String("bucket", bucket),
|
||||
zap.Binary("object", []byte(object)),
|
||||
zap.Error(err),
|
||||
)
|
||||
return deletedObjects, err
|
||||
|
Loading…
Reference in New Issue
Block a user