Skip to content

Commit

Permalink
engine: drop package-level wrappers over StorageEngine
Browse files Browse the repository at this point in the history
The only reason they existed is because StorageEngine interfaces were unusable.
Now they're not and these wrappers are trivial and do nothing in most of the
cases.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Nov 11, 2024
1 parent 8d91f82 commit e482dbf
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 84 deletions.
3 changes: 1 addition & 2 deletions cmd/neofs-lens/internal/storage/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -38,7 +37,7 @@ func getFunc(cmd *cobra.Command, _ []string) error {
}
defer storage.Close()

obj, err := engine.Get(storage, addr)
obj, err := storage.Get(addr)

Check warning on line 40 in cmd/neofs-lens/internal/storage/get.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/get.go#L40

Added line #L40 was not covered by tests
if err != nil {
return fmt.Errorf("could not fetch object: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-node/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ type localStorageLoad struct {
}

func (d *localStorageLoad) Iterate(f loadcontroller.UsedSpaceFilter, h loadcontroller.UsedSpaceHandler) error {
idList, err := engine.ListContainers(d.engine)
idList, err := d.engine.ListContainers()

Check warning on line 434 in cmd/neofs-node/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/container.go#L434

Added line #L434 was not covered by tests
if err != nil {
return fmt.Errorf("list containers on engine failure: %w", err)
}

for i := range idList {
sz, err := engine.ContainerSize(d.engine, idList[i])
sz, err := d.engine.ContainerSize(idList[i])

Check warning on line 440 in cmd/neofs-node/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/container.go#L440

Added line #L440 was not covered by tests
if err != nil {
d.log.Debug("failed to calculate container size in storage engine",
zap.Stringer("cid", idList[i]),
Expand Down
10 changes: 0 additions & 10 deletions pkg/local_object_storage/engine/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ func (e *StorageEngine) ContainerSize(cnr cid.ID) (uint64, error) {
return size, err

Check warning on line 32 in pkg/local_object_storage/engine/container.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/engine/container.go#L32

Added line #L32 was not covered by tests
}

// ContainerSize calls ContainerSize method on engine to calculate sum of estimation container sizes among all shards.
func ContainerSize(e *StorageEngine, id cid.ID) (uint64, error) {
return e.ContainerSize(id)
}

func (e *StorageEngine) containerSize(cnr cid.ID) (uint64, error) {
var size uint64

Check warning on line 36 in pkg/local_object_storage/engine/container.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/engine/container.go#L35-L36

Added lines #L35 - L36 were not covered by tests

Expand Down Expand Up @@ -79,11 +74,6 @@ func (e *StorageEngine) ListContainers() ([]cid.ID, error) {
return res, err

Check warning on line 74 in pkg/local_object_storage/engine/container.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/engine/container.go#L74

Added line #L74 was not covered by tests
}

// ListContainers calls ListContainers method on engine to get a unique container IDs presented in the engine objects.
func ListContainers(e *StorageEngine) ([]cid.ID, error) {
return e.ListContainers()
}

func (e *StorageEngine) listContainers() ([]cid.ID, error) {

Check warning on line 77 in pkg/local_object_storage/engine/container.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/engine/container.go#L77

Added line #L77 was not covered by tests
uniqueIDs := make(map[cid.ID]struct{})

Expand Down
8 changes: 4 additions & 4 deletions pkg/local_object_storage/engine/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,28 @@ func TestExecBlocks(t *testing.T) {

addr := object.AddressOf(obj)

require.NoError(t, Put(e, obj))
require.NoError(t, e.Put(obj, nil, 0))

// block executions
errBlock := errors.New("block exec err")

require.NoError(t, e.BlockExecution(errBlock))

// try to exec some op
_, err := Head(e, addr)
_, err := e.Head(addr, false)
require.ErrorIs(t, err, errBlock)

// resume executions
require.NoError(t, e.ResumeExecution())

_, err = Head(e, addr) // can be any data-related op
_, err = e.Head(addr, false) // can be any data-related op
require.NoError(t, err)

// close
require.NoError(t, e.Close())

// try exec after close
_, err = Head(e, addr)
_, err = e.Head(addr, false)
require.Error(t, err)

// try to resume
Expand Down
4 changes: 2 additions & 2 deletions pkg/local_object_storage/engine/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func TestDeleteBigObject(t *testing.T) {
defer e.Close()

for i := range children {
require.NoError(t, Put(e, children[i]))
require.NoError(t, e.Put(children[i], nil, 0))
}
require.NoError(t, Put(e, link))
require.NoError(t, e.Put(link, nil, 0))

var splitErr *objectSDK.SplitInfoError

Expand Down
2 changes: 1 addition & 1 deletion pkg/local_object_storage/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func benchmarkExists(b *testing.B, shardNum int) {
addr := oidtest.Address()
for range 100 {
obj := generateObjectWithCID(cidtest.ID())
err := Put(e, obj)
err := e.Put(obj, nil, 0)
if err != nil {
b.Fatal(err)
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/local_object_storage/engine/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ func TestChildrenExpiration(t *testing.T) {
link.SetChildren(child1ID, child2ID, child3ID)
link.SetSplitID(splitID)

require.NoError(t, Put(e, child1))
require.NoError(t, Put(e, child2))
require.NoError(t, Put(e, child3))
require.NoError(t, Put(e, link))
require.NoError(t, e.Put(child1, nil, 0))
require.NoError(t, e.Put(child2, nil, 0))
require.NoError(t, e.Put(child3, nil, 0))
require.NoError(t, e.Put(link, nil, 0))

e.HandleNewEpoch(currEpoch + 1)

Expand Down Expand Up @@ -144,10 +144,10 @@ func TestChildrenExpiration(t *testing.T) {
linkObj.CalculateAndSetPayloadChecksum()
require.NoError(t, linkObj.CalculateAndSetID())

require.NoError(t, Put(e, child1))
require.NoError(t, Put(e, child2))
require.NoError(t, Put(e, child3))
require.NoError(t, Put(e, &linkObj))
require.NoError(t, e.Put(child1, nil, 0))
require.NoError(t, e.Put(child2, nil, 0))
require.NoError(t, e.Put(child3, nil, 0))
require.NoError(t, e.Put(&linkObj, nil, 0))

e.HandleNewEpoch(currEpoch + 1)

Expand All @@ -163,7 +163,7 @@ func checkObjectsAsyncRemoval(t *testing.T, e *StorageEngine, cnr cid.ID, objs .
for _, obj := range objs {
addr.SetObject(obj)

_, err := Get(e, addr)
_, err := e.Get(addr)
if !errors.As(err, new(statusSDK.ObjectNotFound)) {
return false
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/local_object_storage/engine/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ func (e *StorageEngine) get(addr oid.Address, shardFunc func(s *shard.Shard, ign
return nil
}

// Get reads object from local storage by provided address.
func Get(storage *StorageEngine, addr oid.Address) (*objectSDK.Object, error) {
return storage.Get(addr)
}

// GetBytes reads object from the StorageEngine by address into memory buffer in
// a canonical NeoFS binary format. Returns [apistatus.ObjectNotFound] if object
// is missing.
Expand Down
2 changes: 1 addition & 1 deletion pkg/local_object_storage/engine/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestStorageEngine_GetBytes(t *testing.T) {

objBin := obj.Marshal()

err := Put(e, obj)
err := e.Put(obj, nil, 0)
require.NoError(t, err)

b, err := e.GetBytes(addr)
Expand Down
11 changes: 0 additions & 11 deletions pkg/local_object_storage/engine/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,3 @@ func (e *StorageEngine) head(addr oid.Address, raw bool) (*objectSDK.Object, err

return head, nil
}

// Head reads object header from local storage by provided address.
func Head(storage *StorageEngine, addr oid.Address) (*objectSDK.Object, error) {
return storage.Head(addr, false)
}

// HeadRaw reads object header from local storage by provided address and raw
// flag.
func HeadRaw(storage *StorageEngine, addr oid.Address, raw bool) (*objectSDK.Object, error) {
return storage.Head(addr, true)
}
14 changes: 7 additions & 7 deletions pkg/local_object_storage/engine/inhume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func TestStorageEngine_Inhume(t *testing.T) {
e := testNewEngineWithShardNum(t, 1)
defer e.Close()

err := Put(e, parent)
err := e.Put(parent, nil, 0)
require.NoError(t, err)

err = e.Inhume(tombstoneID, 0, object.AddressOf(parent))
require.NoError(t, err)

addrs, err := Select(e, cnr, fs)
addrs, err := e.Select(cnr, fs)
require.NoError(t, err)
require.Empty(t, addrs)
})
Expand All @@ -75,13 +75,13 @@ func TestStorageEngine_Inhume(t *testing.T) {
require.NoError(t, err)

t.Run("empty search should fail", func(t *testing.T) {
addrs, err := Select(e, cnr, objectSDK.SearchFilters{})
addrs, err := e.Select(cnr, objectSDK.SearchFilters{})
require.NoError(t, err)
require.Empty(t, addrs)
})

t.Run("root search should fail", func(t *testing.T) {
addrs, err := Select(e, cnr, fs)
addrs, err := e.Select(cnr, fs)
require.NoError(t, err)
require.Empty(t, addrs)
})
Expand All @@ -91,18 +91,18 @@ func TestStorageEngine_Inhume(t *testing.T) {
addr.SetContainer(cnr)
addr.SetObject(idChild)

_, err = Get(e, addr)
_, err = e.Get(addr)
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))

linkID := link.GetID()
addr.SetObject(linkID)

_, err = Get(e, addr)
_, err = e.Get(addr)
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
})

t.Run("parent get should claim deletion", func(t *testing.T) {
_, err = Get(e, object.AddressOf(parent))
_, err = e.Get(object.AddressOf(parent))
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
})
})
Expand Down
14 changes: 7 additions & 7 deletions pkg/local_object_storage/engine/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ func TestLockUserScenario(t *testing.T) {
id := obj.GetID()
objAddr.SetObject(id)

err = Put(e, obj)
err = e.Put(obj, nil, 0)
require.NoError(t, err)

// 2.
var locker object.Lock
locker.WriteMembers([]oid.ID{id})
lockerObj.WriteLock(locker)

err = Put(e, lockerObj)
err = e.Put(lockerObj, nil, 0)
require.NoError(t, err)

err = e.Lock(cnr, lockerID, []oid.ID{id})
Expand All @@ -104,7 +104,7 @@ func TestLockUserScenario(t *testing.T) {
tombObj.SetID(tombForLockID)
tombObj.SetAttributes(a)

err = Put(e, tombObj)
err = e.Put(tombObj, nil, 0)
require.NoError(t, err)

err = e.Inhume(tombForLockAddr, 0, lockerAddr)
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestLockExpiration(t *testing.T) {
// 1.
obj := generateObjectWithCID(cnr)

err = Put(e, obj)
err = e.Put(obj, nil, 0)
require.NoError(t, err)

// 2.
Expand All @@ -161,7 +161,7 @@ func TestLockExpiration(t *testing.T) {
lock.SetType(object.TypeLock)
lock.SetAttributes(a)

err = Put(e, lock)
err = e.Put(lock, nil, 0)
require.NoError(t, err)

id := obj.GetID()
Expand Down Expand Up @@ -215,14 +215,14 @@ func TestLockForceRemoval(t *testing.T) {
// 1.
obj := generateObjectWithCID(cnr)

err = Put(e, obj)
err = e.Put(obj, nil, 0)
require.NoError(t, err)

// 2.
lock := generateObjectWithCID(cnr)
lock.SetType(object.TypeLock)

err = Put(e, lock)
err = e.Put(lock, nil, 0)
require.NoError(t, err)

id := obj.GetID()
Expand Down
5 changes: 0 additions & 5 deletions pkg/local_object_storage/engine/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,3 @@ func (e *StorageEngine) putToShard(sh hashedShard, ind int, pool util.WorkerPool

return putSuccess, alreadyExists
}

// Put writes provided object to local storage.
func Put(storage *StorageEngine, obj *objectSDK.Object) error {
return storage.Put(obj, nil, 0)
}
5 changes: 0 additions & 5 deletions pkg/local_object_storage/engine/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,3 @@ func (e *StorageEngine) getRange(addr oid.Address, offset uint64, length uint64)

return out, nil
}

// GetRange reads object payload range from local storage by provided address.
func GetRange(storage *StorageEngine, addr oid.Address, rng *objectSDK.Range) ([]byte, error) {
return storage.GetRange(addr, rng.GetOffset(), rng.GetLength())
}
11 changes: 0 additions & 11 deletions pkg/local_object_storage/engine/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,3 @@ func (e *StorageEngine) list(limit uint64) ([]oid.Address, error) {

return addrList, nil

Check warning on line 119 in pkg/local_object_storage/engine/select.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/engine/select.go#L119

Added line #L119 was not covered by tests
}

// Select selects objects from local storage using provided filters.
func Select(storage *StorageEngine, cnr cid.ID, fs object.SearchFilters) ([]oid.Address, error) {
return storage.Select(cnr, fs)
}

// List returns `limit` available physically storage object addresses in
// engine. If limit is zero, then returns all available object addresses.
func List(storage *StorageEngine, limit uint64) ([]oid.Address, error) {
return storage.List(limit)
}
2 changes: 1 addition & 1 deletion pkg/local_object_storage/engine/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func benchmarkTreeVsSearch(b *testing.B, objCount int) {
for i := range objCount {
obj := generateObjectWithCID(cid)
addAttribute(obj, pilorama.AttributeFilename, strconv.Itoa(i))
err := Put(e, obj)
err := e.Put(obj, nil, 0)
if err != nil {
b.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/object/acl/eacl/v2/localstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ func (s *localStorage) Head(addr oid.Address) (*objectSDK.Object, error) {
return nil, io.ErrUnexpectedEOF
}

return engine.Head(s.ls, addr)
return s.ls.Head(addr, false)

Check warning on line 20 in pkg/services/object/acl/eacl/v2/localstore.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object/acl/eacl/v2/localstore.go#L20

Added line #L20 was not covered by tests
}

0 comments on commit e482dbf

Please sign in to comment.