mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
fix(sw-block): volume restore reports the typed restore_source_not_own
A restore whose source is itself a restore target now names the master's typed reason, as the page says, instead of the generic not_admitted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27be7892a8
commit
a7305caa4e
2 files changed
+17
-1
No files matched your search
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user