From a4de38b0b9db8721ed86fd843ace639f1b322242 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 26 Feb 2024 09:18:51 +0400 Subject: [PATCH] object: Stop supporting `__NEOFS__NETMAP*` X-headers They are not supported since https://github.com/nspcc-dev/neofs-api/issues/279. Now storage nodes process the current epoch only. Refs #1194. Signed-off-by: Leonard Lyubich --- CHANGELOG.md | 4 + pkg/services/object/get/container.go | 35 ++--- pkg/services/object/get/exec.go | 38 +----- pkg/services/object/get/get_test.go | 127 ------------------ pkg/services/object/get/util.go | 3 - pkg/services/object/internal/client/client.go | 7 - pkg/services/object/search/container.go | 35 ++--- pkg/services/object/search/exec.go | 38 +----- pkg/services/object/search/search_test.go | 120 +---------------- pkg/services/object/search/util.go | 1 - pkg/services/object/util/prm.go | 44 +----- 11 files changed, 33 insertions(+), 419 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41002eb960e..a3aa0b202b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Changelog for NeoFS Node ### Removed - Object notifications incl. NATS (#2750) +- Supporting of `__NEOFS__NETMAP*` X-headers (#2751) ### Updated @@ -22,6 +23,9 @@ supported. All NATS servers running for this purpose only are no longer needed. If your app depends on notifications transmitted to NATS, do not update and create an issue please. +Stop attaching `__NEOFS__NETMAP*` X-headers to NeoFS API requests. If your app +is somehow tied to them, do not update and create an issue please. + ## [0.40.1] - 2024-02-22 ### Fixed diff --git a/pkg/services/object/get/container.go b/pkg/services/object/get/container.go index f63ea1b1e4f..91328579130 100644 --- a/pkg/services/object/get/container.go +++ b/pkg/services/object/get/container.go @@ -13,41 +13,26 @@ func (exec *execCtx) executeOnContainer() { return } - lookupDepth := exec.netmapLookupDepth() - - exec.log.Debug("trying to execute in container...", - zap.Uint64("netmap lookup depth", lookupDepth), - ) + exec.log.Debug("trying to execute in container...") // initialize epoch number - ok := exec.initEpoch() - if !ok { + epoch, err := exec.svc.currentEpochReceiver.currentEpoch() + if err != nil { + exec.status = statusUndefined + exec.err = err + exec.log.Debug("could not get current epoch number", zap.Error(err)) return } - for { - if exec.processCurrentEpoch() { - break - } - - // check the maximum depth has been reached - if lookupDepth == 0 { - break - } - - lookupDepth-- - - // go to the previous epoch - exec.curProcEpoch-- - } + exec.processEpoch(epoch) } -func (exec *execCtx) processCurrentEpoch() bool { +func (exec *execCtx) processEpoch(epoch uint64) bool { exec.log.Debug("process epoch", - zap.Uint64("number", exec.curProcEpoch), + zap.Uint64("number", epoch), ) - traverser, ok := exec.generateTraverser(exec.address()) + traverser, ok := exec.generateTraverser(exec.address(), epoch) if !ok { return true } diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index fc3963e9bbf..cb55a5fbbd3 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -39,8 +39,6 @@ type execCtx struct { curOff uint64 head bool - - curProcEpoch uint64 } type execOption func(*execCtx) @@ -153,42 +151,10 @@ func (exec *execCtx) headOnly() bool { return exec.head } -func (exec *execCtx) netmapEpoch() uint64 { - return exec.prm.common.NetmapEpoch() -} - -func (exec *execCtx) netmapLookupDepth() uint64 { - return exec.prm.common.NetmapLookupDepth() -} - -func (exec *execCtx) initEpoch() bool { - exec.curProcEpoch = exec.netmapEpoch() - if exec.curProcEpoch > 0 { - return true - } - - e, err := exec.svc.currentEpochReceiver.currentEpoch() - - switch { - default: - exec.status = statusUndefined - exec.err = err - - exec.log.Debug("could not get current epoch number", - zap.String("error", err.Error()), - ) - - return false - case err == nil: - exec.curProcEpoch = e - return true - } -} - -func (exec *execCtx) generateTraverser(addr oid.Address) (*placement.Traverser, bool) { +func (exec *execCtx) generateTraverser(addr oid.Address, epoch uint64) (*placement.Traverser, bool) { obj := addr.Object() - t, err := exec.svc.traverserGenerator.GenerateTraverser(addr.Container(), &obj, exec.curProcEpoch) + t, err := exec.svc.traverserGenerator.GenerateTraverser(addr.Container(), &obj, epoch) switch { default: diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index 5c456bba78d..baf5b61ab2a 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -1117,130 +1117,3 @@ func TestGetRemoteSmall(t *testing.T) { }) }) } - -func TestGetFromPastEpoch(t *testing.T) { - ctx := context.Background() - - var cnr container.Container - cnr.SetPlacementPolicy(netmaptest.PlacementPolicy()) - - var idCnr cid.ID - cnr.CalculateID(&idCnr) - - addr := oidtest.Address() - addr.SetContainer(idCnr) - - payloadSz := uint64(10) - payload := make([]byte, payloadSz) - _, _ = rand.Read(payload) - - obj := generateObject(addr, nil, payload) - - ns, as := testNodeMatrix(t, []int{2, 2}) - - c11 := newTestClient() - c11.addResult(addr, nil, errors.New("any error")) - - c12 := newTestClient() - c12.addResult(addr, nil, errors.New("any error")) - - c21 := newTestClient() - c21.addResult(addr, nil, errors.New("any error")) - - c22 := newTestClient() - c22.addResult(addr, obj, nil) - - svc := &Service{cfg: new(cfg)} - svc.log = test.NewLogger(false) - svc.localStorage = newTestStorage() - svc.assembly = true - - const curEpoch = 13 - - svc.traverserGenerator = &testTraverserGenerator{ - c: cnr, - b: map[uint64]placement.Builder{ - curEpoch: &testPlacementBuilder{ - vectors: map[string][][]netmap.NodeInfo{ - addr.EncodeToString(): ns[:1], - }, - }, - curEpoch - 1: &testPlacementBuilder{ - vectors: map[string][][]netmap.NodeInfo{ - addr.EncodeToString(): ns[1:], - }, - }, - }, - } - - svc.clientCache = &testClientCache{ - clients: map[string]*testClient{ - as[0][0]: c11, - as[0][1]: c12, - as[1][0]: c21, - as[1][1]: c22, - }, - } - - svc.currentEpochReceiver = testEpochReceiver(curEpoch) - - w := NewSimpleObjectWriter() - - commonPrm := new(util.CommonPrm) - - p := Prm{} - p.SetObjectWriter(w) - p.SetCommonParameters(commonPrm) - p.WithAddress(addr) - - err := svc.Get(ctx, p) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) - - commonPrm.SetNetmapLookupDepth(1) - - err = svc.Get(ctx, p) - require.NoError(t, err) - require.Equal(t, obj, w.Object()) - - rp := RangePrm{} - rp.SetChunkWriter(w) - commonPrm.SetNetmapLookupDepth(0) - rp.SetCommonParameters(commonPrm) - rp.WithAddress(addr) - - off, ln := payloadSz/3, payloadSz/3 - - r := objectSDK.NewRange() - r.SetOffset(off) - r.SetLength(ln) - - rp.SetRange(r) - - err = svc.GetRange(ctx, rp) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) - - w = NewSimpleObjectWriter() - rp.SetChunkWriter(w) - commonPrm.SetNetmapLookupDepth(1) - - err = svc.GetRange(ctx, rp) - require.NoError(t, err) - require.Equal(t, payload[off:off+ln], w.Object().Payload()) - - hp := HeadPrm{} - hp.SetHeaderWriter(w) - commonPrm.SetNetmapLookupDepth(0) - hp.SetCommonParameters(commonPrm) - hp.WithAddress(addr) - - err = svc.Head(ctx, hp) - require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) - - w = NewSimpleObjectWriter() - hp.SetHeaderWriter(w) - commonPrm.SetNetmapLookupDepth(1) - - err = svc.Head(ctx, hp) - require.NoError(t, err) - require.Equal(t, obj.CutPayload(), w.Object()) -} diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index e9fb77d2f02..2a741ac0a77 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -102,7 +102,6 @@ func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*obj prm.SetContext(exec.context()) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) - prm.SetNetmapEpoch(exec.curProcEpoch) prm.SetAddress(exec.address()) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken()) @@ -134,7 +133,6 @@ func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*obj prm.SetContext(exec.context()) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) - prm.SetNetmapEpoch(exec.curProcEpoch) prm.SetAddress(exec.address()) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken()) @@ -181,7 +179,6 @@ func (c *clientWrapper) get(exec *execCtx, key *ecdsa.PrivateKey) (*object.Objec prm.SetContext(exec.context()) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) - prm.SetNetmapEpoch(exec.curProcEpoch) prm.SetAddress(exec.address()) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken()) diff --git a/pkg/services/object/internal/client/client.go b/pkg/services/object/internal/client/client.go index da266e68272..e6973ea0a30 100644 --- a/pkg/services/object/internal/client/client.go +++ b/pkg/services/object/internal/client/client.go @@ -86,13 +86,6 @@ type readPrmCommon struct { commonPrm } -// SetNetmapEpoch sets the epoch number to be used to locate the object. -// -// By default current epoch on the server will be used. -func (x *readPrmCommon) SetNetmapEpoch(_ uint64) { - // FIXME: (neofs-node#1194) not supported by client -} - // GetObjectPrm groups parameters of GetObject operation. type GetObjectPrm struct { readPrmCommon diff --git a/pkg/services/object/search/container.go b/pkg/services/object/search/container.go index 5c238cde9c8..54bbb902201 100644 --- a/pkg/services/object/search/container.go +++ b/pkg/services/object/search/container.go @@ -15,44 +15,29 @@ func (exec *execCtx) executeOnContainer() { return } - lookupDepth := exec.netmapLookupDepth() - - exec.log.Debug("trying to execute in container...", - zap.Uint64("netmap lookup depth", lookupDepth), - ) + exec.log.Debug("trying to execute in container...") // initialize epoch number - ok := exec.initEpoch() - if !ok { + epoch, err := exec.svc.currentEpochReceiver.currentEpoch() + if err != nil { + exec.status = statusUndefined + exec.err = err + exec.log.Debug("could not get current epoch number", zap.Error(err)) return } - for { - if exec.processCurrentEpoch() { - break - } - - // check the maximum depth has been reached - if lookupDepth == 0 { - break - } - - lookupDepth-- - - // go to the previous epoch - exec.curProcEpoch-- - } + exec.processEpoch(epoch) exec.status = statusOK exec.err = nil } -func (exec *execCtx) processCurrentEpoch() bool { +func (exec *execCtx) processEpoch(epoch uint64) bool { exec.log.Debug("process epoch", - zap.Uint64("number", exec.curProcEpoch), + zap.Uint64("number", epoch), ) - traverser, ok := exec.generateTraverser(exec.containerID()) + traverser, ok := exec.generateTraverser(exec.containerID(), epoch) if !ok { return true } diff --git a/pkg/services/object/search/exec.go b/pkg/services/object/search/exec.go index 46dcb3bb0a7..3bc5d7e635a 100644 --- a/pkg/services/object/search/exec.go +++ b/pkg/services/object/search/exec.go @@ -25,8 +25,6 @@ type execCtx struct { statusError log *zap.Logger - - curProcEpoch uint64 } const ( @@ -66,40 +64,8 @@ func (exec *execCtx) searchFilters() object.SearchFilters { return exec.prm.filters } -func (exec *execCtx) netmapEpoch() uint64 { - return exec.prm.common.NetmapEpoch() -} - -func (exec *execCtx) netmapLookupDepth() uint64 { - return exec.prm.common.NetmapLookupDepth() -} - -func (exec *execCtx) initEpoch() bool { - exec.curProcEpoch = exec.netmapEpoch() - if exec.curProcEpoch > 0 { - return true - } - - e, err := exec.svc.currentEpochReceiver.currentEpoch() - - switch { - default: - exec.status = statusUndefined - exec.err = err - - exec.log.Debug("could not get current epoch number", - zap.String("error", err.Error()), - ) - - return false - case err == nil: - exec.curProcEpoch = e - return true - } -} - -func (exec *execCtx) generateTraverser(cnr cid.ID) (*placement.Traverser, bool) { - t, err := exec.svc.traverserGenerator.generateTraverser(cnr, exec.curProcEpoch) +func (exec *execCtx) generateTraverser(cnr cid.ID, epoch uint64) (*placement.Traverser, bool) { + t, err := exec.svc.traverserGenerator.generateTraverser(cnr, epoch) switch { default: diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 4d6333d46aa..8222ee1695f 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -34,7 +34,7 @@ type testStorage struct { type testTraverserGenerator struct { c container.Container - b map[uint64]placement.Builder + b placement.Builder } type testPlacementBuilder struct { @@ -66,10 +66,10 @@ func newTestStorage() *testStorage { } } -func (g *testTraverserGenerator) generateTraverser(_ cid.ID, epoch uint64) (*placement.Traverser, error) { +func (g *testTraverserGenerator) generateTraverser(_ cid.ID, _ uint64) (*placement.Traverser, error) { return placement.NewTraverser( placement.ForContainer(g.c), - placement.UseBuilder(g.b[epoch]), + placement.UseBuilder(g.b), placement.WithoutSuccessTracking(), ) } @@ -256,9 +256,7 @@ func TestGetRemoteSmall(t *testing.T) { svc.traverserGenerator = &testTraverserGenerator{ c: cnr, - b: map[uint64]placement.Builder{ - curEpoch: b, - }, + b: b, } svc.clientConstructor = c svc.currentEpochReceiver = testEpochReceiver(curEpoch) @@ -315,113 +313,3 @@ func TestGetRemoteSmall(t *testing.T) { } }) } - -func TestGetFromPastEpoch(t *testing.T) { - ctx := context.Background() - - placementDim := []int{2, 2} - - rs := make([]netmap.ReplicaDescriptor, len(placementDim)) - - for i := range placementDim { - rs[i].SetNumberOfObjects(uint32(placementDim[i])) - } - - var pp netmap.PlacementPolicy - pp.AddReplicas(rs...) - - var cnr container.Container - cnr.SetPlacementPolicy(pp) - - var idCnr cid.ID - cnr.CalculateID(&idCnr) - - var addr oid.Address - addr.SetContainer(idCnr) - - ns, as := testNodeMatrix(t, placementDim) - - c11 := newTestStorage() - ids11 := generateIDs(10) - c11.addResult(idCnr, ids11, nil) - - c12 := newTestStorage() - ids12 := generateIDs(10) - c12.addResult(idCnr, ids12, nil) - - c21 := newTestStorage() - ids21 := generateIDs(10) - c21.addResult(idCnr, ids21, nil) - - c22 := newTestStorage() - ids22 := generateIDs(10) - c22.addResult(idCnr, ids22, nil) - - svc := &Service{cfg: new(cfg)} - svc.log = test.NewLogger(false) - svc.localStorage = newTestStorage() - - const curEpoch = 13 - - svc.traverserGenerator = &testTraverserGenerator{ - c: cnr, - b: map[uint64]placement.Builder{ - curEpoch: &testPlacementBuilder{ - vectors: map[string][][]netmap.NodeInfo{ - addr.EncodeToString(): ns[:1], - }, - }, - curEpoch - 1: &testPlacementBuilder{ - vectors: map[string][][]netmap.NodeInfo{ - addr.EncodeToString(): ns[1:], - }, - }, - }, - } - - svc.clientConstructor = &testClientCache{ - clients: map[string]*testStorage{ - as[0][0]: c11, - as[0][1]: c12, - as[1][0]: c21, - as[1][1]: c22, - }, - } - - svc.currentEpochReceiver = testEpochReceiver(curEpoch) - - w := new(simpleIDWriter) - - p := Prm{} - p.WithContainerID(idCnr) - p.SetWriter(w) - - commonPrm := new(util.CommonPrm) - p.SetCommonParameters(commonPrm) - - assertContains := func(idsList ...[]oid.ID) { - var sz int - - for _, ids := range idsList { - sz += len(ids) - - for _, id := range ids { - require.Contains(t, w.ids, id) - } - } - - require.Len(t, w.ids, sz) - } - - err := svc.Search(ctx, p) - require.NoError(t, err) - assertContains(ids11, ids12) - - commonPrm.SetNetmapLookupDepth(1) - w = new(simpleIDWriter) - p.SetWriter(w) - - err = svc.Search(ctx, p) - require.NoError(t, err) - assertContains(ids11, ids12, ids21, ids22) -} diff --git a/pkg/services/object/search/util.go b/pkg/services/object/search/util.go index fd73cef9657..e625f2c2cc2 100644 --- a/pkg/services/object/search/util.go +++ b/pkg/services/object/search/util.go @@ -105,7 +105,6 @@ func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oi prm.SetBearerToken(exec.prm.common.BearerToken()) prm.SetTTL(exec.prm.common.TTL()) prm.SetXHeaders(exec.prm.common.XHeaders()) - prm.SetNetmapEpoch(exec.curProcEpoch) prm.SetContainerID(exec.containerID()) prm.SetFilters(exec.searchFilters()) diff --git a/pkg/services/object/util/prm.go b/pkg/services/object/util/prm.go index d608ad68ea7..ed6ee192a61 100644 --- a/pkg/services/object/util/prm.go +++ b/pkg/services/object/util/prm.go @@ -2,7 +2,6 @@ package util import ( "fmt" - "strconv" "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-sdk-go/bearer" @@ -15,8 +14,6 @@ const maxLocalTTL = 1 type CommonPrm struct { local bool - netmapEpoch, netmapLookupDepth uint64 - token *sessionsdk.Object bearer *bearer.Token @@ -76,28 +73,6 @@ func (p *CommonPrm) BearerToken() *bearer.Token { return nil } -func (p *CommonPrm) NetmapEpoch() uint64 { - if p != nil { - return p.netmapEpoch - } - - return 0 -} - -func (p *CommonPrm) NetmapLookupDepth() uint64 { - if p != nil { - return p.netmapLookupDepth - } - - return 0 -} - -func (p *CommonPrm) SetNetmapLookupDepth(v uint64) { - if p != nil { - p.netmapLookupDepth = v - } -} - // ForgetTokens forgets all the tokens read from the request's // meta information before. func (p *CommonPrm) ForgetTokens() { @@ -148,24 +123,7 @@ func CommonPrmFromV2(req interface { } for i := range xHdrs { - switch key := xHdrs[i].GetKey(); key { - case session.XHeaderNetmapEpoch: - var err error - - prm.netmapEpoch, err = strconv.ParseUint(xHdrs[i].GetValue(), 10, 64) - if err != nil { - return nil, err - } - case session.XHeaderNetmapLookupDepth: - var err error - - prm.netmapLookupDepth, err = strconv.ParseUint(xHdrs[i].GetValue(), 10, 64) - if err != nil { - return nil, err - } - default: - prm.xhdrs = append(prm.xhdrs, key, xHdrs[i].GetValue()) - } + prm.xhdrs = append(prm.xhdrs, xHdrs[i].GetKey(), xHdrs[i].GetValue()) } return prm, nil