diff --git a/seaweed-block/cmd/sw-block/volume_backup.go b/seaweed-block/cmd/sw-block/volume_backup.go index 8dbd3230b5..8d75f2d4ad 100644 --- a/seaweed-block/cmd/sw-block/volume_backup.go +++ b/seaweed-block/cmd/sw-block/volume_backup.go @@ -19,6 +19,7 @@ import ( "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" "github.com/seaweedfs/seaweed-block/core/ops" "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/rpc/lifecycleclient" "github.com/seaweedfs/seaweed-block/core/rpc/link" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -441,6 +442,9 @@ var ( // restoreRefusal maps a refused restore create to its JSON code (the codes // ops chunk restore reports); "" for an outcome a re-run may change. func restoreRefusal(err error) string { + if lifecycleclient.Reason(err) == lifecycleclient.ReasonRestoreSourceNotOwn { + return "restore_source_not_own" + } switch status.Code(err) { case codes.NotFound: return "snapshot_not_found" diff --git a/seaweed-block/cmd/sw-block/volume_backup_test.go b/seaweed-block/cmd/sw-block/volume_backup_test.go index d0ac121bf6..f1363eadae 100644 --- a/seaweed-block/cmd/sw-block/volume_backup_test.go +++ b/seaweed-block/cmd/sw-block/volume_backup_test.go @@ -20,6 +20,7 @@ import ( "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore" "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/rpc/lifecycleclient" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -130,6 +131,9 @@ func (m *restoreMaster) CreateVolume(ctx context.Context, q *control.CreateVolum m.mu.Lock() defer m.mu.Unlock() m.creates++ + if q.GetSourceVolume() == "vol-t" { // a restore target's snapshot names another volume's chunks + return nil, lifecycleclient.WithReason(status.New(codes.FailedPrecondition, "restore target: the snapshot names another volume's chunks"), lifecycleclient.ReasonRestoreSourceNotOwn).Err() + } if q.GetSourceVolume() != "vol-a" { return nil, status.Error(codes.FailedPrecondition, "source is not this cluster's") } @@ -687,6 +691,14 @@ func TestVolumeRestoreRefusals(t *testing.T) { t.Errorf("%s: %d %s", c.name, code, errs) } } + // A source that is itself a restore target: the master's typed reason. + sourceT := filepath.Join(env.EtcDir, "vol-t.env") + if raw, err := os.ReadFile(filepath.Join(env.EtcDir, "vol-a.env")); err != nil || os.WriteFile(sourceT, raw, 0o640) != nil { + t.Fatal(err) + } + if code, _, errs := runRestore(env, append([]string{"vol-t"}, restoreArgs(h)[1:]...)...); code != 2 || !strings.Contains(errs, "restore_source_not_own") { + t.Errorf("restore target as source: %d %s", code, errs) + } m.vols["vol-r"] = &restoreRec{source: "vol-a", snap: "s1", req: "another", ready: true} if code, _, errs := runRestore(env, restoreArgs(h)...); code != 2 || !strings.Contains(errs, "target_exists") { t.Errorf("target of another request: %d %s", code, errs) @@ -696,7 +708,7 @@ func TestVolumeRestoreRefusals(t *testing.T) { if code, _, errs := runRestore(env, restoreArgs(h)...); code != 2 || !strings.Contains(errs, "is walstore") { t.Errorf("walstore source: %d %s", code, errs) } - if m.creates != 2 { + if m.creates != 3 { t.Errorf("creates %d: refusals before the master must not reach it", m.creates) } }