forked from TrueCloudLab/frostfs-node
[#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:
parent
7c3f828893
commit
30ac234c20
1 changed files with 26 additions and 1 deletions
|
@ -23,6 +23,9 @@ func (p *InhumePrm) WithAddress(addr *objectSDK.Address) *InhumePrm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithTombstoneAddress sets tombstone address as the reason for inhume operation.
|
// 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 {
|
func (p *InhumePrm) WithTombstoneAddress(addr *objectSDK.Address) *InhumePrm {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
p.tomb = addr
|
p.tomb = addr
|
||||||
|
@ -31,7 +34,20 @@ func (p *InhumePrm) WithTombstoneAddress(addr *objectSDK.Address) *InhumePrm {
|
||||||
return p
|
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.
|
// Inhume inhumes the object by specified address.
|
||||||
|
//
|
||||||
|
// tomb should not be nil.
|
||||||
func Inhume(db *DB, target, tomb *objectSDK.Address) error {
|
func Inhume(db *DB, target, tomb *objectSDK.Address) error {
|
||||||
_, err := db.Inhume(new(InhumePrm).
|
_, err := db.Inhume(new(InhumePrm).
|
||||||
WithAddress(target).
|
WithAddress(target).
|
||||||
|
@ -41,6 +57,8 @@ func Inhume(db *DB, target, tomb *objectSDK.Address) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const inhumeGCMarkValue = "GCMARK"
|
||||||
|
|
||||||
// Inhume marks objects as removed but not removes it from metabase.
|
// Inhume marks objects as removed but not removes it from metabase.
|
||||||
func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) {
|
func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) {
|
||||||
err = db.boltDB.Update(func(tx *bbolt.Tx) 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?
|
// 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
|
return
|
||||||
|
|
Loading…
Reference in a new issue