2023-09-21 15:18:20 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
2023-10-10 13:01:35 +00:00
|
|
|
"bytes"
|
2023-09-21 15:18:20 +00:00
|
|
|
"context"
|
2023-09-22 10:07:32 +00:00
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2024-08-27 12:51:55 +00:00
|
|
|
"strings"
|
2023-09-27 13:25:15 +00:00
|
|
|
"sync"
|
2023-10-03 08:58:35 +00:00
|
|
|
"sync/atomic"
|
2023-09-22 10:07:32 +00:00
|
|
|
"time"
|
2023-09-21 15:18:20 +00:00
|
|
|
|
2023-09-22 10:07:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
2023-09-21 15:18:20 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-09-27 13:25:15 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-09-22 10:07:32 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"go.uber.org/zap"
|
2023-10-03 08:58:35 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2023-09-21 15:18:20 +00:00
|
|
|
)
|
|
|
|
|
2024-08-27 12:51:55 +00:00
|
|
|
const rebuildSuffix = ".rebuild"
|
|
|
|
|
2023-10-10 13:01:35 +00:00
|
|
|
var (
|
|
|
|
errRebuildInProgress = errors.New("rebuild is in progress, the operation cannot be performed")
|
|
|
|
errBatchFull = errors.New("batch full")
|
|
|
|
)
|
2023-09-22 10:07:32 +00:00
|
|
|
|
|
|
|
func (b *Blobovniczas) Rebuild(ctx context.Context, prm common.RebuildPrm) (common.RebuildRes, error) {
|
|
|
|
if b.readOnly {
|
|
|
|
return common.RebuildRes{}, common.ErrReadOnly
|
|
|
|
}
|
|
|
|
|
2023-09-27 15:21:37 +00:00
|
|
|
b.metrics.SetRebuildStatus(rebuildStatusRunning)
|
2023-10-11 06:23:55 +00:00
|
|
|
b.metrics.SetRebuildPercent(0)
|
2023-09-27 15:21:37 +00:00
|
|
|
success := true
|
|
|
|
defer func() {
|
|
|
|
if success {
|
|
|
|
b.metrics.SetRebuildStatus(rebuildStatusCompleted)
|
|
|
|
} else {
|
|
|
|
b.metrics.SetRebuildStatus(rebuildStatusFailed)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2023-09-22 10:07:32 +00:00
|
|
|
b.rebuildGuard.Lock()
|
|
|
|
defer b.rebuildGuard.Unlock()
|
|
|
|
|
|
|
|
var res common.RebuildRes
|
2023-09-27 13:25:15 +00:00
|
|
|
|
|
|
|
b.log.Debug(logs.BlobovniczaTreeCompletingPreviousRebuild)
|
|
|
|
completedPreviosMoves, err := b.completeIncompletedMove(ctx, prm.MetaStorage)
|
|
|
|
res.ObjectsMoved += completedPreviosMoves
|
|
|
|
if err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczaTreeCompletedPreviousRebuildFailed, zap.Error(err))
|
2023-09-27 15:21:37 +00:00
|
|
|
success = false
|
2023-09-27 13:25:15 +00:00
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
b.log.Debug(logs.BlobovniczaTreeCompletedPreviousRebuildSuccess)
|
|
|
|
|
|
|
|
b.log.Debug(logs.BlobovniczaTreeCollectingDBToRebuild)
|
2023-09-22 10:07:32 +00:00
|
|
|
dbsToMigrate, err := b.getDBsToRebuild(ctx)
|
|
|
|
if err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczaTreeCollectingDBToRebuildFailed, zap.Error(err))
|
2023-09-27 15:21:37 +00:00
|
|
|
success = false
|
2023-09-22 10:07:32 +00:00
|
|
|
return res, err
|
|
|
|
}
|
2023-10-03 08:58:35 +00:00
|
|
|
|
2023-09-22 10:07:32 +00:00
|
|
|
b.log.Info(logs.BlobovniczaTreeCollectingDBToRebuildSuccess, zap.Int("blobovniczas_to_rebuild", len(dbsToMigrate)))
|
2023-10-03 08:58:35 +00:00
|
|
|
res, err = b.migrateDBs(ctx, dbsToMigrate, prm, res)
|
|
|
|
if err != nil {
|
|
|
|
success = false
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Blobovniczas) migrateDBs(ctx context.Context, dbs []string, prm common.RebuildPrm, res common.RebuildRes) (common.RebuildRes, error) {
|
2023-10-11 06:23:55 +00:00
|
|
|
var completedDBCount uint32
|
2023-10-03 08:58:35 +00:00
|
|
|
for _, db := range dbs {
|
2023-10-10 13:01:35 +00:00
|
|
|
b.log.Debug(logs.BlobovniczaTreeRebuildingBlobovnicza, zap.String("path", db))
|
|
|
|
movedObjects, err := b.rebuildDB(ctx, db, prm.MetaStorage, prm.WorkerLimiter)
|
|
|
|
res.ObjectsMoved += movedObjects
|
|
|
|
if err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczaTreeRebuildingBlobovniczaFailed, zap.String("path", db), zap.Uint64("moved_objects_count", movedObjects), zap.Error(err))
|
2023-09-22 10:07:32 +00:00
|
|
|
return res, err
|
|
|
|
}
|
2023-10-10 13:01:35 +00:00
|
|
|
b.log.Debug(logs.BlobovniczaTreeRebuildingBlobovniczaSuccess, zap.String("path", db), zap.Uint64("moved_objects_count", movedObjects))
|
|
|
|
res.FilesRemoved++
|
2023-10-11 06:23:55 +00:00
|
|
|
completedDBCount++
|
|
|
|
b.metrics.SetRebuildPercent((100 * completedDBCount) / uint32(len(dbs)))
|
2023-09-22 10:07:32 +00:00
|
|
|
}
|
2023-10-11 06:23:55 +00:00
|
|
|
b.metrics.SetRebuildPercent(100)
|
2023-10-10 13:01:35 +00:00
|
|
|
return res, nil
|
2023-09-22 10:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Blobovniczas) getDBsToRebuild(ctx context.Context) ([]string, error) {
|
|
|
|
dbsToMigrate := make(map[string]struct{})
|
|
|
|
if err := b.iterateExistingDBPaths(ctx, func(s string) (bool, error) {
|
|
|
|
dbsToMigrate[s] = struct{}{}
|
|
|
|
return false, nil
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := b.iterateSortedLeaves(ctx, nil, func(s string) (bool, error) {
|
|
|
|
delete(dbsToMigrate, s)
|
|
|
|
return false, nil
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
result := make([]string, 0, len(dbsToMigrate))
|
|
|
|
for db := range dbsToMigrate {
|
|
|
|
result = append(result, db)
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2023-10-10 13:01:35 +00:00
|
|
|
func (b *Blobovniczas) rebuildDB(ctx context.Context, path string, meta common.MetaStorage, limiter common.ConcurrentWorkersLimiter) (uint64, error) {
|
2023-09-22 10:07:32 +00:00
|
|
|
shDB := b.getBlobovnicza(path)
|
|
|
|
blz, err := shDB.Open()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
shDBClosed := false
|
|
|
|
defer func() {
|
|
|
|
if shDBClosed {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
shDB.Close()
|
|
|
|
}()
|
2024-08-27 12:51:55 +00:00
|
|
|
dropTempFile, err := b.addRebuildTempFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2023-10-10 13:01:35 +00:00
|
|
|
migratedObjects, err := b.moveObjects(ctx, blz, shDB.SystemPath(), meta, limiter)
|
2023-09-22 10:07:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return migratedObjects, err
|
|
|
|
}
|
|
|
|
shDBClosed, err = b.dropDB(ctx, path, shDB)
|
2024-08-27 12:51:55 +00:00
|
|
|
if err == nil {
|
|
|
|
// drop only on success to continue rebuild on error
|
|
|
|
dropTempFile()
|
|
|
|
}
|
2023-09-22 10:07:32 +00:00
|
|
|
return migratedObjects, err
|
|
|
|
}
|
|
|
|
|
2024-08-27 12:51:55 +00:00
|
|
|
func (b *Blobovniczas) addRebuildTempFile(path string) (func(), error) {
|
|
|
|
sysPath := filepath.Join(b.rootPath, path)
|
|
|
|
sysPath = sysPath + rebuildSuffix
|
|
|
|
_, err := os.OpenFile(sysPath, os.O_RDWR|os.O_CREATE|os.O_EXCL|os.O_SYNC, b.perm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return func() {
|
|
|
|
if err := os.Remove(sysPath); err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczatreeFailedToRemoveRebuildTempFile, zap.Error(err))
|
|
|
|
}
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-10-10 13:01:35 +00:00
|
|
|
func (b *Blobovniczas) moveObjects(ctx context.Context, blz *blobovnicza.Blobovnicza, blzPath string, meta common.MetaStorage, limiter common.ConcurrentWorkersLimiter) (uint64, error) {
|
|
|
|
var result atomic.Uint64
|
|
|
|
batch := make(map[oid.Address][]byte)
|
2023-09-22 10:07:32 +00:00
|
|
|
|
|
|
|
var prm blobovnicza.IteratePrm
|
|
|
|
prm.DecodeAddresses()
|
|
|
|
prm.SetHandler(func(ie blobovnicza.IterationElement) error {
|
2023-10-10 13:01:35 +00:00
|
|
|
batch[ie.Address()] = bytes.Clone(ie.ObjectData())
|
|
|
|
if len(batch) == b.blzMoveBatchSize {
|
|
|
|
return errBatchFull
|
2023-09-22 10:07:32 +00:00
|
|
|
}
|
2023-10-10 13:01:35 +00:00
|
|
|
return nil
|
2023-09-22 10:07:32 +00:00
|
|
|
})
|
|
|
|
|
2023-10-10 13:01:35 +00:00
|
|
|
for {
|
|
|
|
_, err := blz.Iterate(ctx, prm)
|
|
|
|
if err != nil && !errors.Is(err, errBatchFull) {
|
|
|
|
return result.Load(), err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(batch) == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
eg, egCtx := errgroup.WithContext(ctx)
|
|
|
|
|
|
|
|
for addr, data := range batch {
|
|
|
|
if err := limiter.AcquireWorkSlot(egCtx); err != nil {
|
|
|
|
_ = eg.Wait()
|
|
|
|
return result.Load(), err
|
|
|
|
}
|
|
|
|
eg.Go(func() error {
|
|
|
|
defer limiter.ReleaseWorkSlot()
|
|
|
|
err := b.moveObject(egCtx, blz, blzPath, addr, data, meta)
|
|
|
|
if err == nil {
|
|
|
|
result.Add(1)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if err := eg.Wait(); err != nil {
|
|
|
|
return result.Load(), err
|
|
|
|
}
|
|
|
|
|
|
|
|
batch = make(map[oid.Address][]byte)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.Load(), nil
|
2023-09-22 10:07:32 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 13:25:15 +00:00
|
|
|
func (b *Blobovniczas) moveObject(ctx context.Context, source *blobovnicza.Blobovnicza, sourcePath string,
|
2023-10-03 08:58:35 +00:00
|
|
|
addr oid.Address, data []byte, metaStore common.MetaStorage,
|
|
|
|
) error {
|
2023-09-27 15:21:37 +00:00
|
|
|
startedAt := time.Now()
|
|
|
|
defer func() {
|
|
|
|
b.metrics.ObjectMoved(time.Since(startedAt))
|
|
|
|
}()
|
2023-09-27 13:25:15 +00:00
|
|
|
it := &moveIterator{
|
|
|
|
B: b,
|
|
|
|
ID: nil,
|
|
|
|
AllFull: true,
|
|
|
|
Address: addr,
|
|
|
|
ObjectData: data,
|
|
|
|
MetaStore: metaStore,
|
|
|
|
Source: source,
|
|
|
|
SourceSysPath: sourcePath,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := b.iterateDeepest(ctx, addr, func(lvlPath string) (bool, error) { return it.tryMoveToLvl(ctx, lvlPath) }); err != nil {
|
2023-09-22 10:07:32 +00:00
|
|
|
return err
|
2023-09-27 13:25:15 +00:00
|
|
|
} else if it.ID == nil {
|
|
|
|
if it.AllFull {
|
|
|
|
return common.ErrNoSpace
|
|
|
|
}
|
|
|
|
return errPutFailed
|
2023-09-22 10:07:32 +00:00
|
|
|
}
|
2023-09-27 13:25:15 +00:00
|
|
|
return nil
|
2023-09-22 10:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Blobovniczas) dropDB(ctx context.Context, path string, shDb *sharedDB) (bool, error) {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return false, ctx.Err()
|
|
|
|
case <-time.After(b.waitBeforeDropDB): // to complete requests with old storage ID
|
|
|
|
}
|
|
|
|
|
|
|
|
b.dbCache.EvictAndMarkNonCached(path)
|
|
|
|
defer b.dbCache.RemoveFromNonCached(path)
|
|
|
|
|
|
|
|
b.dbFilesGuard.Lock()
|
|
|
|
defer b.dbFilesGuard.Unlock()
|
|
|
|
|
|
|
|
if err := shDb.CloseAndRemoveFile(); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
b.commondbManager.CleanResources(path)
|
|
|
|
if err := b.dropDirectoryIfEmpty(filepath.Dir(path)); err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Blobovniczas) dropDirectoryIfEmpty(path string) error {
|
|
|
|
if path == "." {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
sysPath := filepath.Join(b.rootPath, path)
|
|
|
|
entries, err := os.ReadDir(sysPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(entries) > 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err := os.Remove(sysPath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return b.dropDirectoryIfEmpty(filepath.Dir(path))
|
2023-09-21 15:18:20 +00:00
|
|
|
}
|
2023-09-27 13:25:15 +00:00
|
|
|
|
|
|
|
func (b *Blobovniczas) completeIncompletedMove(ctx context.Context, metaStore common.MetaStorage) (uint64, error) {
|
|
|
|
var count uint64
|
2024-08-27 12:51:55 +00:00
|
|
|
var rebuildTempFilesToRemove []string
|
|
|
|
err := b.iterateIncompletedRebuildDBPaths(ctx, func(s string) (bool, error) {
|
|
|
|
rebuildTmpFilePath := s
|
|
|
|
s = strings.TrimSuffix(s, rebuildSuffix)
|
2023-09-27 13:25:15 +00:00
|
|
|
shDB := b.getBlobovnicza(s)
|
|
|
|
blz, err := shDB.Open()
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
defer shDB.Close()
|
|
|
|
|
|
|
|
incompletedMoves, err := blz.ListMoveInfo(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, move := range incompletedMoves {
|
|
|
|
if err := b.performMove(ctx, blz, shDB.SystemPath(), move, metaStore); err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
|
2024-08-27 12:51:55 +00:00
|
|
|
rebuildTempFilesToRemove = append(rebuildTempFilesToRemove, rebuildTmpFilePath)
|
2023-09-27 13:25:15 +00:00
|
|
|
return false, nil
|
|
|
|
})
|
2024-08-27 12:51:55 +00:00
|
|
|
for _, tmp := range rebuildTempFilesToRemove {
|
|
|
|
if err := os.Remove(filepath.Join(b.rootPath, tmp)); err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczatreeFailedToRemoveRebuildTempFile, zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count, err
|
2023-09-27 13:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Blobovniczas) performMove(ctx context.Context, source *blobovnicza.Blobovnicza, sourcePath string,
|
2023-10-03 08:58:35 +00:00
|
|
|
move blobovnicza.MoveInfo, metaStore common.MetaStorage,
|
|
|
|
) error {
|
2023-09-27 13:25:15 +00:00
|
|
|
targetDB := b.getBlobovnicza(NewIDFromBytes(move.TargetStorageID).Path())
|
|
|
|
target, err := targetDB.Open()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer targetDB.Close()
|
|
|
|
|
|
|
|
existsInSource := true
|
|
|
|
var gPrm blobovnicza.GetPrm
|
|
|
|
gPrm.SetAddress(move.Address)
|
|
|
|
gRes, err := source.Get(ctx, gPrm)
|
|
|
|
if err != nil {
|
|
|
|
if client.IsErrObjectNotFound(err) {
|
|
|
|
existsInSource = false
|
|
|
|
} else {
|
|
|
|
b.log.Warn(logs.BlobovniczatreeCouldNotCheckExistenceInTargetDB, zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-03 08:58:35 +00:00
|
|
|
if !existsInSource { // object was deleted by Rebuild, need to delete move info
|
2023-09-27 13:25:15 +00:00
|
|
|
if err = source.DropMoveInfo(ctx, move.Address); err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczatreeCouldNotDropMoveInfo, zap.String("path", sourcePath), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
b.deleteProtectedObjects.Delete(move.Address)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
existsInTarget, err := target.Exists(ctx, move.Address)
|
|
|
|
if err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczatreeCouldNotCheckExistenceInTargetDB, zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !existsInTarget {
|
|
|
|
var putPrm blobovnicza.PutPrm
|
|
|
|
putPrm.SetAddress(move.Address)
|
|
|
|
putPrm.SetMarshaledObject(gRes.Object())
|
|
|
|
_, err = target.Put(ctx, putPrm)
|
|
|
|
if err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczatreeCouldNotPutObjectToTargetDB, zap.String("path", targetDB.SystemPath()), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = metaStore.UpdateStorageID(ctx, move.Address, move.TargetStorageID); err != nil {
|
2023-10-11 07:33:42 +00:00
|
|
|
b.log.Warn(logs.BlobovniczatreeCouldNotUpdateStorageID, zap.Error(err), zap.Stringer("address", move.Address))
|
2023-09-27 13:25:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var deletePrm blobovnicza.DeletePrm
|
|
|
|
deletePrm.SetAddress(move.Address)
|
|
|
|
if _, err = source.Delete(ctx, deletePrm); err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczatreeCouldNotDeleteFromSource, zap.String("path", sourcePath), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = source.DropMoveInfo(ctx, move.Address); err != nil {
|
|
|
|
b.log.Warn(logs.BlobovniczatreeCouldNotDropMoveInfo, zap.String("path", sourcePath), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
b.deleteProtectedObjects.Delete(move.Address)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type moveIterator struct {
|
|
|
|
B *Blobovniczas
|
|
|
|
ID *ID
|
|
|
|
AllFull bool
|
|
|
|
Address oid.Address
|
|
|
|
ObjectData []byte
|
|
|
|
MetaStore common.MetaStorage
|
|
|
|
Source *blobovnicza.Blobovnicza
|
|
|
|
SourceSysPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *moveIterator) tryMoveToLvl(ctx context.Context, lvlPath string) (bool, error) {
|
|
|
|
target, err := i.B.activeDBManager.GetOpenedActiveDBForLevel(lvlPath)
|
|
|
|
if err != nil {
|
|
|
|
if !isLogical(err) {
|
|
|
|
i.B.reportError(logs.BlobovniczatreeCouldNotGetActiveBlobovnicza, err)
|
|
|
|
} else {
|
|
|
|
i.B.log.Warn(logs.BlobovniczatreeCouldNotGetActiveBlobovnicza, zap.Error(err))
|
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if target == nil {
|
|
|
|
i.B.log.Warn(logs.BlobovniczatreeBlobovniczaOverflowed, zap.String("level", lvlPath))
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
defer target.Close()
|
|
|
|
|
|
|
|
i.AllFull = false
|
|
|
|
|
|
|
|
targetIDx := u64FromHexString(filepath.Base(target.SystemPath()))
|
|
|
|
targetStorageID := NewIDFromBytes([]byte(filepath.Join(lvlPath, u64ToHexString(targetIDx))))
|
|
|
|
|
|
|
|
if err = i.Source.PutMoveInfo(ctx, blobovnicza.MoveInfo{
|
|
|
|
Address: i.Address,
|
|
|
|
TargetStorageID: targetStorageID.Bytes(),
|
|
|
|
}); err != nil {
|
|
|
|
if !isLogical(err) {
|
|
|
|
i.B.reportError(logs.BlobovniczatreeCouldNotPutMoveInfoToSourceBlobovnicza, err)
|
|
|
|
} else {
|
|
|
|
i.B.log.Warn(logs.BlobovniczatreeCouldNotPutMoveInfoToSourceBlobovnicza, zap.String("path", i.SourceSysPath), zap.Error(err))
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
i.B.deleteProtectedObjects.Add(i.Address)
|
|
|
|
|
|
|
|
var putPrm blobovnicza.PutPrm
|
|
|
|
putPrm.SetAddress(i.Address)
|
|
|
|
putPrm.SetMarshaledObject(i.ObjectData)
|
2024-03-04 08:58:36 +00:00
|
|
|
putPrm.SetForce(true)
|
2023-09-27 13:25:15 +00:00
|
|
|
|
|
|
|
_, err = target.Blobovnicza().Put(ctx, putPrm)
|
|
|
|
if err != nil {
|
|
|
|
if !isLogical(err) {
|
|
|
|
i.B.reportError(logs.BlobovniczatreeCouldNotPutObjectToActiveBlobovnicza, err)
|
|
|
|
} else {
|
|
|
|
i.B.log.Warn(logs.BlobovniczatreeCouldNotPutObjectToActiveBlobovnicza, zap.String("path", target.SystemPath()), zap.Error(err))
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = i.MetaStore.UpdateStorageID(ctx, i.Address, targetStorageID.Bytes()); err != nil {
|
2023-10-11 07:33:42 +00:00
|
|
|
i.B.log.Warn(logs.BlobovniczatreeCouldNotUpdateStorageID, zap.Error(err), zap.Stringer("address", i.Address))
|
2023-09-27 13:25:15 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var deletePrm blobovnicza.DeletePrm
|
|
|
|
deletePrm.SetAddress(i.Address)
|
|
|
|
if _, err = i.Source.Delete(ctx, deletePrm); err != nil {
|
|
|
|
if !isLogical(err) {
|
|
|
|
i.B.reportError(logs.BlobovniczatreeCouldNotDeleteFromSource, err)
|
|
|
|
} else {
|
|
|
|
i.B.log.Warn(logs.BlobovniczatreeCouldNotDeleteFromSource, zap.String("path", i.SourceSysPath), zap.Error(err))
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = i.Source.DropMoveInfo(ctx, i.Address); err != nil {
|
|
|
|
if !isLogical(err) {
|
|
|
|
i.B.reportError(logs.BlobovniczatreeCouldNotDropMoveInfo, err)
|
|
|
|
} else {
|
|
|
|
i.B.log.Warn(logs.BlobovniczatreeCouldNotDropMoveInfo, zap.String("path", i.SourceSysPath), zap.Error(err))
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
i.B.deleteProtectedObjects.Delete(i.Address)
|
|
|
|
|
|
|
|
i.ID = targetStorageID
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type addressMap struct {
|
|
|
|
data map[oid.Address]struct{}
|
|
|
|
guard *sync.RWMutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func newAddressMap() *addressMap {
|
|
|
|
return &addressMap{
|
|
|
|
data: make(map[oid.Address]struct{}),
|
|
|
|
guard: &sync.RWMutex{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *addressMap) Add(address oid.Address) {
|
|
|
|
m.guard.Lock()
|
|
|
|
defer m.guard.Unlock()
|
|
|
|
|
|
|
|
m.data[address] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *addressMap) Delete(address oid.Address) {
|
|
|
|
m.guard.Lock()
|
|
|
|
defer m.guard.Unlock()
|
|
|
|
|
|
|
|
delete(m.data, address)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *addressMap) Contains(address oid.Address) bool {
|
|
|
|
m.guard.RLock()
|
|
|
|
defer m.guard.RUnlock()
|
|
|
|
|
|
|
|
_, contains := m.data[address]
|
|
|
|
return contains
|
|
|
|
}
|