2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
2023-05-28 19:37:37 +00:00
|
|
|
"context"
|
2022-07-05 13:47:39 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2024-06-04 13:28:47 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2023-09-20 14:46:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
2022-07-05 13:47:39 +00:00
|
|
|
"go.uber.org/zap"
|
2023-09-22 14:08:48 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2022-07-05 13:47:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Open opens blobovnicza tree.
|
2024-06-04 13:28:47 +00:00
|
|
|
func (b *Blobovniczas) Open(mode mode.ComponentMode) error {
|
|
|
|
b.readOnly = mode.ReadOnly()
|
|
|
|
b.metrics.SetMode(mode)
|
2023-09-27 15:21:37 +00:00
|
|
|
b.metrics.SetRebuildStatus(rebuildStatusNotStarted)
|
2023-08-30 20:36:48 +00:00
|
|
|
b.openManagers()
|
2022-07-05 13:47:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes blobovnicza tree.
|
|
|
|
//
|
|
|
|
// Should be called exactly once.
|
|
|
|
func (b *Blobovniczas) Init() error {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(logs.BlobovniczatreeInitializingBlobovniczas)
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
if b.readOnly {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(logs.BlobovniczatreeReadonlyModeSkipBlobovniczasInitialization)
|
2022-07-05 13:47:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-20 14:46:10 +00:00
|
|
|
return b.initializeDBs(context.TODO())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Blobovniczas) initializeDBs(ctx context.Context) error {
|
|
|
|
err := util.MkdirAllX(b.rootPath, b.perm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-09-22 14:08:48 +00:00
|
|
|
eg, egCtx := errgroup.WithContext(ctx)
|
|
|
|
eg.SetLimit(b.blzInitWorkerCount)
|
2023-09-20 14:46:10 +00:00
|
|
|
visited := make(map[string]struct{})
|
2023-09-22 14:08:48 +00:00
|
|
|
err = b.iterateExistingDBPaths(egCtx, func(p string) (bool, error) {
|
2023-09-20 14:46:10 +00:00
|
|
|
visited[p] = struct{}{}
|
2023-09-22 14:08:48 +00:00
|
|
|
eg.Go(func() error {
|
|
|
|
shBlz := b.getBlobovniczaWithoutCaching(p)
|
2023-09-27 13:25:15 +00:00
|
|
|
blz, err := shBlz.Open()
|
2023-09-22 14:08:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer shBlz.Close()
|
|
|
|
|
2023-09-27 13:25:15 +00:00
|
|
|
moveInfo, err := blz.ListMoveInfo(egCtx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, move := range moveInfo {
|
|
|
|
b.deleteProtectedObjects.Add(move.Address)
|
|
|
|
}
|
|
|
|
|
2023-09-22 14:08:48 +00:00
|
|
|
b.log.Debug(logs.BlobovniczatreeBlobovniczaSuccessfullyInitializedClosing, zap.String("id", p))
|
|
|
|
return nil
|
|
|
|
})
|
2023-09-20 14:46:10 +00:00
|
|
|
return false, nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-09-22 14:08:48 +00:00
|
|
|
_ = eg.Wait()
|
2023-09-20 14:46:10 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-09-22 14:08:48 +00:00
|
|
|
return eg.Wait()
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
func (b *Blobovniczas) openManagers() {
|
2023-10-31 11:56:55 +00:00
|
|
|
b.commondbManager.Open() // order important
|
2023-08-30 20:36:48 +00:00
|
|
|
b.activeDBManager.Open()
|
2023-08-31 08:32:09 +00:00
|
|
|
b.dbCache.Open()
|
2023-08-30 20:36:48 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 07:09:48 +00:00
|
|
|
// Close implements common.Storage.
|
2022-07-05 13:47:39 +00:00
|
|
|
func (b *Blobovniczas) Close() error {
|
2023-10-31 11:56:55 +00:00
|
|
|
b.dbCache.Close() // order important
|
2023-08-31 08:32:09 +00:00
|
|
|
b.activeDBManager.Close()
|
2023-08-30 20:36:48 +00:00
|
|
|
b.commondbManager.Close()
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-08-31 08:32:09 +00:00
|
|
|
// returns blobovnicza with path p
|
2022-07-18 06:16:36 +00:00
|
|
|
//
|
2023-08-31 08:32:09 +00:00
|
|
|
// If blobovnicza is already cached, instance from cache is returned w/o changes.
|
|
|
|
func (b *Blobovniczas) getBlobovnicza(p string) *sharedDB {
|
|
|
|
return b.dbCache.GetOrCreate(p)
|
2022-08-29 07:49:14 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 08:32:09 +00:00
|
|
|
func (b *Blobovniczas) getBlobovniczaWithoutCaching(p string) *sharedDB {
|
2023-08-30 20:36:48 +00:00
|
|
|
return b.commondbManager.GetByPath(p)
|
2022-07-18 06:16:36 +00:00
|
|
|
}
|