forked from TrueCloudLab/frostfs-node
[#1367] writecache: Drop bbolt DB
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
66e17f4b8e
commit
5f6c7cbdb1
12 changed files with 82 additions and 415 deletions
|
@ -5,13 +5,12 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"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/shard/mode"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
||||
"go.etcd.io/bbolt"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
@ -53,7 +52,7 @@ func (c *cache) setMode(ctx context.Context, m mode.Mode, prm setModePrm) error
|
|||
}
|
||||
}
|
||||
|
||||
if err := c.closeDB(prm.shrink); err != nil {
|
||||
if err := c.closeStorage(ctx, prm.shrink); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -78,33 +77,37 @@ func (c *cache) setMode(ctx context.Context, m mode.Mode, prm setModePrm) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *cache) closeDB(shrink bool) error {
|
||||
if c.db == nil {
|
||||
func (c *cache) closeStorage(ctx context.Context, shrink bool) error {
|
||||
if c.fsTree == nil {
|
||||
return nil
|
||||
}
|
||||
if !shrink {
|
||||
if err := c.db.Close(); err != nil {
|
||||
return fmt.Errorf("can't close write-cache database: %w", err)
|
||||
if err := c.fsTree.Close(); err != nil {
|
||||
return fmt.Errorf("can't close write-cache storage: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var empty bool
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
b := tx.Bucket(defaultBucket)
|
||||
empty = b == nil || b.Stats().KeyN == 0
|
||||
return nil
|
||||
empty := true
|
||||
_, err := c.fsTree.Iterate(ctx, common.IteratePrm{
|
||||
Handler: func(common.IterationElement) error {
|
||||
return errIterationCompleted
|
||||
},
|
||||
})
|
||||
if err != nil && !errors.Is(err, bbolt.ErrDatabaseNotOpen) {
|
||||
return fmt.Errorf("failed to check DB items: %w", err)
|
||||
if err != nil {
|
||||
if errors.Is(err, errIterationCompleted) {
|
||||
empty = false
|
||||
} else {
|
||||
return fmt.Errorf("failed to check write-cache items: %w", err)
|
||||
}
|
||||
}
|
||||
if err := c.db.Close(); err != nil {
|
||||
return fmt.Errorf("can't close write-cache database: %w", err)
|
||||
if err := c.fsTree.Close(); err != nil {
|
||||
return fmt.Errorf("can't close write-cache storage: %w", err)
|
||||
}
|
||||
if empty {
|
||||
err := os.Remove(filepath.Join(c.path, dbName))
|
||||
err := os.RemoveAll(c.path)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to remove DB file: %w", err)
|
||||
return fmt.Errorf("failed to remove write-cache files: %w", err)
|
||||
}
|
||||
} else {
|
||||
c.log.Info(logs.WritecacheShrinkSkippedNotEmpty)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue