2023-06-22 11:55:30 +00:00
|
|
|
package writecachebadger
|
2021-04-06 10:56:06 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
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
|
|
|
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-06-22 11:55:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-06-22 11:55:30 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2023-06-22 11:55:30 +00:00
|
|
|
"github.com/dgraph-io/badger/v4"
|
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-04-12 14:01:29 +00:00
|
|
|
func (c *cache) Delete(ctx context.Context, addr oid.Address) error {
|
2023-06-22 11:55:30 +00:00
|
|
|
_, span := tracing.StartSpanFromContext(ctx, "writecache.Delete",
|
2023-04-12 14:01:29 +00:00
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", addr.EncodeToString()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2023-05-18 14:19:41 +00:00
|
|
|
deleted := false
|
2023-06-22 11:55:30 +00:00
|
|
|
storageType := writecache.StorageTypeUndefined
|
2023-05-18 14:19:41 +00:00
|
|
|
startedAt := time.Now()
|
|
|
|
defer func() {
|
|
|
|
c.metrics.Delete(time.Since(startedAt), deleted, storageType)
|
|
|
|
}()
|
|
|
|
|
2022-01-18 12:47:16 +00:00
|
|
|
c.modeMtx.RLock()
|
|
|
|
defer c.modeMtx.RUnlock()
|
2022-03-17 11:55:25 +00:00
|
|
|
if c.readOnly() {
|
2023-06-22 11:55:30 +00:00
|
|
|
return writecache.ErrReadOnly
|
2022-01-18 12:47:16 +00:00
|
|
|
}
|
|
|
|
|
2023-08-29 12:26:22 +00:00
|
|
|
key := addr2key(addr)
|
2021-04-06 10:56:06 +00:00
|
|
|
|
2023-06-22 11:55:30 +00:00
|
|
|
err := c.db.Update(func(tx *badger.Txn) error {
|
2023-08-29 12:26:22 +00:00
|
|
|
it, err := tx.Get(key[:])
|
2021-06-21 09:42:09 +00:00
|
|
|
if err != nil {
|
2023-06-22 11:55:30 +00:00
|
|
|
if err == badger.ErrKeyNotFound {
|
2023-08-04 11:14:07 +00:00
|
|
|
return logicerr.Wrap(new(apistatus.ObjectNotFound))
|
2023-06-22 11:55:30 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if it.ValueSize() > 0 {
|
|
|
|
storageType = writecache.StorageTypeDB
|
2023-08-29 12:26:22 +00:00
|
|
|
err := tx.Delete(key[:])
|
2023-06-22 11:55:30 +00:00
|
|
|
if err == nil {
|
|
|
|
storagelog.Write(c.log,
|
2023-08-29 12:26:22 +00:00
|
|
|
storagelog.AddressField(addr.EncodeToString()),
|
2023-06-22 11:55:30 +00:00
|
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
|
|
storagelog.OpField("db DELETE"),
|
|
|
|
)
|
|
|
|
deleted = true
|
2023-10-27 06:53:12 +00:00
|
|
|
c.decDB()
|
2023-06-22 11:55:30 +00:00
|
|
|
}
|
2021-06-21 09:42:09 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2023-06-22 11:55:30 +00:00
|
|
|
})
|
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
|
|
|
}
|