All checks were successful
ci/woodpecker/pr/pre-commit Pipeline was successful
Do not use write-cache as a read cache: always remove objects from the WC, not only if an object hasn't been used for some time (LRU cache is dropped). Use object size (in bytes) as a metric of used space, not an approximate (and too inaccurate) maximum stored objects number. Signed-off-by: Pavel Karpy <p.karpy@yadro.com>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package writecache
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
// smallStore represents persistent storage with in-memory LRU cache
|
|
// for flushed items on top of it.
|
|
type smallStore struct {
|
|
db *bbolt.DB
|
|
}
|
|
|
|
const dbName = "small.bolt"
|
|
|
|
func (c *Cache) openStore(readOnly bool) error {
|
|
err := util.MkdirAllX(c.path, os.ModePerm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.db, err = OpenDB(c.path, readOnly, c.openFile)
|
|
if err != nil {
|
|
return fmt.Errorf("could not open database: %w", err)
|
|
}
|
|
|
|
c.db.MaxBatchSize = c.maxBatchSize
|
|
c.db.MaxBatchDelay = c.maxBatchDelay
|
|
|
|
if !readOnly {
|
|
err = c.db.Update(func(tx *bbolt.Tx) error {
|
|
_, err := tx.CreateBucketIfNotExists(defaultBucket)
|
|
return err
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("could not create default bucket: %w", err)
|
|
}
|
|
}
|
|
|
|
c.fsTree = fstree.New(
|
|
fstree.WithPath(c.path),
|
|
fstree.WithPerm(os.ModePerm),
|
|
fstree.WithDepth(1),
|
|
fstree.WithDirNameLen(1),
|
|
fstree.WithNoSync(c.noSync))
|
|
if err = c.fsTree.Open(readOnly); err != nil {
|
|
return fmt.Errorf("could not open FSTree: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|