carlos / platform Public

region-ha p1b-2: the view does not age edges files (their generation moves only on a rewrite)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev fdad2fd622214f354c21487153d5f18573560df4 parent feb9739
3 files changed, +19 −29
  • internal/edge/holderview.go +9 −19
  • internal/edge/holderview_test.go +5 −4
  • internal/edge/homemap.go +5 −6
diff --git a/internal/edge/holderview.go b/internal/edge/holderview.go
index 4260475e1..204bcabdf 100644
--- a/internal/edge/holderview.go
+++ b/internal/edge/holderview.go
@@ -3,36 +3,33 @@ package edge
import (
"time"
- "github.com/carlosframework/platform/internal/boxchoice"
"github.com/carlosframework/platform/internal/edgesfile"
)
-// holderMaxSkew is how far in the future a file's generation may be before it
-// is not believed: box clocks are synchronised, not equal. boxchoice's own
-// bound, which that package keeps unexported.
-const holderMaxSkew = time.Minute
-
// boxInView reports whether the box labelled ref is a valid forward target for
// this box at now, and the address to dial it at.
//
// "In view" is the edge's half of region HA forwarding: ref is another box in
// this box's own region and placement, writing to the same data store with the
-// same secrets key, whose edges file is current. The test is made on the fold's
-// own files, so it is as fresh as the last poll and needs no request to the
-// bucket. Every rule fails closed: a file this build cannot read a field from
+// same secrets key. The test is made on the fold's own files, so it needs no
+// request to the bucket. It does not age the file: a file's generation moves
+// only when the file is rewritten, and the writer skips unchanged rewrites, so
+// a healthy box's generation is arbitrarily old. Liveness comes from the
+// caller, which names a holder only by an unexpired lease or the platform's
+// header, and drops one that fails the dial. Every rule fails closed: a file this build cannot read a field from
// is out of view, and with no file of this box's own there is nothing to
// compare against, so nothing is in view.
//
// - ref is not this box (a box never forwards to itself);
-// - its generation is no older than boxchoice.MaxEdgesAge and no more than
-// holderMaxSkew in the future;
// - its region and placement equal this box's own file's;
// - its data bucket is non-empty and equals this box's;
// - its secrets key fingerprint equals this box's. Both empty is equal: a
// deployment with no key. One empty is a mismatch.
//
// dial is edgesfile.Reader.Dial for the file, built as foldHomes builds its
-// reader: this box's own file as Self and this edge's region HA switch.
+// reader: this box's own file as Self and this edge's region HA switch. A box
+// whose file offers no dialable address is out. now is unused; the signature
+// is the one the forwarding callers are written against.
func (m *homeMap) boxInView(ref string, now time.Time) (dial string, ok bool) {
if ref == "" || m.self == "" || ref == m.self {
return "", false
@@ -50,13 +47,6 @@ func (m *homeMap) boxInView(ref string, now time.Time) (dial string, ok bool) {
if !ownKnown || !peerKnown {
return "", false
}
- at, err := time.Parse(time.RFC3339, peer.Generation)
- if err != nil {
- return "", false
- }
- if age := now.Sub(at); age > boxchoice.MaxEdgesAge || age < -holderMaxSkew {
- return "", false
- }
if peer.Region != own.Region || peer.Placement != own.Placement {
return "", false
}
diff --git a/internal/edge/holderview_test.go b/internal/edge/holderview_test.go
index ccbb32716..0f2de8d66 100644
--- a/internal/edge/holderview_test.go
+++ b/internal/edge/holderview_test.go
@@ -36,16 +36,17 @@ func TestHolderViewRules(t *testing.T) {
own := viewFile("a", "ie", "p", now, "bkt", "fp1")
peers := []peer{
{"fresh", viewFile("b", "ie", "p", now.Add(-time.Minute), "bkt", "fp1"), true},
- {"old", viewFile("c", "ie", "p", now.Add(-16*time.Minute), "bkt", "fp1"), false},
- {"future", viewFile("d", "ie", "p", now.Add(2*time.Minute), "bkt", "fp1"), false},
+ // A generation moves only when the file is rewritten, so a healthy
+ // box's is arbitrarily old: the view does not age files.
+ {"old", viewFile("c", "ie", "p", now.Add(-12*time.Hour), "bkt", "fp1"), true},
{"region", viewFile("e", "uk", "p", now, "bkt", "fp1"), false},
{"placement", viewFile("f", "ie", "q", now, "bkt", "fp1"), false},
{"nobucket", viewFile("g", "ie", "p", now, "", "fp1"), false},
{"bucket", viewFile("h", "ie", "p", now, "other", "fp1"), false},
{"fp", viewFile("i", "ie", "p", now, "bkt", "fp2"), false},
{"emptyfp", viewFile("j", "ie", "p", now, "bkt", ""), false},
- {"nogen", `{"v":1,"box":"k","eip":"1.2.3.4","region":"ie","placement":"p","data_bucket":"bkt","secrets_key_fp":"fp1","hosts":{}}`, false},
- {"badgen", `{"v":1,"box":"l","eip":"1.2.3.4","region":"ie","placement":"p","generation":"yesterday","data_bucket":"bkt","secrets_key_fp":"fp1","hosts":{}}`, false},
+ {"nogen", `{"v":1,"box":"k","eip":"1.2.3.4","region":"ie","placement":"p","data_bucket":"bkt","secrets_key_fp":"fp1","hosts":{}}`, true},
+ {"badgen", `{"v":1,"box":"l","eip":"1.2.3.4","region":"ie","placement":"p","generation":"yesterday","data_bucket":"bkt","secrets_key_fp":"fp1","hosts":{}}`, true},
}
s := meshTestStore(t)
putJSON(t, s, "control/edges/a.json", own)
diff --git a/internal/edge/homemap.go b/internal/edge/homemap.go
index e9e0bc001..829b82bdf 100644
--- a/internal/edge/homemap.go
+++ b/internal/edge/homemap.go
@@ -143,12 +143,11 @@ type edgesFileView struct {
PrivateCIDR string `json:"private_cidr"`
Region string `json:"region"`
Placement string `json:"placement"`
- // Generation, DataBucket and SecretsKeyFP are what the holder view reads
- // (holderview.go): when the box last wrote the file (RFC 3339), its data
- // bucket, and the fingerprint of its secrets key. The writer's names
- // (internal/edgesfile snapshot.go); absent from an older writer, and a
- // file without them is then never in view.
- Generation string `json:"generation"`
+ // DataBucket and SecretsKeyFP are what the holder view reads
+ // (holderview.go): the box's data bucket and the fingerprint of its
+ // secrets key. The writer's names (internal/edgesfile snapshot.go);
+ // absent from an older writer, and a file without a bucket is then
+ // never in view.
DataBucket string `json:"data_bucket"`
SecretsKeyFP string `json:"secrets_key_fp"`
}