Routes may share one lease (affinity = "route") and skip crossbar's queue (queue = false)
route.go gains Route.Affinity/Queue with PerRoute(), Queues() and affinity validation (checkRoutes moved here; config.go calls it once). limiter.Track counts a request without holding or refusing it; a release hands the slot to a waiter only while in flight <= parallel. The proxy leases a PerRoute() route under an empty fingerprint (the row keeps the real one) and uses Track when Queues() is false. Implemented by Ornith (OpenCode); owner review removed a release-on-first-flush workaround for a race in the owner's given test (see implementer log). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,14 +71,6 @@ type Host struct {
|
||||
Wake *Wake `toml:"wake"`
|
||||
}
|
||||
|
||||
// Route is an ordered list of hosts to try, with an optional default model and
|
||||
// the peers allowed to reach it.
|
||||
type Route struct {
|
||||
Hosts []string `toml:"hosts"`
|
||||
DefaultModel string `toml:"default_model"`
|
||||
Peers []string `toml:"peers"`
|
||||
}
|
||||
|
||||
// Config is the whole file: what to listen on, tuning, hosts and routes.
|
||||
type Config struct {
|
||||
Listen string `toml:"listen"`
|
||||
@@ -117,8 +109,6 @@ const (
|
||||
DefaultIdentity = "off"
|
||||
)
|
||||
|
||||
var routeName = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
|
||||
|
||||
// Load reads and parses the config file at path. An open failure is wrapped as
|
||||
// "config: …", the same shape as a decode failure.
|
||||
func Load(path string) (*Config, error) {
|
||||
@@ -345,54 +335,3 @@ func (c *Config) checkHosts() *Error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) checkRoutes(peersDefined map[string]bool, identityDefined bool) *Error {
|
||||
if len(c.Routes) == 0 {
|
||||
return &Error{Field: "routes", Msg: "at least one required"}
|
||||
}
|
||||
names := make([]string, 0, len(c.Routes))
|
||||
for name := range c.Routes {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
for _, name := range names {
|
||||
r := c.Routes[name]
|
||||
|
||||
if !routeName.MatchString(name) && !templateName.MatchString(name) {
|
||||
return &Error{Field: fmt.Sprintf("routes.%s", name), Msg: "must match [a-z0-9][a-z0-9-]*"}
|
||||
}
|
||||
|
||||
hostsField := fmt.Sprintf("routes.%s.hosts", name)
|
||||
if len(r.Hosts) == 0 {
|
||||
return &Error{Field: hostsField, Msg: "at least one required"}
|
||||
}
|
||||
seen := make(map[string]bool, len(r.Hosts))
|
||||
for _, h := range r.Hosts {
|
||||
if seen[h] {
|
||||
return &Error{Field: hostsField, Msg: "host listed twice"}
|
||||
}
|
||||
seen[h] = true
|
||||
if _, ok := c.Hosts[h]; !ok {
|
||||
return &Error{Field: hostsField, Msg: "unknown host"}
|
||||
}
|
||||
}
|
||||
|
||||
if r.DefaultModel != "" {
|
||||
served := false
|
||||
for _, h := range r.Hosts {
|
||||
if _, ok := c.Hosts[h].Models[r.DefaultModel]; ok {
|
||||
served = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !served {
|
||||
return &Error{Field: fmt.Sprintf("routes.%s.default_model", name), Msg: "not served by any host in route"}
|
||||
}
|
||||
}
|
||||
|
||||
if e := checkPeers(name, r.Peers, peersDefined[name], identityDefined, c.Identity); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user