pacman keeps one mirror list for the mesh, ranked in the write that opens each round and written by every node (ADR 0585, issue 1876)
Each node's reflector ranked its own list on its own timer, and on 2026-10-31 one node's lagging first mirror left it a Node.js version behind the rest. The list is now the module's state mirrors, key list: the node that opens a week's round ranks it with the module's reflector options, keeps only mirrors whose last sync is no older than the newest found, and the round's key names the list's revision. Every keeper writes /etc/pacman.d/mirrorlist whole from the key through the root helper's new verb mirrorlist, when the key changes and when the file differs, and never writes an empty or unreadable list. reflector.timer is declared stopped and disabled, and reflector.conf saves nothing. pacman_mirrors answers the shared list, its ranker and age and whether this node's file matches; with refresh it asks this node's keeper to rank again, refused while a round runs, naming it. The round's integration test proves the opening write and both nodes' files. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
This commit is contained in:
@@ -118,8 +118,26 @@ func roundNodeOf(s *fakeStore, round, node string) RoundNode {
|
||||
|
||||
// 1841/AC6 through the keeper's loop: the first of the order opens the week's round at its start on Saturday
|
||||
// 04:00 and starts its run in it; the round's parts get the operator channel's reader and the rounds state.
|
||||
//
|
||||
// ADR 0585 §2, §3: it ranks the mesh's mirrors inside the write that opens the round, before the round's key, which names
|
||||
// the list's revision; and its keeper writes the list to its node's file.
|
||||
func TestTheFirstNodesKeeperOpensTheRoundAndTakesItsTurn(t *testing.T) {
|
||||
k, states, _ := roundKeeper(t, "node-a", []string{"node-a", "node-b"})
|
||||
root := &fakeRoot{}
|
||||
k.Root = root
|
||||
servers := []string{"https://nl.mirror.example/archlinux/$repo/os/$arch"}
|
||||
k.Rank = func(conf []byte, round string) (MirrorList, error) {
|
||||
if string(conf) != "--sort rate\n" {
|
||||
t.Errorf("ranked with %q", conf)
|
||||
}
|
||||
return MirrorList{Servers: servers, RankedAt: t0, RankedBy: "node-a", Round: round}, nil
|
||||
}
|
||||
k.Machine.ReadFile = func(path string) ([]byte, error) {
|
||||
if path == ReflectorConf {
|
||||
return []byte("--sort rate\n"), nil
|
||||
}
|
||||
return nil, errNoFile
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go func() { _ = k.Run(ctx) }()
|
||||
@@ -130,6 +148,14 @@ func TestTheFirstNodesKeeperOpensTheRoundAndTakesItsTurn(t *testing.T) {
|
||||
if rn := roundNodeOf(rounds, round, "node-b"); rn.Run != "" {
|
||||
t.Errorf("node-b started in node-a's keeper: %+v", rn)
|
||||
}
|
||||
var opened Round
|
||||
e, _ := rounds.Get(round)
|
||||
_ = json.Unmarshal(e.Value, &opened)
|
||||
list, rev, err := readMirrorList(states.store(StateMirrors))
|
||||
if err != nil || list == nil || list.Round != round || opened.Mirrors != rev || rev == 0 || opened.MirrorsNote != "" {
|
||||
t.Errorf("the round opened with mirrors %d (%q), the list is %+v at %d (%v)", opened.Mirrors, opened.MirrorsNote, list, rev, err)
|
||||
}
|
||||
until(t, "the list written to the node's file", func() bool { w := root.written(); return len(w) == 1 && w[0][0] == servers[0] })
|
||||
}
|
||||
|
||||
// 1841/AC6 through the keeper's loop: a node waits until the node before it passed its check, and starts on
|
||||
@@ -169,4 +195,64 @@ func TestTheKeeperHandsTheOperatorChannelsReaderToTheRound(t *testing.T) {
|
||||
if len(h.Wakes) < 2 {
|
||||
t.Fatalf("no wake for the round: %d wakes", len(h.Wakes))
|
||||
}
|
||||
// ADR 0585 §3: the node's file is written from the shared list when they differ, and never from a list that is empty
|
||||
// or unreadable; the file is written again when it differs (the watch's MirrorsRewritten).
|
||||
if len(h.MirrorsRewritten) != 1 {
|
||||
t.Fatalf("the mirror list file is not written again when it changes: %d hooks", len(h.MirrorsRewritten))
|
||||
}
|
||||
root := &fakeRoot{}
|
||||
u := k.upgrades
|
||||
u.Root = root
|
||||
file := []byte(nil)
|
||||
u.Machine.ReadFile = func(path string) ([]byte, error) {
|
||||
if path == Mirrorlist && file != nil {
|
||||
return file, nil
|
||||
}
|
||||
return nil, errNoFile
|
||||
}
|
||||
mirrors := states.store(StateMirrors)
|
||||
good := []string{"https://a.example/$repo/os/$arch", "https://b.example/archlinux/$repo/os/$arch"}
|
||||
for _, step := range []struct {
|
||||
name string
|
||||
put any
|
||||
file []byte
|
||||
wrote bool
|
||||
failed bool
|
||||
}{
|
||||
{name: "no shared list yet writes nothing"},
|
||||
{name: "an empty list is never written", put: MirrorList{Servers: []string{}}, failed: true},
|
||||
{name: "an unreadable list is never written", put: "not a list", failed: true},
|
||||
{name: "a list the file differs from is written whole", put: MirrorList{Servers: good}, file: []byte(mirrorlistReflector), wrote: true},
|
||||
{name: "a file holding the list is not written again", put: MirrorList{Servers: good}, file: RenderMirrorlist(good)},
|
||||
} {
|
||||
if step.put != nil {
|
||||
mirrors.Put(MirrorsKey, step.put)
|
||||
}
|
||||
file = step.file
|
||||
before := len(root.written())
|
||||
wrote, err := u.WriteMirrors()
|
||||
if wrote != step.wrote || (err != nil) != step.failed || len(root.written()) != before+map[bool]int{true: 1}[step.wrote] {
|
||||
t.Errorf("%s: wrote %v (%v), the root helper wrote %v", step.name, wrote, err, root.written())
|
||||
}
|
||||
}
|
||||
// ADR 0585 §4: a refresh asked of the keeper is refused while a round runs, and ranks the list when none does; the
|
||||
// ask is taken once either way.
|
||||
asks, rounds := states.store(StateAsks), states.store(StateRounds)
|
||||
ranked := 0
|
||||
u.Rank = func([]byte, string) (MirrorList, error) { ranked++; return MirrorList{Servers: good}, nil }
|
||||
u.Machine.ReadFile = func(string) ([]byte, error) { return []byte("--sort rate\n"), nil }
|
||||
rounds.Put("2026-W43", Round{Round: "2026-W43", Opened: t0, OpenedBy: "node-a", Order: []string{"node-a"}})
|
||||
for _, running := range []bool{true, false} {
|
||||
if !running {
|
||||
rounds.Delete("2026-W43")
|
||||
}
|
||||
key := NodeKey("node-a", "ask-m")
|
||||
asks.Put(key, Ask{ID: "ask-m", Node: "node-a", Act: ActMirrors, At: t0})
|
||||
e, _ := asks.Get(key)
|
||||
err := u.TakeAsk(stdio.StateChange{Op: "put", Key: key, Value: e.Value})
|
||||
if left, _ := asks.Get(key); left != nil || (err != nil) != running || ranked != map[bool]int{true: 0, false: 1}[running] ||
|
||||
(running && !strings.Contains(err.Error(), "round 2026-W43 runs")) {
|
||||
t.Errorf("a refresh with a round running %v: %v, ranked %d, ask left %v", running, err, ranked, left)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user