2020-11-23 13:30:56 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
2021-02-19 09:49:23 +00:00
|
|
|
"bytes"
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2023-06-06 09:27:19 +00:00
|
|
|
"time"
|
2021-02-19 09:49:23 +00:00
|
|
|
|
2024-01-15 05:52:52 +00:00
|
|
|
storagelog "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/log"
|
2023-06-15 10:19:36 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-11-23 13:30:56 +00:00
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
// InhumePrm encapsulates parameters for Inhume operation.
|
|
|
|
type InhumePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
tomb *oid.Address
|
2021-02-15 11:50:21 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
target []oid.Address
|
2022-05-26 17:38:32 +00:00
|
|
|
|
|
|
|
lockObjectHandling bool
|
2022-05-31 20:11:42 +00:00
|
|
|
|
|
|
|
forceRemoval bool
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2023-02-02 20:28:42 +00:00
|
|
|
// DeletionInfo contains details on deleted object.
|
|
|
|
type DeletionInfo struct {
|
2023-12-05 14:00:16 +00:00
|
|
|
Size uint64
|
|
|
|
CID cid.ID
|
|
|
|
IsUser bool
|
2023-02-02 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
// InhumeRes encapsulates results of Inhume operation.
|
2022-05-26 17:38:32 +00:00
|
|
|
type InhumeRes struct {
|
2023-12-25 07:15:26 +00:00
|
|
|
deletedLockObj []oid.Address
|
|
|
|
logicInhumed uint64
|
|
|
|
userInhumed uint64
|
|
|
|
inhumedByCnrID map[cid.ID]ObjectCounters
|
|
|
|
deletionDetails []DeletionInfo
|
2022-09-09 11:33:38 +00:00
|
|
|
}
|
|
|
|
|
2023-12-25 07:15:26 +00:00
|
|
|
// LogicInhumed return number of logic object
|
2022-09-09 11:33:38 +00:00
|
|
|
// that have been inhumed.
|
2023-12-25 07:15:26 +00:00
|
|
|
func (i InhumeRes) LogicInhumed() uint64 {
|
|
|
|
return i.logicInhumed
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
|
|
|
|
2023-12-05 14:00:16 +00:00
|
|
|
func (i InhumeRes) UserInhumed() uint64 {
|
|
|
|
return i.userInhumed
|
|
|
|
}
|
|
|
|
|
2023-11-02 10:50:52 +00:00
|
|
|
// InhumedByCnrID return number of object
|
|
|
|
// that have been inhumed by container ID.
|
|
|
|
func (i InhumeRes) InhumedByCnrID() map[cid.ID]ObjectCounters {
|
|
|
|
return i.inhumedByCnrID
|
2022-05-26 17:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeletedLockObjects returns deleted object of LOCK
|
|
|
|
// type. Returns always nil if WithoutLockObjectHandling
|
|
|
|
// was provided to the InhumePrm.
|
|
|
|
func (i InhumeRes) DeletedLockObjects() []oid.Address {
|
|
|
|
return i.deletedLockObj
|
|
|
|
}
|
2020-12-08 09:56:14 +00:00
|
|
|
|
2023-02-02 20:28:42 +00:00
|
|
|
// GetDeletionInfoLength returns amount of stored elements
|
|
|
|
// in deleted sizes array.
|
|
|
|
func (i InhumeRes) GetDeletionInfoLength() int {
|
|
|
|
return len(i.deletionDetails)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDeletionInfoByIndex returns both deleted object sizes and
|
|
|
|
// associated container ID by index.
|
|
|
|
func (i InhumeRes) GetDeletionInfoByIndex(target int) DeletionInfo {
|
|
|
|
return i.deletionDetails[target]
|
|
|
|
}
|
|
|
|
|
|
|
|
// StoreDeletionInfo stores size of deleted object and associated container ID
|
|
|
|
// in corresponding arrays.
|
2023-12-05 14:00:16 +00:00
|
|
|
func (i *InhumeRes) storeDeletionInfo(containerID cid.ID, deletedSize uint64, isUser bool) {
|
2023-02-02 20:28:42 +00:00
|
|
|
i.deletionDetails = append(i.deletionDetails, DeletionInfo{
|
2023-12-05 14:00:16 +00:00
|
|
|
Size: deletedSize,
|
|
|
|
CID: containerID,
|
|
|
|
IsUser: isUser,
|
2023-02-02 20:28:42 +00:00
|
|
|
})
|
2023-12-25 07:15:26 +00:00
|
|
|
i.logicInhumed++
|
2023-12-05 14:00:16 +00:00
|
|
|
if isUser {
|
|
|
|
i.userInhumed++
|
|
|
|
}
|
|
|
|
|
2023-11-02 10:50:52 +00:00
|
|
|
if v, ok := i.inhumedByCnrID[containerID]; ok {
|
2023-12-04 14:35:11 +00:00
|
|
|
v.Logic++
|
2023-12-05 14:00:16 +00:00
|
|
|
if isUser {
|
|
|
|
v.User++
|
|
|
|
}
|
2023-11-02 10:50:52 +00:00
|
|
|
i.inhumedByCnrID[containerID] = v
|
|
|
|
} else {
|
2023-12-05 14:00:16 +00:00
|
|
|
v = ObjectCounters{
|
2023-12-04 14:35:11 +00:00
|
|
|
Logic: 1,
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
2023-12-05 14:00:16 +00:00
|
|
|
if isUser {
|
|
|
|
v.User = 1
|
|
|
|
}
|
|
|
|
i.inhumedByCnrID[containerID] = v
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
2023-02-02 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
// SetAddresses sets a list of object addresses that should be inhumed.
|
|
|
|
func (p *InhumePrm) SetAddresses(addrs ...oid.Address) {
|
|
|
|
p.target = addrs
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
// SetTombstoneAddress sets tombstone address as the reason for inhume operation.
|
2021-02-15 11:11:10 +00:00
|
|
|
//
|
|
|
|
// addr should not be nil.
|
2022-07-12 14:59:37 +00:00
|
|
|
// Should not be called along with SetGCMark.
|
|
|
|
func (p *InhumePrm) SetTombstoneAddress(addr oid.Address) {
|
|
|
|
p.tomb = &addr
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
// SetGCMark marks the object to be physically removed.
|
2021-02-15 11:11:10 +00:00
|
|
|
//
|
2022-07-12 14:59:37 +00:00
|
|
|
// Should not be called along with SetTombstoneAddress.
|
|
|
|
func (p *InhumePrm) SetGCMark() {
|
|
|
|
p.tomb = nil
|
2021-02-15 11:11:10 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
// SetLockObjectHandling checks if there were
|
2022-05-26 17:38:32 +00:00
|
|
|
// any LOCK object among the targets set via WithAddresses.
|
2022-07-12 14:59:37 +00:00
|
|
|
func (p *InhumePrm) SetLockObjectHandling() {
|
|
|
|
p.lockObjectHandling = true
|
2022-05-26 17:38:32 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
// SetForceGCMark allows removal any object. Expected to be
|
2022-05-31 20:11:42 +00:00
|
|
|
// called only in control service.
|
2022-07-12 14:59:37 +00:00
|
|
|
func (p *InhumePrm) SetForceGCMark() {
|
|
|
|
p.tomb = nil
|
|
|
|
p.forceRemoval = true
|
2022-05-31 20:11:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 09:49:23 +00:00
|
|
|
var errBreakBucketForEach = errors.New("bucket ForEach break")
|
|
|
|
|
2022-06-06 14:44:37 +00:00
|
|
|
// ErrLockObjectRemoval is returned when inhume operation is being
|
|
|
|
// performed on lock object, and it is not a forced object removal.
|
2022-10-31 07:02:30 +00:00
|
|
|
var ErrLockObjectRemoval = logicerr.New("lock object removal")
|
2022-06-06 14:44:37 +00:00
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
// Inhume marks objects as removed but not removes it from metabase.
|
2022-02-15 22:16:07 +00:00
|
|
|
//
|
|
|
|
// Allows inhuming non-locked objects only. Returns apistatus.ObjectLocked
|
2022-07-07 12:33:27 +00:00
|
|
|
// if at least one object is locked. Returns ErrLockObjectRemoval if inhuming
|
|
|
|
// is being performed on lock (not locked) object.
|
|
|
|
//
|
|
|
|
// NOTE: Marks any object with GC mark (despite any prohibitions on operations
|
|
|
|
// with that object) if WithForceGCMark option has been provided.
|
2023-11-02 10:50:52 +00:00
|
|
|
func (db *DB) Inhume(ctx context.Context, prm InhumePrm) (InhumeRes, error) {
|
2023-06-06 09:27:19 +00:00
|
|
|
var (
|
|
|
|
startedAt = time.Now()
|
|
|
|
success = false
|
|
|
|
)
|
|
|
|
defer func() {
|
|
|
|
db.metrics.AddMethodDuration("Inhume", time.Since(startedAt), success)
|
|
|
|
}()
|
2023-04-12 14:01:29 +00:00
|
|
|
_, span := tracing.StartSpanFromContext(ctx, "metabase.Inhume")
|
|
|
|
defer span.End()
|
|
|
|
|
2022-07-21 13:26:25 +00:00
|
|
|
db.modeMtx.RLock()
|
|
|
|
defer db.modeMtx.RUnlock()
|
|
|
|
|
2022-10-26 06:12:09 +00:00
|
|
|
if db.mode.NoMetabase() {
|
|
|
|
return InhumeRes{}, ErrDegradedMode
|
2022-11-15 14:53:23 +00:00
|
|
|
} else if db.mode.ReadOnly() {
|
|
|
|
return InhumeRes{}, ErrReadOnlyMode
|
2022-10-26 06:12:09 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 10:50:52 +00:00
|
|
|
res := InhumeRes{
|
|
|
|
inhumedByCnrID: make(map[cid.ID]ObjectCounters),
|
|
|
|
}
|
2022-07-27 18:38:28 +00:00
|
|
|
currEpoch := db.epochState.CurrentEpoch()
|
2024-09-19 14:00:58 +00:00
|
|
|
err := db.boltDB.Batch(func(tx *bbolt.Tx) error {
|
2023-03-31 11:12:18 +00:00
|
|
|
return db.inhumeTx(tx, currEpoch, prm, &res)
|
|
|
|
})
|
2023-06-06 09:27:19 +00:00
|
|
|
success = err == nil
|
2024-01-15 05:52:52 +00:00
|
|
|
if success {
|
|
|
|
for _, addr := range prm.target {
|
|
|
|
storagelog.Write(db.log,
|
|
|
|
storagelog.AddressField(addr),
|
|
|
|
storagelog.OpField("metabase INHUME"))
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 10:19:36 +00:00
|
|
|
return res, metaerr.Wrap(err)
|
2023-03-31 11:12:18 +00:00
|
|
|
}
|
2021-04-08 14:19:31 +00:00
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
func (db *DB) inhumeTx(tx *bbolt.Tx, epoch uint64, prm InhumePrm, res *InhumeRes) error {
|
|
|
|
garbageBKT := tx.Bucket(garbageBucketName)
|
|
|
|
graveyardBKT := tx.Bucket(graveyardBucketName)
|
|
|
|
|
|
|
|
bkt, value, err := db.getInhumeTargetBucketAndValue(garbageBKT, graveyardBKT, &prm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := make([]byte, addressKeySize)
|
|
|
|
for i := range prm.target {
|
|
|
|
id := prm.target[i].Object()
|
|
|
|
cnr := prm.target[i].Container()
|
|
|
|
|
|
|
|
// prevent locked objects to be inhumed
|
|
|
|
if !prm.forceRemoval && objectLocked(tx, cnr, id) {
|
2023-08-04 11:14:07 +00:00
|
|
|
return new(apistatus.ObjectLocked)
|
2021-02-19 09:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
var lockWasChecked bool
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
// prevent lock objects to be inhumed
|
|
|
|
// if `Inhume` was called not with the
|
|
|
|
// `WithForceGCMark` option
|
|
|
|
if !prm.forceRemoval {
|
|
|
|
if isLockObject(tx, cnr, id) {
|
|
|
|
return ErrLockObjectRemoval
|
2022-02-15 22:16:07 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
lockWasChecked = true
|
|
|
|
}
|
2022-05-31 20:11:42 +00:00
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
obj, err := db.get(tx, prm.target[i], buf, false, true, epoch)
|
|
|
|
targetKey := addressKey(prm.target[i], buf)
|
2024-05-27 19:07:43 +00:00
|
|
|
var ecErr *objectSDK.ECInfoError
|
2023-03-31 11:12:18 +00:00
|
|
|
if err == nil {
|
|
|
|
err = db.updateDeleteInfo(tx, garbageBKT, graveyardBKT, targetKey, cnr, obj, res)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-05-27 19:07:43 +00:00
|
|
|
} else if errors.As(err, &ecErr) {
|
2024-08-19 09:34:05 +00:00
|
|
|
err = db.inhumeECInfo(tx, epoch, prm.tomb, res, garbageBKT, graveyardBKT, ecErr.ECInfo(), cnr, bkt, value)
|
2024-05-27 19:07:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-31 11:12:18 +00:00
|
|
|
}
|
2022-05-31 20:11:42 +00:00
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
if prm.tomb != nil {
|
|
|
|
var isTomb bool
|
|
|
|
isTomb, err = db.markAsGC(graveyardBKT, garbageBKT, targetKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-05-31 20:11:42 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
if isTomb {
|
|
|
|
continue
|
2021-02-15 11:50:21 +00:00
|
|
|
}
|
2023-03-31 11:12:18 +00:00
|
|
|
}
|
2021-02-15 11:50:21 +00:00
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
// consider checking if target is already in graveyard?
|
|
|
|
err = bkt.Put(targetKey, value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.lockObjectHandling {
|
|
|
|
// do not perform lock check if
|
|
|
|
// it was already called
|
|
|
|
if lockWasChecked {
|
|
|
|
// inhumed object is not of
|
|
|
|
// the LOCK type
|
|
|
|
continue
|
2021-02-15 11:50:21 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
if isLockObject(tx, cnr, id) {
|
|
|
|
res.deletedLockObj = append(res.deletedLockObj, prm.target[i])
|
2021-01-22 11:07:08 +00:00
|
|
|
}
|
2023-03-31 11:12:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-26 17:38:32 +00:00
|
|
|
|
2023-11-01 17:53:24 +00:00
|
|
|
return db.applyInhumeResToCounters(tx, res)
|
|
|
|
}
|
|
|
|
|
2024-05-27 19:07:43 +00:00
|
|
|
func (db *DB) inhumeECInfo(tx *bbolt.Tx, epoch uint64, tomb *oid.Address, res *InhumeRes,
|
|
|
|
garbageBKT *bbolt.Bucket, graveyardBKT *bbolt.Bucket,
|
2024-08-19 09:34:05 +00:00
|
|
|
ecInfo *objectSDK.ECInfo, cnr cid.ID, targetBucket *bbolt.Bucket, value []byte,
|
2024-05-27 19:07:43 +00:00
|
|
|
) error {
|
|
|
|
for _, chunk := range ecInfo.Chunks {
|
|
|
|
chunkBuf := make([]byte, addressKeySize)
|
|
|
|
var chunkAddr oid.Address
|
|
|
|
chunkAddr.SetContainer(cnr)
|
|
|
|
var chunkID oid.ID
|
|
|
|
err := chunkID.ReadFromV2(chunk.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
chunkAddr.SetObject(chunkID)
|
|
|
|
chunkObj, err := db.get(tx, chunkAddr, chunkBuf, false, true, epoch)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-08-19 09:34:05 +00:00
|
|
|
chunkKey := addressKey(chunkAddr, chunkBuf)
|
|
|
|
err = db.updateDeleteInfo(tx, garbageBKT, graveyardBKT, chunkKey, cnr, chunkObj, res)
|
2024-05-27 19:07:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if tomb != nil {
|
|
|
|
_, err = db.markAsGC(graveyardBKT, garbageBKT, chunkKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = targetBucket.Put(chunkKey, value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-01 17:53:24 +00:00
|
|
|
func (db *DB) applyInhumeResToCounters(tx *bbolt.Tx, res *InhumeRes) error {
|
2023-12-25 07:15:26 +00:00
|
|
|
if err := db.updateShardObjectCounter(tx, logical, res.LogicInhumed(), false); err != nil {
|
2023-12-05 14:00:16 +00:00
|
|
|
return err
|
2023-11-01 17:53:24 +00:00
|
|
|
}
|
2023-12-05 14:00:16 +00:00
|
|
|
if err := db.updateShardObjectCounter(tx, user, res.UserInhumed(), false); err != nil {
|
2023-11-01 17:53:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-12-05 14:00:16 +00:00
|
|
|
return db.updateContainerCounter(tx, res.inhumedByCnrID, false)
|
2023-03-31 11:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getInhumeTargetBucketAndValue return target bucket to store inhume result and value that will be put in the bucket.
|
|
|
|
//
|
|
|
|
// target bucket of the operation, one of the:
|
|
|
|
// 1. Graveyard if Inhume was called with a Tombstone
|
|
|
|
// 2. Garbage if Inhume was called with a GC mark
|
|
|
|
//
|
|
|
|
// value that will be put in the bucket, one of the:
|
|
|
|
// 1. tombstone address if Inhume was called with
|
|
|
|
// a Tombstone
|
|
|
|
// 2. zeroValue if Inhume was called with a GC mark
|
|
|
|
func (db *DB) getInhumeTargetBucketAndValue(garbageBKT, graveyardBKT *bbolt.Bucket, prm *InhumePrm) (targetBucket *bbolt.Bucket, value []byte, err error) {
|
|
|
|
if prm.tomb != nil {
|
|
|
|
targetBucket = graveyardBKT
|
|
|
|
tombKey := addressKey(*prm.tomb, make([]byte, addressKeySize))
|
|
|
|
|
|
|
|
// it is forbidden to have a tomb-on-tomb in FrostFS,
|
|
|
|
// so graveyard keys must not be addresses of tombstones
|
|
|
|
data := targetBucket.Get(tombKey)
|
|
|
|
if data != nil {
|
|
|
|
err := targetBucket.Delete(tombKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("could not remove grave with tombstone key: %w", err)
|
2022-05-26 17:38:32 +00:00
|
|
|
}
|
2021-01-22 11:07:08 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
value = tombKey
|
|
|
|
} else {
|
|
|
|
targetBucket = garbageBKT
|
|
|
|
value = zeroValue
|
|
|
|
}
|
|
|
|
return targetBucket, value, nil
|
|
|
|
}
|
2020-12-08 09:56:14 +00:00
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
func (db *DB) markAsGC(graveyardBKT, garbageBKT *bbolt.Bucket, key []byte) (bool, error) {
|
|
|
|
targetIsTomb, err := isTomb(graveyardBKT, key)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2022-09-09 11:33:38 +00:00
|
|
|
|
2023-03-31 11:12:18 +00:00
|
|
|
// do not add grave if target is a tombstone
|
|
|
|
if targetIsTomb {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// if tombstone appears object must be
|
|
|
|
// additionally marked with GC
|
|
|
|
return false, garbageBKT.Put(key, zeroValue)
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (db *DB) updateDeleteInfo(tx *bbolt.Tx, garbageBKT, graveyardBKT *bbolt.Bucket, targetKey []byte, cnr cid.ID, obj *objectSDK.Object, res *InhumeRes) error {
|
2023-03-31 11:12:18 +00:00
|
|
|
containerID, _ := obj.ContainerID()
|
|
|
|
if inGraveyardWithKey(targetKey, graveyardBKT, garbageBKT) == 0 {
|
2023-12-05 14:00:16 +00:00
|
|
|
res.storeDeletionInfo(containerID, obj.PayloadSize(), IsUserObject(obj))
|
2023-03-31 11:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if object is stored, and it is regular object then update bucket
|
|
|
|
// with container size estimations
|
2023-07-06 12:36:41 +00:00
|
|
|
if obj.Type() == objectSDK.TypeRegular {
|
2023-03-31 11:12:18 +00:00
|
|
|
err := changeContainerSize(tx, cnr, obj.PayloadSize(), false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func isTomb(graveyardBucket *bbolt.Bucket, key []byte) (bool, error) {
|
|
|
|
targetIsTomb := false
|
|
|
|
|
|
|
|
// iterate over graveyard and check if target address
|
|
|
|
// is the address of tombstone in graveyard.
|
2024-03-11 14:11:49 +00:00
|
|
|
err := graveyardBucket.ForEach(func(_, v []byte) error {
|
2023-03-31 11:12:18 +00:00
|
|
|
// check if graveyard has record with key corresponding
|
|
|
|
// to tombstone address (at least one)
|
|
|
|
targetIsTomb = bytes.Equal(v, key)
|
|
|
|
|
|
|
|
if targetIsTomb {
|
|
|
|
// break bucket iterator
|
|
|
|
return errBreakBucketForEach
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil && !errors.Is(err, errBreakBucketForEach) {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return targetIsTomb, nil
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|