Skip to content

Commit

Permalink
metabase: drop almost all of Prm/Res structures (#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Nov 7, 2024
2 parents bfe1c70 + 782005b commit 619d638
Show file tree
Hide file tree
Showing 43 changed files with 283 additions and 837 deletions.
16 changes: 4 additions & 12 deletions cmd/neofs-lens/internal/meta/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

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

storageID := meta.StorageIDPrm{}
storageID.SetAddress(addr)

resStorageID, err := db.StorageID(storageID)
id, err := db.StorageID(addr)
if err != nil {
return fmt.Errorf("could not check if the obj is small: %w", err)
}

if id := resStorageID.StorageID(); id != nil {
if id != nil {
cmd.Printf("Object storageID: %x (%q)\n\n", id, id)
} else {
cmd.Printf("Object does not contain storageID\n\n")
}

prm := meta.GetPrm{}
prm.SetAddress(addr)
prm.SetRaw(true)

siErr := new(object.SplitInfoError)

res, err := db.Get(prm)
obj, err := db.Get(addr, true)
if errors.As(err, &siErr) {
link := siErr.SplitInfo().GetLink()
last := siErr.SplitInfo().GetLastPart()
Expand All @@ -79,7 +71,7 @@ func getFunc(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("could not get object: %w", err)
}

common.PrintObjectHeader(cmd, *res.Header())
common.PrintObjectHeader(cmd, *obj)

return nil
}
12 changes: 4 additions & 8 deletions cmd/neofs-lens/internal/meta/list-garbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ func listGarbageFunc(cmd *cobra.Command, _ []string) error {
}
defer db.Close()

var garbPrm meta.GarbageIterationPrm
garbPrm.SetHandler(
func(garbageObject meta.GarbageObject) error {
cmd.Println(garbageObject.Address().EncodeToString())
return nil
})

err = db.IterateOverGarbage(garbPrm)
err = db.IterateOverGarbage(func(garbageObject meta.GarbageObject) error {
cmd.Println(garbageObject.Address().EncodeToString())
return nil
}, nil)
if err != nil {
return fmt.Errorf("could not iterate over garbage bucket: %w", err)
}
Expand Down
24 changes: 10 additions & 14 deletions cmd/neofs-lens/internal/meta/list-graveyard.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ func listGraveyardFunc(cmd *cobra.Command, _ []string) error {
}
defer db.Close()

var gravePrm meta.GraveyardIterationPrm
gravePrm.SetHandler(
func(tsObj meta.TombstonedObject) error {
cmd.Printf(
"Object: %s\nTS: %s (TS expiration: %d)\n",
tsObj.Address().EncodeToString(),
tsObj.Tombstone().EncodeToString(),
tsObj.TombstoneExpiration(),
)

return nil
})

err = db.IterateOverGraveyard(gravePrm)
err = db.IterateOverGraveyard(func(tsObj meta.TombstonedObject) error {
cmd.Printf(
"Object: %s\nTS: %s (TS expiration: %d)\n",
tsObj.Address().EncodeToString(),
tsObj.Tombstone().EncodeToString(),
tsObj.TombstoneExpiration(),
)

return nil
}, nil)
if err != nil {
return fmt.Errorf("could not iterate over graveyard bucket: %w", err)
}
Expand Down
8 changes: 2 additions & 6 deletions cmd/neofs-lens/internal/meta/list.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"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -40,15 +39,12 @@ func listFunc(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("%s flag must be positive", limitFlagName)
}

var prm meta.ListPrm
prm.SetCount(vLimit)

res, err := db.ListWithCursor(prm)
addrs, _, err := db.ListWithCursor(int(vLimit), nil)
if err != nil {
return fmt.Errorf("metabase's `ListWithCursor`: %w", err)
}

for _, addressWithType := range res.AddressList() {
for _, addressWithType := range addrs {
cmd.Printf("%s, Type: %s\n", addressWithType.Address, addressWithType.Type)
}

Expand Down
6 changes: 1 addition & 5 deletions cmd/neofs-lens/internal/meta/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
"github.com/nspcc-dev/neofs-sdk-go/object"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -56,10 +55,7 @@ func writeObject(cmd *cobra.Command, _ []string) error {
return errors.New("missing container ID in object")
}

var pPrm meta.PutPrm
pPrm.SetObject(obj)

_, err = db.Put(pPrm)
err = db.Put(obj, nil, nil)
if err != nil {
return fmt.Errorf("can't put object: %w", err)
}
Expand Down
33 changes: 13 additions & 20 deletions cmd/neofs-lens/internal/storage/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,15 @@ func sanityCheck(cmd *cobra.Command, _ []string) error {
}

func checkShard(cmd *cobra.Command, sh storageShard) (int, error) {
var objectsChecked int
var mPrm meta.ListPrm
mPrm.SetCount(1024)
var (
addrs []objectcore.AddressWithType
cursor *meta.Cursor
err error
objectsChecked int
)

for {
listRes, err := sh.m.ListWithCursor(mPrm)
addrs, cursor, err = sh.m.ListWithCursor(1024, cursor)
if err != nil {
if errors.Is(err, meta.ErrEndOfListing) {
return objectsChecked, nil
Expand All @@ -170,7 +173,7 @@ func checkShard(cmd *cobra.Command, sh storageShard) (int, error) {
return objectsChecked, fmt.Errorf("listing objects in metabase: %w", err)
}

for _, obj := range listRes.AddressList() {
for _, obj := range addrs {
select {
case <-cmd.Context().Done():
return objectsChecked, cmd.Context().Err()
Expand All @@ -179,29 +182,21 @@ func checkShard(cmd *cobra.Command, sh storageShard) (int, error) {

addr := obj.Address

var sIDPrm meta.StorageIDPrm
sIDPrm.SetAddress(addr)

sIDRes, err := sh.m.StorageID(sIDPrm)
sid, err := sh.m.StorageID(addr)
if err != nil {
return objectsChecked, fmt.Errorf("reading %s storage ID in metabase: %w", addr, err)
}

var mGet meta.GetPrm
mGet.SetAddress(addr)

getRes, err := sh.m.Get(mGet)
header, err := sh.m.Get(addr, false)
if err != nil {
return objectsChecked, fmt.Errorf("reading %s object in metabase: %w", addr, err)
}

header := *getRes.Header()

switch id := string(sIDRes.StorageID()); id {
switch id := string(sid); id {
case "":
err = checkObject(header, sh.fsT)
err = checkObject(*header, sh.fsT)
case peapod.Type:
err = checkObject(header, sh.p)
err = checkObject(*header, sh.p)
default:
err = fmt.Errorf("uknown storage ID: %s", id)
}
Expand All @@ -217,8 +212,6 @@ func checkShard(cmd *cobra.Command, sh storageShard) (int, error) {

objectsChecked++
}

mPrm.SetCursor(listRes.Cursor())
}
}

Expand Down
9 changes: 1 addition & 8 deletions pkg/local_object_storage/metabase/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,5 @@ func TestReset(t *testing.T) {
}

func metaExists(db *meta.DB, addr oid.Address) (bool, error) {
var existsPrm meta.ExistsPrm
existsPrm.SetAddress(addr)

res, err := db.Exists(existsPrm)
if err != nil {
return false, err
}
return res.Exists(), nil
return db.Exists(addr, false)
}
30 changes: 8 additions & 22 deletions pkg/local_object_storage/metabase/counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ func TestCounters(t *testing.T) {
oo = append(oo, generateObject(t))
}

var prm meta.PutPrm

for i := range objCount {
prm.SetObject(oo[i])

_, err = db.Put(prm)
err = db.Put(oo[i], nil, nil)
require.NoError(t, err)

c, err = db.ObjectCounters()
Expand All @@ -53,13 +49,10 @@ func TestCounters(t *testing.T) {
t.Run("delete", func(t *testing.T) {
oo := putObjs(t, db, objCount, false)

var prm meta.DeletePrm
for i := objCount - 1; i >= 0; i-- {
prm.SetAddresses(objectcore.AddressOf(oo[i]))

res, err := db.Delete(prm)
res, err := db.Delete([]oid.Address{objectcore.AddressOf(oo[i])})
require.NoError(t, err)
require.Equal(t, uint64(1), res.AvailableObjectsRemoved())
require.Equal(t, uint64(1), res.AvailableRemoved)

c, err = db.ObjectCounters()
require.NoError(t, err)
Expand Down Expand Up @@ -236,12 +229,9 @@ func TestCounters_Expired(t *testing.T) {
// phy counter but does not affect the logic counter (after
// that step they should be equal)

var deletePrm meta.DeletePrm
deletePrm.SetAddresses(oo[0])

deleteRes, err := db.Delete(deletePrm)
deleteRes, err := db.Delete(oo[:1])
require.NoError(t, err)
require.Zero(t, deleteRes.AvailableObjectsRemoved())
require.Zero(t, deleteRes.AvailableRemoved)

oo = oo[1:]

Expand All @@ -254,11 +244,9 @@ func TestCounters_Expired(t *testing.T) {
// service do) should decrease both counters despite the
// expiration fact

deletePrm.SetAddresses(oo[0])

deleteRes, err = db.Delete(deletePrm)
deleteRes, err = db.Delete(oo[:1])
require.NoError(t, err)
require.Equal(t, uint64(1), deleteRes.AvailableObjectsRemoved())
require.Equal(t, uint64(1), deleteRes.AvailableRemoved)

oo = oo[1:]

Expand All @@ -269,7 +257,6 @@ func TestCounters_Expired(t *testing.T) {
}

func putObjs(t *testing.T, db *meta.DB, count int, withParent bool) []*object.Object {
var prm meta.PutPrm
var err error
parent := generateObject(t)

Expand All @@ -282,8 +269,7 @@ func putObjs(t *testing.T, db *meta.DB, count int, withParent bool) []*object.Ob

oo = append(oo, o)

prm.SetObject(o)
_, err = db.Put(prm)
err = db.Put(o, nil, nil)
require.NoError(t, err)

c, err := db.ObjectCounters()
Expand Down
Loading

0 comments on commit 619d638

Please sign in to comment.