2020-11-23 13:30:56 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
// InhumePrm encapsulates parameters for Inhume operation.
|
|
|
|
type InhumePrm struct {
|
|
|
|
target, tomb *objectSDK.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// InhumeRes encapsulates results of Inhume operation.
|
|
|
|
type InhumeRes struct{}
|
|
|
|
|
|
|
|
// WithAddress sets object address that should be inhumed.
|
|
|
|
func (p *InhumePrm) WithAddress(addr *objectSDK.Address) *InhumePrm {
|
|
|
|
if p != nil {
|
|
|
|
p.target = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithTombstoneAddress sets tombstone address as the reason for inhume operation.
|
2021-02-15 11:11:10 +00:00
|
|
|
//
|
|
|
|
// addr should not be nil.
|
|
|
|
// Should not be called along with WithGCMark.
|
2020-12-08 09:56:14 +00:00
|
|
|
func (p *InhumePrm) WithTombstoneAddress(addr *objectSDK.Address) *InhumePrm {
|
|
|
|
if p != nil {
|
|
|
|
p.tomb = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-02-15 11:11:10 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
// Inhume inhumes the object by specified address.
|
2021-02-15 11:11:10 +00:00
|
|
|
//
|
|
|
|
// tomb should not be nil.
|
2020-12-08 09:56:14 +00:00
|
|
|
func Inhume(db *DB, target, tomb *objectSDK.Address) error {
|
|
|
|
_, err := db.Inhume(new(InhumePrm).
|
|
|
|
WithAddress(target).
|
|
|
|
WithTombstoneAddress(tomb),
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-15 11:11:10 +00:00
|
|
|
const inhumeGCMarkValue = "GCMARK"
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
// Inhume marks objects as removed but not removes it from metabase.
|
2020-12-08 09:56:14 +00:00
|
|
|
func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) {
|
|
|
|
err = db.boltDB.Update(func(tx *bbolt.Tx) error {
|
2020-11-23 13:30:56 +00:00
|
|
|
graveyard, err := tx.CreateBucketIfNotExists(graveyardBucketName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-01-22 11:07:08 +00:00
|
|
|
obj, err := db.get(tx, prm.target, false, true)
|
|
|
|
|
|
|
|
// if object is stored and it is regular object then update bucket
|
|
|
|
// with container size estimations
|
|
|
|
if err == nil && obj.Type() == objectSDK.TypeRegular {
|
|
|
|
err := changeContainerSize(
|
|
|
|
tx,
|
|
|
|
obj.ContainerID(),
|
|
|
|
obj.PayloadSize(),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 11:11:10 +00:00
|
|
|
var val []byte
|
|
|
|
if prm.tomb != nil {
|
|
|
|
val = addressKey(prm.tomb)
|
|
|
|
} else {
|
|
|
|
val = []byte(inhumeGCMarkValue)
|
|
|
|
}
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
// consider checking if target is already in graveyard?
|
2021-02-15 11:11:10 +00:00
|
|
|
return graveyard.Put(addressKey(prm.target), val)
|
2020-11-23 13:30:56 +00:00
|
|
|
})
|
2020-12-08 09:56:14 +00:00
|
|
|
|
|
|
|
return
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|