2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
2023-05-28 19:37:37 +00:00
|
|
|
"context"
|
2024-08-27 12:51:55 +00:00
|
|
|
"strings"
|
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 {
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Debug(context.Background(), logs.BlobovniczatreeInitializingBlobovniczas)
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
if b.readOnly {
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Debug(context.Background(), 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)
|
2024-08-27 12:51:55 +00:00
|
|
|
err = b.iterateIncompletedRebuildDBPaths(egCtx, func(p string) (bool, error) {
|
2023-09-22 14:08:48 +00:00
|
|
|
eg.Go(func() error {
|
2024-08-27 12:51:55 +00:00
|
|
|
p = strings.TrimSuffix(p, rebuildSuffix)
|
2023-09-22 14:08:48 +00:00
|
|
|
shBlz := b.getBlobovniczaWithoutCaching(p)
|
2024-10-21 08:20:17 +00:00
|
|
|
blz, err := shBlz.Open(egCtx)
|
2023-09-22 14:08:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-10-21 13:27:28 +00:00
|
|
|
defer shBlz.Close(egCtx)
|
2023-09-22 14:08:48 +00:00
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Debug(egCtx, logs.BlobovniczatreeBlobovniczaSuccessfullyInitializedClosing, zap.String("id", p))
|
2023-09-22 14:08:48 +00:00
|
|
|
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.
|
2024-10-21 13:27:28 +00:00
|
|
|
func (b *Blobovniczas) Close(ctx context.Context) error {
|
2023-10-31 11:56:55 +00:00
|
|
|
b.dbCache.Close() // order important
|
2024-10-21 13:27:28 +00:00
|
|
|
b.activeDBManager.Close(ctx)
|
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.
|
2024-10-21 08:20:17 +00:00
|
|
|
func (b *Blobovniczas) getBlobovnicza(ctx context.Context, p string) *sharedDB {
|
|
|
|
return b.dbCache.GetOrCreate(ctx, 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
|
|
|
}
|