mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-05 23:36:49 -04:00
Move ReplicaCandidate and PickBestReplica out of core/services/nodes (which depends on gorm) into a new dependency-light leaf package pkg/clusterrouting, so the p2p federation server can later share the same replica-selection policy without pulling in a database driver. core/services/nodes keeps a type alias and a thin delegator, so every existing reference (the LoadedReplicaStats interface method, the ReplicaCandidate row conversion in registry.go, and the SQL policy-mirror test) compiles and behaves unchanged. This is a pure, behavior-preserving refactor: the full nodes suite, including the policy-mirror spec that pins the SQL ORDER BY to PickBestReplica, stays green. Assisted-by: Claude Code:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
18 lines
879 B
Go
18 lines
879 B
Go
package nodes
|
|
|
|
import "github.com/mudler/LocalAI/pkg/clusterrouting"
|
|
|
|
// ReplicaCandidate aliases the canonical type in pkg/clusterrouting. The policy
|
|
// implementation moved there so the p2p federation server can share it without
|
|
// importing this package (which pulls in gorm). Because this is a type alias,
|
|
// existing references such as the LoadedReplicaStats interface method and the
|
|
// ReplicaCandidate(rw) row conversion in registry.go remain valid unchanged.
|
|
type ReplicaCandidate = clusterrouting.ReplicaCandidate
|
|
|
|
// PickBestReplica delegates to the canonical implementation in pkg/clusterrouting.
|
|
// The SQL ORDER BY in FindAndLockNodeWithModel (registry.go) must mirror it; the
|
|
// "policy mirror" spec in registry_test.go asserts they agree.
|
|
func PickBestReplica(candidates []ReplicaCandidate) *ReplicaCandidate {
|
|
return clusterrouting.PickBestReplica(candidates)
|
|
}
|