From 0a525292e4745956e166e1c1ca23ead72499bb27 Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Wed, 15 Feb 2023 11:12:39 +0100 Subject: [PATCH] satellite/metainfo: fix duplicates while listing pending objects While working on fixing listing for committed objects we didn't fix the same case for pending objects. For case were we have many pending objects under different locations we need to set cursor version to highest value to avoid duplicates. For case where we have many pending objects under the same location we will need to make a separate fix. https://github.com/storj/storj/issues/5570 Change-Id: Id5c8eb728868e8e1177fdbcf65a493142be4eaf0 --- satellite/metainfo/endpoint_object.go | 16 +++++----- satellite/metainfo/endpoint_object_test.go | 37 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/satellite/metainfo/endpoint_object.go b/satellite/metainfo/endpoint_object.go index 1a1d94fd1..27317d048 100644 --- a/satellite/metainfo/endpoint_object.go +++ b/satellite/metainfo/endpoint_object.go @@ -805,14 +805,14 @@ func (endpoint *Endpoint) ListObjects(ctx context.Context, req *pb.ObjectListReq if len(cursor.Key) != 0 { cursor.Key = prefix + cursor.Key - if status == metabase.Committed { - // TODO this is a workaround to avoid duplicates while listing objects by libuplink. - // because version is not part of cursor yet and we can have object with version higher - // than 1 we cannot use hardcoded version 1 as default. - // This workaround should be in place for a longer time even if metainfo protocol will be - // fix as we still want to avoid this problem for older libuplink versions. - cursor.Version = metabase.MaxVersion - } + // TODO this is a workaround to avoid duplicates while listing objects by libuplink. + // because version is not part of cursor yet and we can have object with version higher + // than 1 we cannot use hardcoded version 1 as default. + // This workaround should be in place for a longer time even if metainfo protocol will be + // fix as we still want to avoid this problem for older libuplink versions. + // + // it should be set in case of pending and committed objects + cursor.Version = metabase.MaxVersion } includeCustomMetadata := true diff --git a/satellite/metainfo/endpoint_object_test.go b/satellite/metainfo/endpoint_object_test.go index 349b88e65..5a9305d1f 100644 --- a/satellite/metainfo/endpoint_object_test.go +++ b/satellite/metainfo/endpoint_object_test.go @@ -2406,3 +2406,40 @@ func TestListObjectDuplicates(t *testing.T) { } }) } + +func TestListUploads(t *testing.T) { + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, + StorageNodeCount: 0, + UplinkCount: 1, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + // basic ListUploads tests, more tests are on storj/uplink side + u := planet.Uplinks[0] + s := planet.Satellites[0] + + project, err := u.OpenProject(ctx, s) + require.NoError(t, err) + defer ctx.Check(project.Close) + + require.NoError(t, u.CreateBucket(ctx, s, "testbucket")) + + // TODO number of objects created can be limited when uplink will + // have an option to control listing limit value for ListUploads + for i := 0; i < 1001; i++ { + _, err := project.BeginUpload(ctx, "testbucket", "object"+strconv.Itoa(i), nil) + require.NoError(t, err) + } + + list := project.ListUploads(ctx, "testbucket", nil) + items := 0 + for list.Next() { + items++ + } + require.NoError(t, list.Err()) + // TODO result should be 1001 but we have bug in libuplink + // were it's not possible to get second page of results for + // pending objets. + // test will fail when we will fix uplink and we will need to adjust this test + require.Equal(t, 1000, items) + }) +}