2023-09-19 10:50:14 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-09-21 15:18:20 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-09-22 10:07:32 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2023-09-21 15:18:20 +00:00
|
|
|
"go.uber.org/zap"
|
2023-09-19 10:50:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type StorageIDUpdate interface {
|
2023-09-22 10:07:32 +00:00
|
|
|
UpdateStorageID(ctx context.Context, addr oid.Address, storageID []byte) error
|
2023-09-19 10:50:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-03 08:58:35 +00:00
|
|
|
type ConcurrentWorkersLimiter interface {
|
|
|
|
AcquireWorkSlot(ctx context.Context) error
|
|
|
|
ReleaseWorkSlot()
|
|
|
|
}
|
|
|
|
|
2024-09-04 06:30:56 +00:00
|
|
|
func (b *BlobStor) Rebuild(ctx context.Context, upd StorageIDUpdate, limiter ConcurrentWorkersLimiter, fillPercent int) error {
|
2023-09-21 15:18:20 +00:00
|
|
|
var summary common.RebuildRes
|
|
|
|
var rErr error
|
|
|
|
for _, storage := range b.storage {
|
|
|
|
res, err := storage.Storage.Rebuild(ctx, common.RebuildPrm{
|
2023-10-03 08:58:35 +00:00
|
|
|
MetaStorage: upd,
|
|
|
|
WorkerLimiter: limiter,
|
2024-09-04 06:30:56 +00:00
|
|
|
FillPercent: fillPercent,
|
2023-09-21 15:18:20 +00:00
|
|
|
})
|
|
|
|
summary.FilesRemoved += res.FilesRemoved
|
|
|
|
summary.ObjectsMoved += res.ObjectsMoved
|
|
|
|
if err != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Error(ctx, logs.BlobstorRebuildFailedToRebuildStorages,
|
2023-09-21 15:18:20 +00:00
|
|
|
zap.String("failed_storage_path", storage.Storage.Path()),
|
|
|
|
zap.String("failed_storage_type", storage.Storage.Type()),
|
|
|
|
zap.Error(err))
|
|
|
|
rErr = err
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Info(ctx, logs.BlobstorRebuildRebuildStoragesCompleted,
|
2023-09-21 15:18:20 +00:00
|
|
|
zap.Bool("success", rErr == nil),
|
|
|
|
zap.Uint64("total_files_removed", summary.FilesRemoved),
|
|
|
|
zap.Uint64("total_objects_moved", summary.ObjectsMoved))
|
|
|
|
return rErr
|
2023-09-19 10:50:14 +00:00
|
|
|
}
|