Skip to content

Commit

Permalink
fix: large file make ltfs into readonly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelncui committed Sep 27, 2023
1 parent 2341515 commit a6c7820
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 54 deletions.
2 changes: 1 addition & 1 deletion cmd/lto-info/cm.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func cmDensityFriendly(d int) (string, SpecsType) {
specs = SpecsType{true, 12000, 30000, 360, 900, 60*9 + 16, "2.5:1", true, true, 4, 4, 52, 32}
case 0x60: /* guessed, to check FIXME */
friendlyName = "LTO-9"
specs = SpecsType{true, 18000, 45000, 400, 1000, 60*12 + 30, "2.5:1", true, true, 4, 0, 0, 0} /* FIXME */
specs = SpecsType{true, 18000, 45000, 400, 1000, 60*12 + 30, "2.5:1", true, true, 4, 0, 0, 32} /* FIXME */
}
return friendlyName, specs
}
Expand Down
48 changes: 43 additions & 5 deletions executor/job_archive_exe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package executor
import (
"context"
"encoding/hex"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -188,6 +189,7 @@ func (a *jobArchiveExecutor) makeTape(ctx context.Context, device, barcode, name
a.progress = newProgress()
defer func() { a.progress = nil }()

var dropToReadonly bool
opts = append(opts, acp.WithEventHandler(func(ev acp.Event) {
switch e := ev.(type) {
case *acp.EventUpdateCount:
Expand All @@ -207,19 +209,30 @@ func (a *jobArchiveExecutor) makeTape(ctx context.Context, device, barcode, name

var targetStatus entity.CopyStatus
switch job.Status {
case "pending":
case acp.JobStatusPending, acp.JobStatusPreparing:
targetStatus = entity.CopyStatus_PENDING
case "preparing":
case acp.JobStatusCopying:
targetStatus = entity.CopyStatus_RUNNING
case "finished":
a.logger.WithContext(ctx).Infof("file '%s' copy finished, size= %d", src.RealPath(), job.Size)
targetStatus = entity.CopyStatus_STAGED
case acp.JobStatusFinished:
targetStatus = entity.CopyStatus_FAILED
if len(job.SuccessTargets) > 0 {
a.logger.WithContext(ctx).Infof("file '%s' copy success, size= %d", src.RealPath(), job.Size)
targetStatus = entity.CopyStatus_STAGED
break // break from switch
}

for dst, err := range job.FailTargets {
if err == nil {
continue
}
if errors.Is(err, acp.ErrTargetNoSpace) {
continue
}

a.logger.WithContext(ctx).WithError(err).Errorf("file '%s' copy fail, dst= '%s'", src.RealPath(), dst)
if errors.Is(err, acp.ErrTargetDropToReadonly) {
dropToReadonly = true
}
}
default:
return
Expand Down Expand Up @@ -254,6 +267,14 @@ func (a *jobArchiveExecutor) makeTape(ctx context.Context, device, barcode, name
defer func() {
ctx := tools.WithoutTimeout(ctx)

// if tape drop to readonly, ltfs cannot write index to partition a.
// rollback sources for next try.
if dropToReadonly {
a.logger.WithContext(ctx).Errorf("tape filesystem had droped to readonly, rollback, barcode= '%s'", barcode)
a.rollbackSources(ctx)
return
}

report := reportGetter()
sort.Slice(report.Jobs, func(i, j int) bool {
return entity.NewSourceFromACPJob(report.Jobs[i]).Compare(entity.NewSourceFromACPJob(report.Jobs[j])) < 0
Expand Down Expand Up @@ -373,6 +394,23 @@ func (a *jobArchiveExecutor) markSourcesAsSubmited(ctx context.Context, jobs []*
return nil
}

func (a *jobArchiveExecutor) rollbackSources(ctx context.Context) error {
a.stateLock.Lock()
defer a.stateLock.Unlock()

for _, source := range a.state.Sources {
if source.Status == entity.CopyStatus_SUBMITED {
continue
}
source.Status = entity.CopyStatus_PENDING
}

if _, err := a.exe.SaveJob(ctx, a.job); err != nil {
return fmt.Errorf("mark sources as submited, save job, %w", err)
}
return nil
}

func (a *jobArchiveExecutor) getTodoSources() int {
a.stateLock.Lock()
defer a.stateLock.Unlock()
Expand Down
25 changes: 12 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ go 1.20

require (
github.com/HewlettPackard/structex v1.0.4
github.com/aws/aws-sdk-go v1.44.118
github.com/benmcclelland/mtio v0.0.0-20170506231306-f929531fb4fe
github.com/benmcclelland/sgio v0.0.0-20180629175614-f710aebf64c1
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set/v2 v2.1.0
github.com/deckarep/golang-set/v2 v2.3.1
github.com/gin-gonic/gin v1.9.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.5
github.com/hashicorp/go-multierror v1.1.1
Expand All @@ -19,8 +18,8 @@ require (
github.com/modern-go/reflect2 v1.0.2
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/samber/lo v1.38.1
github.com/samuelncui/acp v0.0.0-20230922160619-0d364575f621
github.com/sirupsen/logrus v1.9.0
github.com/samuelncui/acp v0.0.0-20230927101214-786cd32f8d38
github.com/sirupsen/logrus v1.9.3
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.30.0
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -44,31 +43,31 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.11.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.2 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-sqlite3 v1.14.12 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/schollz/progressbar/v3 v3.12.2 // indirect
github.com/samuelncui/godf v0.0.0-20230927093204-37ea5acb9fc1 // indirect
github.com/schollz/progressbar/v3 v3.13.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit a6c7820

Please sign in to comment.