[#377] metabase: Add Inhume parameter to mark the object as garbage

Implement `InhumePrm.WithGCMark` method that marks the object as garbage in
graveyard. Update `InhumePrm.WithTombstoneAddress` doc indicating a conflict
with the new method. Update `Inhume` function doc about tombstone address
parameter.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-15 14:11:10 +03:00 committed by Alex Vanin
parent 7c3f828893
commit 30ac234c20

View file

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