| index 9885ddd8b..fab2fbacc 100644 |
| --- a/internal/host/movesfileslive_test.go |
| +++ b/internal/host/movesfileslive_test.go |
| @@ -15,6 +15,7 @@ import ( |
| "github.com/carlosframework/platform/internal/lease" |
| "github.com/carlosframework/platform/internal/park" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| ) |
| |
| // The files live set (J2/F4, Paul's #236 ruling; M10): every moves park |
| @@ -249,6 +250,147 @@ func TestReturnResidueParkKeepsTheFilesLiveSet(t *testing.T) { |
| } |
| } |
| |
| +// TestRestoringKeepsTheSourcesFilesLiveSetUntilTheReturn (J2/F4; L18 joint |
| +// round, finding 1): a park of an older source generation is queued in the |
| +// source's region before the target's probe is admitted; then the target is |
| +// admitted and the landing is rolled back. While the target releases |
| +// (restoring/releasing, released) the newest admission is the target's, but |
| +// a clean return restores the source's retained generation, so seen from the |
| +// source's region the source stays authoritative: its marker and files pins |
| +// hold, the chore is refused and nothing the retained manifest names is |
| +// retired. A dirty release is protected the same way (a declared loss turns |
| +// it clean). The target's region still names the target. From the return CAS |
| +// on the newest admission decides, as before: a clean return is admitted in |
| +// the source, and a dirty one names the target until the source's probe is |
| +// admitted, so the source pins nothing and the chore parks the pre-move |
| +// generation (D6). |
| +func TestRestoringKeepsTheSourcesFilesLiveSetUntilTheReturn(t *testing.T) { |
| + for _, dirty := range []bool{false, true} { |
| + t.Run(fmt.Sprintf("dirty %v", dirty), func(t *testing.T) { |
| + ctx := t.Context() |
| + f := newVwFixture(t) |
| + markerVer, snapshot := f.marker(t, "cur", f.inc) |
| + snapKey := f.location + "/g-cur/0009/0000000000000001-0000000000000005.ltx" |
| + old := map[string]string{} |
| + for _, k := range []string{f.location + "/files/g-old/objects/0000000000000001-aa", f.location + "/g-old/0000/db"} { |
| + old[k] = f.bucket.Put("data", k, []byte("old")) |
| + } |
| + named := f.location + "/files/g-old/objects/0000000000000001-aa" |
| + filesManifest(t, func(k string, b []byte) { f.bucket.Put("data", k, b) }, f.location, "cur", "a.txt="+named) |
| + f.move(provision.MoveLanding) |
| + |
| + // The chore, queued in the source's region at landing, before |
| + // the target's probe is admitted. |
| + claims := release.NewDirStore(t.TempDir()) |
| + chore := hostclaim.Obligation{ID: "park-old", Op: vwMove, Kind: "park-generation", Region: "ie", Owner: "region:ie", Generation: "old", Retirement: "ret-1", |
| + Park: &hostclaim.ParkScope{Location: f.location, Incarnation: f.inc, EvidenceAt: evAt, RequestLimit: hostbox.RequestLimit}} |
| + update := func(step func(*hostclaim.Claim) error) { |
| + t.Helper() |
| + obs, err := hostclaim.Read(ctx, claims, vwHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := hostclaim.Update(ctx, claims, obs, step); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + update(func(c *hostclaim.Claim) error { |
| + c.Host, c.Holder = vwHost, f.holder("cur", "cur@ie") |
| + c.Op = hostclaim.Op{Kind: hostclaim.KindLanding, ID: vwMove, Phase: provision.LandProbing, Exec: "uk-box", Participants: []string{"ie-box", "uk-box"}, |
| + Intent: map[string]string{"source": "ie-box", "target": "uk-box", "from": "ie", "to": "uk"}, |
| + Journal: map[string]string{hostclaim.JournalSourceStamp: "3", hostclaim.JournalSrcGen: "cur"}} |
| + c.Obligations = []hostclaim.Obligation{chore} |
| + return nil |
| + }) |
| + // The target's probe's admission, then the rollback. |
| + update(func(c *hostclaim.Claim) error { |
| + c.Holder.Admissions = append(c.Holder.Admissions, hostclaim.AdmissionRecord{Session: 2, Box: "uk-box", Generation: vwMove, Predecessor: "cur", Mode: "cold", Region: "uk", PredecessorRegion: "ie"}) |
| + c.Holder.Generation = vwMove |
| + return nil |
| + }) |
| + f.rec.Move.State = provision.MoveRollingBack |
| + f.rec.Move.Rollback = &provision.MoveRollback{ID: vwRb, TargetPhase: provision.RbTargetReleasing} |
| + update(hostclaim.RollBack(vwMove, vwRb)) |
| + |
| + seq := 0 |
| + engine := park.Engine{Store: f.bucket, Claims: claims, Bucket: "data", Region: "ie", Leases: evLeases{}, Now: func() time.Time { return evNow }, |
| + NewID: func() string { seq++; return fmt.Sprintf("id%d", seq) }, View: f.view("ie"), Authorize: allowParkAuthorize} |
| + observe := func() hostclaim.Observed { |
| + t.Helper() |
| + obs, err := hostclaim.Read(ctx, claims, vwHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return obs |
| + } |
| + intact := func() bool { |
| + for k, ver := range old { |
| + if _, ok := f.bucket.Current("data", k); !ok || f.bucket.LatestID("data", k) != ver { |
| + return false |
| + } |
| + } |
| + return true |
| + } |
| + protectedOnSource := func(when string) { |
| + t.Helper() |
| + if err := engine.Run(ctx, park.Work{Host: vwHost, ID: chore.ID, Op: vwMove}); !errors.Is(err, park.ErrUnsafe) { |
| + t.Fatalf("%s: the source's park of a generation its retained manifest names: %v", when, err) |
| + } |
| + if !intact() { |
| + t.Fatalf("%s: an object the retained manifest names was retired", when) |
| + } |
| + v, err := f.view("ie")(ctx, observe()) |
| + if err != nil { |
| + t.Fatalf("%s: the source's view: %v", when, err) |
| + } |
| + if v.AuthoritativeRegion != "ie" || v.MarkerGeneration != "cur" || v.Marker != (park.Ref{Key: f.location + "/generation.json", VersionID: markerVer}) || |
| + !v.Pinned[park.Ref{Key: named, VersionID: old[named]}] || !v.Pinned[park.Ref{Key: snapKey, VersionID: snapshot}] { |
| + t.Fatalf("%s: the source's view %+v", when, v) |
| + } |
| + } |
| + targetView := func(when, want string) { |
| + t.Helper() |
| + if v, err := f.view("uk")(ctx, observe()); err != nil || v.AuthoritativeRegion != want { |
| + t.Fatalf("%s: the target's view %+v, %v; want %s", when, v, err, want) |
| + } |
| + } |
| + |
| + protectedOnSource("releasing") |
| + targetView("releasing", "uk") |
| + |
| + f.rec.Move.Rollback.TargetPhase, f.rec.Move.Rollback.Dirty = provision.RbTargetReleased, dirty |
| + update(hostclaim.TargetReleased(vwMove, "uk-box", "uk", "stopped-target", hostclaim.ParkScope{Location: f.location, Incarnation: f.inc, EvidenceAt: evAt, RequestLimit: hostbox.RequestLimit}, |
| + func() string { seq++; return fmt.Sprintf("id%d", seq) })) |
| + if op := observe().Claim.Op; op.Phase != hostclaim.PhaseReleased || op.Exec != "" { |
| + t.Fatalf("the release: %+v", op) |
| + } |
| + protectedOnSource("released") |
| + targetView("released", "uk") |
| + |
| + // The source's return CAS. |
| + update(hostclaim.ReturnToSource(vwMove, "ie-box", !dirty, hostclaim.ReturnFence{})) |
| + if !dirty { |
| + protectedOnSource("after the clean return") |
| + targetView("after the clean return", "ie") |
| + return |
| + } |
| + v, err := f.view("ie")(ctx, observe()) |
| + if err != nil || v.AuthoritativeRegion != "uk" || len(v.Pinned) != 0 || v.MarkerKnown { |
| + t.Fatalf("after the dirty return the source's view %+v, %v", v, err) |
| + } |
| + targetView("after the dirty return", "uk") |
| + if err := engine.Run(ctx, park.Work{Host: vwHost, ID: chore.ID, Op: vwMove}); err != nil && !errors.Is(err, park.ErrPending) { |
| + t.Fatalf("the dirty return's park of the pre-move generation: %v", err) |
| + } |
| + for k := range old { |
| + if _, ok := f.bucket.Current("data", k); ok { |
| + t.Fatalf("%s was not parked after the dirty return", k) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| // TestFilesLiveSetFollowsTheLiveChain (fix round 1, I2): with the marker |
| // lagging, park.protected treats the whole unfinished chain g3 -> g2 -> g1 |
| // as live, and the view reads every one of those generations' manifests. An |