forked from TrueCloudLab/frostfs-node
77b1b80e73
It is not used for testing, its absence does not break build. The only one implementation is placed in the same package. Signed-off-by: Pavel Karpy <p.karpy@yadro.com>
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package writecache
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
|
"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"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"go.etcd.io/bbolt"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// Delete removes object from write-cache.
|
|
//
|
|
// Returns an error of type apistatus.ObjectNotFound if object is missing in write-cache.
|
|
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()
|
|
|
|
c.modeMtx.RLock()
|
|
defer c.modeMtx.RUnlock()
|
|
if c.readOnly() {
|
|
return ErrReadOnly
|
|
}
|
|
|
|
saddr := addr.EncodeToString()
|
|
|
|
// Check disk cache.
|
|
var has int
|
|
_ = c.db.View(func(tx *bbolt.Tx) error {
|
|
b := tx.Bucket(defaultBucket)
|
|
has = len(b.Get([]byte(saddr)))
|
|
return nil
|
|
})
|
|
|
|
if 0 < has {
|
|
err := c.db.Update(func(tx *bbolt.Tx) error {
|
|
b := tx.Bucket(defaultBucket)
|
|
err := b.Delete([]byte(saddr))
|
|
return err
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
storagelog.Write(c.log,
|
|
storagelog.AddressField(saddr),
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
storagelog.OpField("db DELETE"),
|
|
)
|
|
c.objCounters.DecDB()
|
|
return nil
|
|
}
|
|
|
|
_, err := c.fsTree.Delete(ctx, common.DeletePrm{Address: addr})
|
|
if err == nil {
|
|
storagelog.Write(c.log,
|
|
storagelog.AddressField(saddr),
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
storagelog.OpField("fstree DELETE"),
|
|
)
|
|
c.objCounters.DecFS()
|
|
}
|
|
|
|
return err
|
|
}
|