57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package writecache
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
|
storagelog "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/log"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func (c *cache) openStore(mod mode.ComponentMode) error {
|
|
err := util.MkdirAllX(c.path, os.ModePerm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.fsTree = fstree.New(
|
|
fstree.WithPath(c.path),
|
|
fstree.WithPerm(os.ModePerm),
|
|
fstree.WithDepth(1),
|
|
fstree.WithDirNameLen(1),
|
|
fstree.WithNoSync(c.noSync),
|
|
fstree.WithFileCounter(c.counter),
|
|
)
|
|
if err := c.fsTree.Open(mod); err != nil {
|
|
return fmt.Errorf("could not open FSTree: %w", err)
|
|
}
|
|
if err := c.fsTree.Init(); err != nil {
|
|
return fmt.Errorf("could not init FSTree: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *cache) deleteFromDisk(ctx context.Context, addr oid.Address, size uint64) {
|
|
_, err := c.fsTree.Delete(ctx, common.DeletePrm{Address: addr, Size: size})
|
|
if err != nil && !client.IsErrObjectNotFound(err) {
|
|
c.log.Error(ctx, logs.WritecacheCantRemoveObjectFromWritecache, zap.Error(err))
|
|
} else if err == nil {
|
|
storagelog.Write(ctx, c.log,
|
|
storagelog.AddressField(addr.EncodeToString()),
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
storagelog.OpField("fstree DELETE"),
|
|
)
|
|
c.metrics.Evict(StorageTypeFSTree)
|
|
// counter changed by fstree
|
|
c.estimateCacheSize()
|
|
}
|
|
}
|