carlos / platform Public

Merge remote-tracking branch 'origin/main' into settings-5-surfaces

claude agent, operated by paul@keymail.dev e87d73d6ae6d6300c65ef54cefeaeb69f135d83a parent 86329f0parent 650e615
2 files changed, +163 −0
  • internal/host/movesfileslive_test.go +142 −0
  • internal/host/movessources.go +21 −0
diff --git a/internal/host/movesfileslive_test.go b/internal/host/movesfileslive_test.go
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
diff --git a/internal/host/movessources.go b/internal/host/movessources.go
index 73c975bbc..7dcae6483 100644
--- a/internal/host/movessources.go
+++ b/internal/host/movessources.go
@@ -395,6 +395,12 @@ func readMarker(ctx context.Context, data genselect.Reader, bucket, host, locati
// the source's or the target's (a clean return's CAS names the source's
// generation again, a dirty return keeps the target's until the source's
// probe is admitted); no admission is the source's pre-move generation.
+// Seen from the source's own region, the source stays authoritative
+// while the target releases (releasing, released), until the source's
+// return (J2/F4, L18 finding 1: a clean return restores the source's
+// retained generation, so its files live set stays protected there).
+// A dirty return's install parks the pre-move generations (D6), so
+// from its return CAS on the newest admission decides again.
//
// For a move kind the record must carry the op's move, or have closed it
// (the record-first close, M4), when the newest admission decides alone. A
@@ -493,6 +499,21 @@ func movesAuthoritative(ctx context.Context, records MovesRecordReader, obs host
return "", err
}
if known {
+ returned := c.Op.Phase != hostclaim.PhaseReleasing && c.Op.Phase != hostclaim.PhaseReleased
+ if park.SameRegion(c.Op.Intent["home_region"], admitted, to) && park.SameRegion(c.Op.Intent["home_region"], region, from) && !returned {
+ // J2/F4 (Paul's #236 ruling; L18 finding 1): the
+ // newest admission is still the target's, but until
+ // the source takes the host back a clean return may
+ // name the source's retained generation again (a
+ // dirty release declared lost becomes clean,
+ // MoveRollbackLossCommitted), so seen from the
+ // source's region the source stays authoritative, as
+ // at landing before the commit. Once the return is
+ // written, a clean one is admitted in the source
+ // already, and a dirty one's install parks the
+ // pre-move generations (D6).
+ return from, nil
+ }
return admitted, nil
}
return from, nil