forked from TrueCloudLab/frostfs-node
[#1337] blobovniczatree: Add .rebuild temp files
This allows to reduce open/close DBs to check incompleted rebuilds. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
f652518c24
commit
007827255e
6 changed files with 71 additions and 9 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
@ -19,6 +20,8 @@ import (
|
|||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
const rebuildSuffix = ".rebuild"
|
||||
|
||||
var (
|
||||
errRebuildInProgress = errors.New("rebuild is in progress, the operation cannot be performed")
|
||||
errBatchFull = errors.New("batch full")
|
||||
|
@ -124,15 +127,36 @@ func (b *Blobovniczas) rebuildDB(ctx context.Context, path string, meta common.M
|
|||
}
|
||||
shDB.Close()
|
||||
}()
|
||||
|
||||
dropTempFile, err := b.addRebuildTempFile(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
migratedObjects, err := b.moveObjects(ctx, blz, shDB.SystemPath(), meta, limiter)
|
||||
if err != nil {
|
||||
return migratedObjects, err
|
||||
}
|
||||
shDBClosed, err = b.dropDB(ctx, path, shDB)
|
||||
if err == nil {
|
||||
// drop only on success to continue rebuild on error
|
||||
dropTempFile()
|
||||
}
|
||||
return migratedObjects, err
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -256,7 +280,10 @@ func (b *Blobovniczas) dropDirectoryIfEmpty(path string) error {
|
|||
|
||||
func (b *Blobovniczas) completeIncompletedMove(ctx context.Context, metaStore common.MetaStorage) (uint64, error) {
|
||||
var count uint64
|
||||
return count, b.iterateExistingDBPaths(ctx, func(s string) (bool, error) {
|
||||
var rebuildTempFilesToRemove []string
|
||||
err := b.iterateIncompletedRebuildDBPaths(ctx, func(s string) (bool, error) {
|
||||
rebuildTmpFilePath := s
|
||||
s = strings.TrimSuffix(s, rebuildSuffix)
|
||||
shDB := b.getBlobovnicza(s)
|
||||
blz, err := shDB.Open()
|
||||
if err != nil {
|
||||
|
@ -276,8 +303,15 @@ func (b *Blobovniczas) completeIncompletedMove(ctx context.Context, metaStore co
|
|||
count++
|
||||
}
|
||||
|
||||
rebuildTempFilesToRemove = append(rebuildTempFilesToRemove, rebuildTmpFilePath)
|
||||
return false, nil
|
||||
})
|
||||
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
|
||||
}
|
||||
|
||||
func (b *Blobovniczas) performMove(ctx context.Context, source *blobovnicza.Blobovnicza, sourcePath string,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue