From c105562479b88fe0e15433858f3e5d8017dfdda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Niewrza=C5=82?= Date: Wed, 6 Apr 2022 10:30:20 +0200 Subject: [PATCH] satellite/gc: test GC with object copies We implemented server-side copy feature and we would like to confirm that it is not affecting GC. Fixes https://github.com/storj/storj/issues/4696 Change-Id: Id391f0badf5fce51f9910f0df732d477b07fa7ac --- satellite/gc/gc_test.go | 94 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/satellite/gc/gc_test.go b/satellite/gc/gc_test.go index 474802c3b..378de5f7d 100644 --- a/satellite/gc/gc_test.go +++ b/satellite/gc/gc_test.go @@ -132,6 +132,100 @@ func TestGarbageCollection(t *testing.T) { }) } +// TestGarbageCollectionWithCopies checkes that server-side copy elements are not +// affecting GC and nothing unexpected was deleted from storage nodes. +func TestGarbageCollectionWithCopies(t *testing.T) { + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1, + Reconfigure: testplanet.Reconfigure{ + Satellite: testplanet.ReconfigureRS(2, 3, 4, 4), + }, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + satellite := planet.Satellites[0] + gcService := satellite.GarbageCollection.Service + gcService.Loop.Pause() + + project, err := planet.Uplinks[0].OpenProject(ctx, satellite) + require.NoError(t, err) + defer ctx.Check(project.Close) + + allSpaceUsedForPieces := func() (all int64) { + for _, node := range planet.StorageNodes { + total, _, _, err := node.Storage2.Store.SpaceUsedTotalAndBySatellite(ctx) + require.NoError(t, err) + all += total + } + return all + } + + expectedRemoteData := testrand.Bytes(8 * memory.KiB) + expectedInlineData := testrand.Bytes(1 * memory.KiB) + + require.NoError(t, planet.Uplinks[0].Upload(ctx, satellite, "testbucket", "remote", expectedRemoteData)) + require.NoError(t, planet.Uplinks[0].Upload(ctx, satellite, "testbucket", "inline", expectedInlineData)) + + require.NoError(t, planet.WaitForStorageNodeEndpoints(ctx)) + + // how much used space we should have after deleting objects + expectedUsedAfterDeleteAndGC := allSpaceUsedForPieces() + require.NotZero(t, expectedUsedAfterDeleteAndGC) + + require.NoError(t, planet.Uplinks[0].Upload(ctx, satellite, "testbucket", "remote-no-copy", expectedRemoteData)) + + _, err = project.CopyObject(ctx, "testbucket", "remote", "testbucket", "remote-copy", nil) + require.NoError(t, err) + _, err = project.CopyObject(ctx, "testbucket", "inline", "testbucket", "inline-copy", nil) + require.NoError(t, err) + + require.NoError(t, planet.WaitForStorageNodeEndpoints(ctx)) + + totalUsedByNodes := allSpaceUsedForPieces() + + // run GC + gcService.Loop.TriggerWait() + for _, node := range planet.StorageNodes { + node.Storage2.RetainService.TestWaitUntilEmpty() + } + + // we should see all space used by all objects + afterTotalUsedByNodes := allSpaceUsedForPieces() + require.Equal(t, totalUsedByNodes, afterTotalUsedByNodes) + + // delete ancestors, no change in used space + _, err = project.DeleteObject(ctx, "testbucket", "remote") + require.NoError(t, err) + + _, err = project.DeleteObject(ctx, "testbucket", "inline") + require.NoError(t, err) + + // delete object without copy, used space should be decreased + _, err = project.DeleteObject(ctx, "testbucket", "remote-no-copy") + require.NoError(t, err) + + planet.WaitForStorageNodeDeleters(ctx) + + // run GC + gcService.Loop.TriggerWait() + for _, node := range planet.StorageNodes { + node.Storage2.RetainService.TestWaitUntilEmpty() + } + + // verify that we deleted only pieces for "remote-no-copy" object + afterTotalUsedByNodes = allSpaceUsedForPieces() + require.Equal(t, expectedUsedAfterDeleteAndGC, afterTotalUsedByNodes) + + // run GC + gcService.Loop.TriggerWait() + for _, node := range planet.StorageNodes { + node.Storage2.RetainService.TestWaitUntilEmpty() + } + + // verify that nothing more was deleted from storage nodes after GC + afterTotalUsedByNodes = allSpaceUsedForPieces() + require.Equal(t, expectedUsedAfterDeleteAndGC, afterTotalUsedByNodes) + }) +} + func getSegment(ctx *testcontext.Context, t *testing.T, satellite *testplanet.Satellite, upl *testplanet.Uplink, bucket, path string) (_ metabase.ObjectLocation, _ metabase.Segment) { access := upl.Access[satellite.ID()]