Some checks failed
Tests and linters / Tests with -race (pull_request) Failing after 12s
Tests and linters / Run gofumpt (pull_request) Successful in 1m14s
DCO action / DCO (pull_request) Successful in 1m26s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m51s
Vulncheck / Vulncheck (pull_request) Successful in 1m48s
Build / Build Components (pull_request) Successful in 2m2s
Tests and linters / Tests (pull_request) Successful in 3m7s
Tests and linters / Staticcheck (pull_request) Successful in 3m9s
Tests and linters / Lint (pull_request) Successful in 3m45s
Tests and linters / gopls check (pull_request) Successful in 3m56s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
101 lines
2.8 KiB
Go
101 lines
2.8 KiB
Go
package writecache
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"math"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"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"
|
|
"github.com/cockroachdb/pebble"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
const dbName = "pebble"
|
|
|
|
func (c *cache) openStore(mod mode.ComponentMode) error {
|
|
err := util.MkdirAllX(filepath.Join(c.path, dbName), os.ModePerm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.db, err = OpenDB(filepath.Join(c.path, dbName), mod.ReadOnly())
|
|
if err != nil {
|
|
return fmt.Errorf("could not open database: %w", err)
|
|
}
|
|
|
|
c.fsTree = fstree.New(
|
|
fstree.WithPath(filepath.Join(c.path, "fstree")),
|
|
fstree.WithPerm(os.ModePerm),
|
|
fstree.WithDepth(1),
|
|
fstree.WithDirNameLen(1),
|
|
fstree.WithNoSync(c.noSync),
|
|
fstree.WithFileCounter(&c.objCounters),
|
|
)
|
|
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) deleteFromDB(key string) {
|
|
c.dbEditLocker.Lock(key)
|
|
defer func() {
|
|
c.dbEditLocker.Unlock(key)
|
|
}()
|
|
var dataSize uint32
|
|
dbKey := []byte(key)
|
|
data, closer, err := c.db.Get(dbKey)
|
|
if err == nil {
|
|
dataSize = uint32(len(data))
|
|
err = closer.Close()
|
|
}
|
|
if err != nil && !errors.Is(err, pebble.ErrNotFound) {
|
|
c.log.Error(logs.WritecacheCantRemoveObjectsFromTheDatabase, zap.Error(err))
|
|
return
|
|
}
|
|
if err := c.db.DeleteSized(dbKey, dataSize, pebble.Sync); err != nil {
|
|
c.log.Error(logs.WritecacheCantRemoveObjectsFromTheDatabase, zap.Error(err))
|
|
return
|
|
}
|
|
|
|
c.metrics.Evict(StorageTypeDB)
|
|
storagelog.Write(c.log,
|
|
storagelog.AddressField(key),
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
storagelog.OpField("db DELETE"),
|
|
)
|
|
if dataSize > 0 {
|
|
c.objCounters.cDB.Add(math.MaxUint64)
|
|
c.estimateCacheSize()
|
|
}
|
|
}
|
|
|
|
func (c *cache) deleteFromDisk(ctx context.Context, addr oid.Address) {
|
|
_, err := c.fsTree.Delete(ctx, common.DeletePrm{Address: addr})
|
|
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()
|
|
}
|
|
}
|