Dmitrii Stepanov
b33559754d
All checks were successful
DCO action / DCO (pull_request) Successful in 1m2s
Vulncheck / Vulncheck (pull_request) Successful in 1m20s
Tests and linters / Run gofumpt (pull_request) Successful in 1m44s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m6s
Build / Build Components (pull_request) Successful in 2m19s
Tests and linters / gopls check (pull_request) Successful in 2m34s
Tests and linters / Staticcheck (pull_request) Successful in 2m36s
Tests and linters / Lint (pull_request) Successful in 3m29s
Tests and linters / Tests (pull_request) Successful in 4m0s
Tests and linters / Tests with -race (pull_request) Successful in 5m48s
This allow to not to call `os.Stat` if caller already knows data size. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
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(logs.WritecacheCantRemoveObjectFromWritecache, zap.Error(err))
|
|
} else if err == nil {
|
|
storagelog.Write(c.log,
|
|
storagelog.AddressField(addr.EncodeToString()),
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
storagelog.OpField("fstree DELETE"),
|
|
)
|
|
c.metrics.Evict(StorageTypeFSTree)
|
|
// counter changed by fstree
|
|
c.estimateCacheSize()
|
|
}
|
|
}
|