feat(M6): token-ring protocol complete — task ride+lowest-load claim, topology publish back to token, real worker spawn via claim, incremental log sync e2e

This commit is contained in:
2026-08-18 09:08:22 +08:00
parent e59feb82c1
commit 1a8c362080
2 changed files with 40 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import (
"context"
"log"
"time"
"webui4frpc/internal/store"
)
// Phase constants for the two-round cycle.
@ -159,7 +161,10 @@ func (e *Engine) phase2(ctx context.Context, tk *Token) error {
}
e.state.AddTopology(claimed, e.ID)
}
e.state = tk.State
// Publish our updated state back into the token so the next node carries
// the fresh topology + pending set (do NOT revert local state to the
// incoming snapshot — that would discard the claim we just made).
tk.State = e.state
tk.Passed = append(tk.Passed, e.ID)
return nil
}
@ -359,6 +364,12 @@ func (e *Engine) AdoptState(s State) {
}
}
// SubmitTask adds a new forward request to pending; it rides the next token
// round and is claimed by the lowest-load member.
func (e *Engine) SubmitTask(local store.Local, remote store.Remote, link store.Link) *Task {
return e.state.AddPending(local, remote, link)
}
// IsLeader reports whether this node is the current ring leader.
func (e *Engine) IsLeader() bool { return e.state.LeaderID == e.ID }