diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index e65fe2c22..a43d6ead2 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -23,6 +23,9 @@ func (p *InhumePrm) WithAddress(addr *objectSDK.Address) *InhumePrm { } // WithTombstoneAddress sets tombstone address as the reason for inhume operation. +// +// addr should not be nil. +// Should not be called along with WithGCMark. func (p *InhumePrm) WithTombstoneAddress(addr *objectSDK.Address) *InhumePrm { if p != nil { p.tomb = addr @@ -31,7 +34,20 @@ func (p *InhumePrm) WithTombstoneAddress(addr *objectSDK.Address) *InhumePrm { return p } +// WithGCMark marks the object to be physically removed. +// +// Should not be called along with WithTombstoneAddress. +func (p *InhumePrm) WithGCMark() *InhumePrm { + if p != nil { + p.tomb = nil + } + + return p +} + // Inhume inhumes the object by specified address. +// +// tomb should not be nil. func Inhume(db *DB, target, tomb *objectSDK.Address) error { _, err := db.Inhume(new(InhumePrm). WithAddress(target). @@ -41,6 +57,8 @@ func Inhume(db *DB, target, tomb *objectSDK.Address) error { return err } +const inhumeGCMarkValue = "GCMARK" + // Inhume marks objects as removed but not removes it from metabase. func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) { err = db.boltDB.Update(func(tx *bbolt.Tx) error { @@ -65,8 +83,15 @@ func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) { } } + var val []byte + if prm.tomb != nil { + val = addressKey(prm.tomb) + } else { + val = []byte(inhumeGCMarkValue) + } + // consider checking if target is already in graveyard? - return graveyard.Put(addressKey(prm.target), addressKey(prm.tomb)) + return graveyard.Put(addressKey(prm.target), val) }) return