From 4e71dd302abfb662c122065af6b521fa4f303f11 Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Mon, 19 Sep 2022 15:26:50 +0200 Subject: [PATCH] satellite/{metainfo,metabase}: prepare feature flag MultipleVersions We will introduce new logic for creating new objects (BeginObject). Instead of using single version internally (1) we will be selecting first available version during object creation. Because we need to be sure that everything is wired up correctly we need a feature flag to be able to control if new feature is enabled. Change-Id: If0f8496397130811f43bf9db9fdcc2b30cd2e4ca --- private/testplanet/satellite.go | 1 + satellite/metabase/commit.go | 4 ++++ satellite/metabase/commit_test.go | 13 +++++++++++++ satellite/metabase/db.go | 1 + satellite/metabase/metabasetest/run.go | 1 + satellite/metainfo/config.go | 1 + satellite/metainfo/endpoint_object.go | 4 ++++ satellite/metainfo/endpoint_object_test.go | 17 +++++++++++++++++ scripts/testdata/satellite-config.yaml.lock | 3 +++ 9 files changed, 45 insertions(+) diff --git a/private/testplanet/satellite.go b/private/testplanet/satellite.go index de41ad24b..505811637 100644 --- a/private/testplanet/satellite.go +++ b/private/testplanet/satellite.go @@ -466,6 +466,7 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int MinPartSize: config.Metainfo.MinPartSize, MaxNumberOfParts: config.Metainfo.MaxNumberOfParts, ServerSideCopy: config.Metainfo.ServerSideCopy, + MultipleVersions: config.Metainfo.MultipleVersions, }) if err != nil { return nil, err diff --git a/satellite/metabase/commit.go b/satellite/metabase/commit.go index 75f15a9e2..cb10d4506 100644 --- a/satellite/metabase/commit.go +++ b/satellite/metabase/commit.go @@ -509,6 +509,10 @@ func (c *CommitObject) Verify() error { func (db *DB) CommitObject(ctx context.Context, opts CommitObject) (object Object, err error) { defer mon.Task()(&ctx)(&err) + if db.config.MultipleVersions { + return Object{}, Error.New("Unimplemented") + } + if err := opts.Verify(); err != nil { return Object{}, err } diff --git a/satellite/metabase/commit_test.go b/satellite/metabase/commit_test.go index c830354b3..c4714963f 100644 --- a/satellite/metabase/commit_test.go +++ b/satellite/metabase/commit_test.go @@ -8,6 +8,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "storj.io/common/memory" "storj.io/common/storj" "storj.io/common/testcontext" @@ -3204,3 +3206,14 @@ func TestCommitObjectWithIncorrectAmountOfParts(t *testing.T) { }) }) } + +func TestMultipleVersionsFlag(t *testing.T) { + // TODO test will be removed when functionality will be implemented + metabasetest.RunWithConfig(t, metabase.Config{ + ApplicationName: "satellite-test", + MultipleVersions: true, + }, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) { + _, err := db.CommitObject(ctx, metabase.CommitObject{}) + require.EqualError(t, err, "metabase: Unimplemented") + }) +} diff --git a/satellite/metabase/db.go b/satellite/metabase/db.go index 794d4dfa8..38308e428 100644 --- a/satellite/metabase/db.go +++ b/satellite/metabase/db.go @@ -36,6 +36,7 @@ type Config struct { // TODO remove this flag when server-side copy implementation will be finished ServerSideCopy bool ServerSideCopyDisabled bool + MultipleVersions bool } // DB implements a database for storing objects and segments. diff --git a/satellite/metabase/metabasetest/run.go b/satellite/metabase/metabasetest/run.go index 63abb2a0b..b43c589fa 100644 --- a/satellite/metabase/metabasetest/run.go +++ b/satellite/metabase/metabasetest/run.go @@ -67,6 +67,7 @@ func Run(t *testing.T, fn func(ctx *testcontext.Context, t *testing.T, db *metab MaxNumberOfParts: config.MaxNumberOfParts, ServerSideCopy: config.ServerSideCopy, ServerSideCopyDisabled: config.ServerSideCopyDisabled, + MultipleVersions: config.MultipleVersions, }, fn) } diff --git a/satellite/metainfo/config.go b/satellite/metainfo/config.go index ec62583df..048c62f75 100644 --- a/satellite/metainfo/config.go +++ b/satellite/metainfo/config.go @@ -138,4 +138,5 @@ type Config struct { // TODO remove this flag when server-side copy implementation will be finished ServerSideCopy bool `help:"enable code for server-side copy, deprecated. please leave this to true." default:"true"` ServerSideCopyDisabled bool `help:"disable already enabled server-side copy. this is because once server side copy is enabled, delete code should stay changed, even if you want to disable server side copy" default:"false"` + MultipleVersions bool `help:"feature flag to enable using multple objects versions in the system internally" default:"false"` } diff --git a/satellite/metainfo/endpoint_object.go b/satellite/metainfo/endpoint_object.go index b57cabdf9..25e0e7d3f 100644 --- a/satellite/metainfo/endpoint_object.go +++ b/satellite/metainfo/endpoint_object.go @@ -29,6 +29,10 @@ import ( func (endpoint *Endpoint) BeginObject(ctx context.Context, req *pb.ObjectBeginRequest) (resp *pb.ObjectBeginResponse, err error) { defer mon.Task()(&ctx)(&err) + if endpoint.config.MultipleVersions { + return nil, rpcstatus.Error(rpcstatus.Unimplemented, "Unimplemented") + } + endpoint.versionCollector.collect(req.Header.UserAgent, mon.Func().ShortName()) now := time.Now() diff --git a/satellite/metainfo/endpoint_object_test.go b/satellite/metainfo/endpoint_object_test.go index 34808fee5..406ebee40 100644 --- a/satellite/metainfo/endpoint_object_test.go +++ b/satellite/metainfo/endpoint_object_test.go @@ -1826,3 +1826,20 @@ func TestEndpoint_UpdateObjectMetadata(t *testing.T) { require.Equal(t, validKey, objects[0].EncryptedMetadataEncryptedKey) }) } + +func TestMultipleVersionsFlag(t *testing.T) { + // TODO test will be removed when functionality will be implemented + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, + Reconfigure: testplanet.Reconfigure{ + Satellite: func(log *zap.Logger, index int, config *satellite.Config) { + config.Metainfo.MultipleVersions = true + }, + }, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + planet.Satellites[0].Config.Metainfo.MultipleVersions = true + _, err := planet.Satellites[0].Metainfo.Endpoint.BeginObject(ctx, &pb.ObjectBeginRequest{}) + require.Error(t, err) + require.True(t, errs2.IsRPC(err, rpcstatus.Unimplemented)) + }) +} diff --git a/scripts/testdata/satellite-config.yaml.lock b/scripts/testdata/satellite-config.yaml.lock index 6b30b4d48..945261d79 100755 --- a/scripts/testdata/satellite-config.yaml.lock +++ b/scripts/testdata/satellite-config.yaml.lock @@ -550,6 +550,9 @@ identity.key-path: /root/.local/share/storj/identity/satellite/identity.key # minimum remote segment size # metainfo.min-remote-segment-size: 1.2 KiB +# feature flag to enable using multple objects versions in the system internally +# metainfo.multiple-versions: false + # toggle flag if overlay is enabled # metainfo.overlay: true