2023-12-22 09:58:20 +00:00
|
|
|
package writecache
|
2021-04-06 10:56:06 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2023-08-11 09:51:41 +00:00
|
|
|
"math"
|
2023-05-18 14:19:41 +00:00
|
|
|
"time"
|
2023-04-12 14:01:29 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
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-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-04-06 10:56:06 +00:00
|
|
|
"go.etcd.io/bbolt"
|
2023-04-12 14:01:29 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2021-04-06 10:56:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Delete removes object from write-cache.
|
2022-03-17 08:03:58 +00:00
|
|
|
//
|
2022-03-17 13:26:17 +00:00
|
|
|
// Returns an error of type apistatus.ObjectNotFound if object is missing in write-cache.
|
2023-12-27 08:40:55 +00:00
|
|
|
// Returns ErrNotInitialized if write-cache has not been initialized yet.
|
2024-02-20 14:24:57 +00:00
|
|
|
// Returns ErrDegraded if write-cache is in DEGRADED mode.
|
2023-04-12 14:01:29 +00:00
|
|
|
func (c *cache) Delete(ctx context.Context, addr oid.Address) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "writecache.Delete",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", addr.EncodeToString()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2023-05-18 14:19:41 +00:00
|
|
|
deleted := false
|
2023-12-22 09:58:20 +00:00
|
|
|
storageType := StorageTypeUndefined
|
2023-05-18 14:19:41 +00:00
|
|
|
startedAt := time.Now()
|
|
|
|
defer func() {
|
|
|
|
c.metrics.Delete(time.Since(startedAt), deleted, storageType)
|
|
|
|
}()
|
|
|
|
|
2023-12-27 08:40:55 +00:00
|
|
|
if !c.modeMtx.TryRLock() {
|
|
|
|
return ErrNotInitialized
|
|
|
|
}
|
2022-01-18 12:47:16 +00:00
|
|
|
defer c.modeMtx.RUnlock()
|
2022-03-17 11:55:25 +00:00
|
|
|
if c.readOnly() {
|
2023-12-22 09:58:20 +00:00
|
|
|
return ErrReadOnly
|
2022-01-18 12:47:16 +00:00
|
|
|
}
|
2024-02-20 14:24:57 +00:00
|
|
|
if c.noMetabase() {
|
|
|
|
return ErrDegraded
|
|
|
|
}
|
2022-01-18 12:47:16 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
saddr := addr.EncodeToString()
|
2021-04-06 10:56:06 +00:00
|
|
|
|
2023-05-18 14:19:41 +00:00
|
|
|
var dataSize int
|
2021-04-06 10:56:06 +00:00
|
|
|
_ = c.db.View(func(tx *bbolt.Tx) error {
|
|
|
|
b := tx.Bucket(defaultBucket)
|
2023-05-18 14:19:41 +00:00
|
|
|
dataSize = len(b.Get([]byte(saddr)))
|
2021-04-06 10:56:06 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2023-05-18 14:19:41 +00:00
|
|
|
if dataSize > 0 {
|
2023-12-22 09:58:20 +00:00
|
|
|
storageType = StorageTypeDB
|
2023-08-11 09:51:41 +00:00
|
|
|
var recordDeleted bool
|
2021-06-21 09:42:09 +00:00
|
|
|
err := c.db.Update(func(tx *bbolt.Tx) error {
|
2021-04-06 10:56:06 +00:00
|
|
|
b := tx.Bucket(defaultBucket)
|
2023-08-11 09:51:41 +00:00
|
|
|
key := []byte(saddr)
|
|
|
|
recordDeleted = b.Get(key) != nil
|
|
|
|
err := b.Delete(key)
|
2021-06-21 09:42:09 +00:00
|
|
|
return err
|
2021-04-06 10:56:06 +00:00
|
|
|
})
|
2021-06-21 09:42:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-20 12:29:05 +00:00
|
|
|
storagelog.Write(c.log,
|
|
|
|
storagelog.AddressField(saddr),
|
|
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
|
|
storagelog.OpField("db DELETE"),
|
|
|
|
)
|
2023-08-11 09:51:41 +00:00
|
|
|
if recordDeleted {
|
|
|
|
c.objCounters.cDB.Add(math.MaxUint64)
|
|
|
|
c.estimateCacheSize()
|
|
|
|
}
|
2023-05-18 14:19:41 +00:00
|
|
|
deleted = true
|
2021-06-21 09:42:09 +00:00
|
|
|
return nil
|
2021-04-06 10:56:06 +00:00
|
|
|
}
|
|
|
|
|
2023-12-22 09:58:20 +00:00
|
|
|
storageType = StorageTypeFSTree
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := c.fsTree.Delete(ctx, common.DeletePrm{Address: addr})
|
2021-09-06 14:28:55 +00:00
|
|
|
if err == nil {
|
2022-12-20 12:29:05 +00:00
|
|
|
storagelog.Write(c.log,
|
|
|
|
storagelog.AddressField(saddr),
|
|
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
|
|
storagelog.OpField("fstree DELETE"),
|
|
|
|
)
|
2023-05-18 14:19:41 +00:00
|
|
|
deleted = true
|
2023-10-27 06:53:12 +00:00
|
|
|
// counter changed by fstree
|
2023-08-11 09:51:41 +00:00
|
|
|
c.estimateCacheSize()
|
2021-09-06 14:28:55 +00:00
|
|
|
}
|
2023-06-15 10:19:36 +00:00
|
|
|
return metaerr.Wrap(err)
|
2021-04-06 10:56:06 +00:00
|
|
|
}
|