Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metabase: drop almost all of Prm/Res structures #3001

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
}
defer db.Close()

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

resStorageID, err := db.StorageID(storageID)
id, err := db.StorageID(addr)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L40 was not covered by tests
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 {

Check warning on line 45 in cmd/neofs-lens/internal/meta/get.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/meta/get.go#L45

Added line #L45 was not covered by tests
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)

Check warning on line 53 in cmd/neofs-lens/internal/meta/get.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/meta/get.go#L53

Added line #L53 was not covered by tests
if errors.As(err, &siErr) {
link := siErr.SplitInfo().GetLink()
last := siErr.SplitInfo().GetLastPart()
Expand All @@ -79,7 +71,7 @@
return fmt.Errorf("could not get object: %w", err)
}

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

Check warning on line 74 in cmd/neofs-lens/internal/meta/get.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/meta/get.go#L74

Added line #L74 was not covered by tests

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 @@
}
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)

Check warning on line 33 in cmd/neofs-lens/internal/meta/list-garbage.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/meta/list-garbage.go#L30-L33

Added lines #L30 - L33 were not covered by tests
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 @@
}
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)

Check warning on line 39 in cmd/neofs-lens/internal/meta/list-graveyard.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/meta/list-graveyard.go#L30-L39

Added lines #L30 - L39 were not covered by tests
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 @@
"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 @@
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)

Check warning on line 42 in cmd/neofs-lens/internal/meta/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/meta/list.go#L42

Added line #L42 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why int?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that's the type ListPrm had for count.

if err != nil {
return fmt.Errorf("metabase's `ListWithCursor`: %w", err)
}

for _, addressWithType := range res.AddressList() {
for _, addressWithType := range addrs {

Check warning on line 47 in cmd/neofs-lens/internal/meta/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/meta/list.go#L47

Added line #L47 was not covered by tests
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 @@
"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 @@
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)

Check warning on line 58 in cmd/neofs-lens/internal/meta/put.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/meta/put.go#L58

Added line #L58 was not covered by tests
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 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
)

Check warning on line 164 in cmd/neofs-lens/internal/storage/sanity.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/sanity.go#L159-L164

Added lines #L159 - L164 were not covered by tests

for {
listRes, err := sh.m.ListWithCursor(mPrm)
addrs, cursor, err = sh.m.ListWithCursor(1024, cursor)

Check warning on line 167 in cmd/neofs-lens/internal/storage/sanity.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/sanity.go#L167

Added line #L167 was not covered by tests
if err != nil {
if errors.Is(err, meta.ErrEndOfListing) {
return objectsChecked, nil
Expand All @@ -170,7 +173,7 @@
return objectsChecked, fmt.Errorf("listing objects in metabase: %w", err)
}

for _, obj := range listRes.AddressList() {
for _, obj := range addrs {

Check warning on line 176 in cmd/neofs-lens/internal/storage/sanity.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/sanity.go#L176

Added line #L176 was not covered by tests
select {
case <-cmd.Context().Done():
return objectsChecked, cmd.Context().Err()
Expand All @@ -179,29 +182,21 @@

addr := obj.Address

var sIDPrm meta.StorageIDPrm
sIDPrm.SetAddress(addr)

sIDRes, err := sh.m.StorageID(sIDPrm)
sid, err := sh.m.StorageID(addr)

Check warning on line 185 in cmd/neofs-lens/internal/storage/sanity.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/sanity.go#L185

Added line #L185 was not covered by tests
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)

Check warning on line 190 in cmd/neofs-lens/internal/storage/sanity.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/sanity.go#L190

Added line #L190 was not covered by tests
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 {

Check warning on line 195 in cmd/neofs-lens/internal/storage/sanity.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/sanity.go#L195

Added line #L195 was not covered by tests
case "":
err = checkObject(header, sh.fsT)
err = checkObject(*header, sh.fsT)

Check warning on line 197 in cmd/neofs-lens/internal/storage/sanity.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/sanity.go#L197

Added line #L197 was not covered by tests
case peapod.Type:
err = checkObject(header, sh.p)
err = checkObject(*header, sh.p)

Check warning on line 199 in cmd/neofs-lens/internal/storage/sanity.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/sanity.go#L199

Added line #L199 was not covered by tests
default:
err = fmt.Errorf("uknown storage ID: %s", id)
}
Expand All @@ -217,8 +212,6 @@

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
Loading