feat: add restore hash & size check

This commit is contained in:
Samuel N Cui
2023-09-22 23:54:56 +08:00
parent ede138317f
commit f59f0b81a6
15 changed files with 130 additions and 85 deletions

View File

@@ -74,7 +74,7 @@ type jobArchiveExecutor struct {
func (a *jobArchiveExecutor) submit(ctx context.Context, param *entity.JobArchiveNextParam) {
if err := a.handle(ctx, param); err != nil {
a.logger.WithContext(ctx).Infof("handler param fail, err= %w", err)
a.logger.WithContext(ctx).WithError(err).Infof("handler param fail, param= %s", param)
}
}

View File

@@ -2,6 +2,7 @@ package executor
import (
"context"
"encoding/hex"
"fmt"
"io"
"os"
@@ -74,7 +75,7 @@ type jobRestoreExecutor struct {
func (a *jobRestoreExecutor) submit(ctx context.Context, param *entity.JobRestoreNextParam) {
if err := a.handle(ctx, param); err != nil {
a.logger.WithContext(ctx).Infof("handler param fail, err= %w", err)
a.logger.WithContext(ctx).WithError(err).Infof("handler param fail, param= %s", param)
}
}
@@ -289,11 +290,31 @@ func (a *jobRestoreExecutor) restoreTape(ctx context.Context, device string) (re
)
return
}
targetFile.Status = targetStatus
if targetStatus == entity.CopyStatus_STAGED {
if targetHash := hex.EncodeToString(targetFile.Hash); targetHash != job.SHA256 {
targetStatus = entity.CopyStatus_FAILED
a.logger.Warnf(
"copy checksum do not match target file hash, real_path= %s target_hash= %s copy_hash= %s",
realPath, targetHash, job.SHA256,
)
}
if targetSize := targetFile.Size; targetSize != job.Size {
targetStatus = entity.CopyStatus_FAILED
a.logger.Warnf(
"copy size do not match target file hash, real_path= %s target_size= %d copy_size= %d",
realPath, targetSize, job.Size,
)
}
}
targetFile.Status = targetStatus
if _, err := a.exe.SaveJob(ctx, a.job); err != nil {
a.logger.WithContext(ctx).Infof("save job for update file fail, name= %s", job.Base+path.Join(job.Path...))
}
return
}
}))

View File

@@ -120,6 +120,7 @@ func (e *Executor) createRestore(ctx context.Context, job *Job, param *entity.Jo
PositionId: p.ID,
Status: entity.CopyStatus_PENDING,
Size: file.Size,
Hash: file.Hash,
TapePath: p.Path,
TargetPath: file.target,
})