Skip to content

Commit

Permalink
lens, meta: support both graveyard version
Browse files Browse the repository at this point in the history
It may or may not index tombstone's expiration in graveyard.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Sep 12, 2024
1 parent 90d5cfe commit 28fd1e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/neofs-lens/internal/meta/list-graveyard.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func listGraveyardFunc(cmd *cobra.Command, _ []string) {
gravePrm.SetHandler(
func(tsObj meta.TombstonedObject) error {
cmd.Printf(
"Object: %s\nTS: %s\n",
"Object: %s\nTS: %s (TS expiration: %d)\n",

Check warning on line 29 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#L29

Added line #L29 was not covered by tests
tsObj.Address().EncodeToString(),
tsObj.Tombstone().EncodeToString(),
tsObj.TombstoneExpiration(),

Check warning on line 32 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#L32

Added line #L32 was not covered by tests
)

return nil
Expand Down
28 changes: 22 additions & 6 deletions pkg/local_object_storage/metabase/graveyard.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func (db *DB) IterateOverGarbage(p GarbageIterationPrm) error {
// TombstonedObject represents descriptor of the
// object that has been covered with tombstone.
type TombstonedObject struct {
addr oid.Address
tomb oid.Address
addr oid.Address
tomb oid.Address
tombExpiration uint64
}

// Address returns tombstoned object address.
Expand All @@ -90,6 +91,13 @@ func (g TombstonedObject) Tombstone() oid.Address {
return g.tomb
}

// TombstoneExpiration returns tombstone's expiration. It can be zero if
// metabase version does not support expiration indexing or if TS does not
// expire.
func (g TombstonedObject) TombstoneExpiration() uint64 {
return g.tombExpiration

Check warning on line 98 in pkg/local_object_storage/metabase/graveyard.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/graveyard.go#L97-L98

Added lines #L97 - L98 were not covered by tests
}

// TombstonedHandler is a TombstonedObject handling function.
type TombstonedHandler func(object TombstonedObject) error

Expand Down Expand Up @@ -220,10 +228,18 @@ func garbageFromKV(k []byte) (res GarbageObject, err error) {
}

func graveFromKV(k, v []byte) (res TombstonedObject, err error) {
if err = decodeAddressFromKey(&res.addr, k); err != nil {
err = fmt.Errorf("decode tombstone target from key: %w", err)
} else if err = decodeAddressFromKey(&res.tomb, v[:addressKeySize]); err != nil {
err = fmt.Errorf("decode tombstone address from value: %w", err)
err = decodeAddressFromKey(&res.addr, k)
if err != nil {
return res, fmt.Errorf("decode tombstone target from key: %w", err)

Check warning on line 233 in pkg/local_object_storage/metabase/graveyard.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/graveyard.go#L233

Added line #L233 was not covered by tests
}

err = decodeAddressFromKey(&res.tomb, v[:addressKeySize])
if err != nil {
return res, fmt.Errorf("decode tombstone address from value: %w", err)

Check warning on line 238 in pkg/local_object_storage/metabase/graveyard.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/graveyard.go#L238

Added line #L238 was not covered by tests
}

if len(v) == addressKeySize+8 {
res.tombExpiration = binary.LittleEndian.Uint64(v[addressKeySize:])
}

return
Expand Down

0 comments on commit 28fd1e7

Please sign in to comment.