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 1df7c82 commit 312a33a
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",
tsObj.Address().EncodeToString(),
tsObj.Tombstone().EncodeToString(),
tsObj.TombstoneExpiration(),
)

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
}

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

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

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

return
Expand Down

0 comments on commit 312a33a

Please sign in to comment.