From d75d030a90b6547dde00bdcbdf068125a1eadccf Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 6 Jul 2022 14:59:35 +0300 Subject: [PATCH] [#1523] local_object_storage: Unify parameters for the `Delete` operation Signed-off-by: Evgenii Stratonikov --- .../blobstor/blobovniczatree/blobovnicza.go | 30 +++++++++---------- .../blobovniczatree/blobovnicza_test.go | 4 +-- .../blobstor/blobovniczatree/delete.go | 10 ------- .../blobstor/common/delete.go | 15 ++++++++++ pkg/local_object_storage/blobstor/delete.go | 20 ++++--------- pkg/local_object_storage/shard/delete.go | 14 ++++----- 6 files changed, 44 insertions(+), 49 deletions(-) delete mode 100644 pkg/local_object_storage/blobstor/blobovniczatree/delete.go create mode 100644 pkg/local_object_storage/blobstor/common/delete.go diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go index 4b53e6dbe..c29b78268 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go @@ -261,12 +261,12 @@ func (b *Blobovniczas) Get(prm common.GetPrm) (res common.GetRes, err error) { // // If blobocvnicza ID is specified, only this blobovnicza is processed. // Otherwise, all Blobovniczas are processed descending weight. -func (b *Blobovniczas) Delete(prm DeleteSmallPrm) (res DeleteSmallRes, err error) { +func (b *Blobovniczas) Delete(prm common.DeletePrm) (res common.DeleteRes, err error) { var bPrm blobovnicza.DeletePrm - bPrm.SetAddress(prm.addr) + bPrm.SetAddress(prm.Address) - if prm.blobovniczaID != nil { - blz, err := b.openBlobovnicza(prm.blobovniczaID.String()) + if prm.BlobovniczaID != nil { + blz, err := b.openBlobovnicza(prm.BlobovniczaID.String()) if err != nil { return res, err } @@ -277,7 +277,7 @@ func (b *Blobovniczas) Delete(prm DeleteSmallPrm) (res DeleteSmallRes, err error activeCache := make(map[string]struct{}) objectFound := false - err = b.iterateSortedLeaves(&prm.addr, func(p string) (bool, error) { + err = b.iterateSortedLeaves(&prm.Address, func(p string) (bool, error) { dirPath := filepath.Dir(p) // don't process active blobovnicza of the level twice @@ -307,7 +307,7 @@ func (b *Blobovniczas) Delete(prm DeleteSmallPrm) (res DeleteSmallRes, err error // not found in any blobovnicza var errNotFound apistatus.ObjectNotFound - return DeleteSmallRes{}, errNotFound + return common.DeleteRes{}, errNotFound } return @@ -370,7 +370,7 @@ func (b *Blobovniczas) GetRange(prm common.GetRangePrm) (res common.GetRangeRes, // tries to delete object from particular blobovnicza. // // returns no error if object was removed from some blobovnicza of the same level. -func (b *Blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath string, tryActive bool, dp DeleteSmallPrm) (DeleteSmallRes, error) { +func (b *Blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath string, tryActive bool, dp common.DeletePrm) (common.DeleteRes, error) { lvlPath := filepath.Dir(blzPath) // try to remove from blobovnicza if it is opened @@ -416,13 +416,13 @@ func (b *Blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath b.log.Debug("index is too big", zap.String("path", blzPath)) var errNotFound apistatus.ObjectNotFound - return DeleteSmallRes{}, errNotFound + return common.DeleteRes{}, errNotFound } // open blobovnicza (cached inside) blz, err := b.openBlobovnicza(blzPath) if err != nil { - return DeleteSmallRes{}, err + return common.DeleteRes{}, err } return b.deleteObject(blz, prm, dp) @@ -563,20 +563,20 @@ func (b *Blobovniczas) getRangeFromLevel(prm common.GetRangePrm, blzPath string, return b.getObjectRange(blz, prm) } -// removes object from blobovnicza and returns DeleteSmallRes. -func (b *Blobovniczas) deleteObject(blz *blobovnicza.Blobovnicza, prm blobovnicza.DeletePrm, dp DeleteSmallPrm) (DeleteSmallRes, error) { +// removes object from blobovnicza and returns common.DeleteRes. +func (b *Blobovniczas) deleteObject(blz *blobovnicza.Blobovnicza, prm blobovnicza.DeletePrm, dp common.DeletePrm) (common.DeleteRes, error) { _, err := blz.Delete(prm) if err != nil { - return DeleteSmallRes{}, err + return common.DeleteRes{}, err } storagelog.Write(b.log, - storagelog.AddressField(dp.addr), + storagelog.AddressField(dp.Address), storagelog.OpField("Blobovniczas DELETE"), - zap.Stringer("blobovnicza ID", dp.blobovniczaID), + zap.Stringer("blobovnicza ID", dp.BlobovniczaID), ) - return DeleteSmallRes{}, nil + return common.DeleteRes{}, nil } // reads object from blobovnicza and returns GetSmallRes. diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go index 0ba923798..8fd77b93f 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go @@ -116,11 +116,11 @@ func TestBlobovniczas(t *testing.T) { require.Equal(t, payload[off:off+ln], rngRes.Data) } - var dPrm DeleteSmallPrm + var dPrm common.DeletePrm var gPrm common.GetPrm for i := range addrList { - dPrm.SetAddress(addrList[i]) + dPrm.Address = addrList[i] _, err := b.Delete(dPrm) require.NoError(t, err) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/delete.go b/pkg/local_object_storage/blobstor/blobovniczatree/delete.go deleted file mode 100644 index b90ced454..000000000 --- a/pkg/local_object_storage/blobstor/blobovniczatree/delete.go +++ /dev/null @@ -1,10 +0,0 @@ -package blobovniczatree - -// DeleteSmallPrm groups the parameters of DeleteSmall operation. -type DeleteSmallPrm struct { - address - rwBlobovniczaID -} - -// DeleteSmallRes groups the resulting values of DeleteSmall operation. -type DeleteSmallRes struct{} diff --git a/pkg/local_object_storage/blobstor/common/delete.go b/pkg/local_object_storage/blobstor/common/delete.go new file mode 100644 index 000000000..0ed993450 --- /dev/null +++ b/pkg/local_object_storage/blobstor/common/delete.go @@ -0,0 +1,15 @@ +package common + +import ( + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" +) + +// DeletePrm groups the parameters of Delete operation. +type DeletePrm struct { + Address oid.Address + BlobovniczaID *blobovnicza.ID +} + +// DeleteRes groups the resulting values of Delete operation. +type DeleteRes struct{} diff --git a/pkg/local_object_storage/blobstor/delete.go b/pkg/local_object_storage/blobstor/delete.go index 1c1e53554..8edfd6e1a 100644 --- a/pkg/local_object_storage/blobstor/delete.go +++ b/pkg/local_object_storage/blobstor/delete.go @@ -3,28 +3,20 @@ package blobstor import ( "errors" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/blobovniczatree" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" ) -// DeleteBigPrm groups the parameters of DeleteBig operation. -type DeleteBigPrm struct { - address -} - -// DeleteBigRes groups the resulting values of DeleteBig operation. -type DeleteBigRes struct{} - // DeleteBig removes an object from shallow dir of BLOB storage. // // Returns any error encountered that did not allow // to completely remove the object. // // Returns an error of type apistatus.ObjectNotFound if there is no object to delete. -func (b *BlobStor) DeleteBig(prm DeleteBigPrm) (DeleteBigRes, error) { - err := b.fsTree.Delete(prm.addr) +func (b *BlobStor) DeleteBig(prm common.DeletePrm) (common.DeleteRes, error) { + err := b.fsTree.Delete(prm.Address) if errors.Is(err, fstree.ErrFileNotFound) { var errNotFound apistatus.ObjectNotFound @@ -32,10 +24,10 @@ func (b *BlobStor) DeleteBig(prm DeleteBigPrm) (DeleteBigRes, error) { } if err == nil { - storagelog.Write(b.log, storagelog.AddressField(prm.addr), storagelog.OpField("fstree DELETE")) + storagelog.Write(b.log, storagelog.AddressField(prm.Address), storagelog.OpField("fstree DELETE")) } - return DeleteBigRes{}, err + return common.DeleteRes{}, err } // DeleteSmall removes an object from blobovnicza of BLOB storage. @@ -47,6 +39,6 @@ func (b *BlobStor) DeleteBig(prm DeleteBigPrm) (DeleteBigRes, error) { // to completely remove the object. // // Returns an error of type apistatus.ObjectNotFound if there is no object to delete. -func (b *BlobStor) DeleteSmall(prm blobovniczatree.DeleteSmallPrm) (blobovniczatree.DeleteSmallRes, error) { +func (b *BlobStor) DeleteSmall(prm common.DeletePrm) (common.DeleteRes, error) { return b.blobovniczas.Delete(prm) } diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go index df815e77e..9beb5c653 100644 --- a/pkg/local_object_storage/shard/delete.go +++ b/pkg/local_object_storage/shard/delete.go @@ -2,8 +2,7 @@ package shard import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/blobovniczatree" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -36,8 +35,6 @@ func (s *Shard) Delete(prm DeletePrm) (DeleteRes, error) { } ln := len(prm.addr) - var delSmallPrm blobovniczatree.DeleteSmallPrm - var delBigPrm blobstor.DeleteBigPrm smalls := make(map[oid.Address]*blobovnicza.ID, ln) @@ -76,8 +73,9 @@ func (s *Shard) Delete(prm DeletePrm) (DeleteRes, error) { for i := range prm.addr { // delete small object if id, ok := smalls[prm.addr[i]]; ok { - delSmallPrm.SetAddress(prm.addr[i]) - delSmallPrm.SetBlobovniczaID(id) + var delSmallPrm common.DeletePrm + delSmallPrm.Address = prm.addr[i] + delSmallPrm.BlobovniczaID = id _, err = s.blobStor.DeleteSmall(delSmallPrm) if err != nil { @@ -90,8 +88,8 @@ func (s *Shard) Delete(prm DeletePrm) (DeleteRes, error) { } // delete big object - - delBigPrm.SetAddress(prm.addr[i]) + var delBigPrm common.DeletePrm + delBigPrm.Address = prm.addr[i] _, err = s.blobStor.DeleteBig(delBigPrm) if err != nil {