Documentation
¶
Index ¶
- type RouteIndex
- type Store
- func (s *Store) AgentCount() int
- func (s *Store) CacheSnapshot() map[string]protocol.CacheEntityStats
- func (s *Store) ChannelCount() int
- func (s *Store) DeleteAgent(agentID string)
- func (s *Store) DeleteChannel(id uint)
- func (s *Store) DeleteGlobalRouting(name string)
- func (s *Store) DeleteModelConfig(modelName string)
- func (s *Store) DeleteToken(key string)
- func (s *Store) DeleteTokenByID(id uint)
- func (s *Store) DeleteUser(id uint)
- func (s *Store) DeleteUserGroup(id uint)
- func (s *Store) GetAgent(agentID string) *models.Agent
- func (s *Store) GetAgentsByTag(tag string) []*models.Agent
- func (s *Store) GetAllAgents() []*models.Agent
- func (s *Store) GetAllModelNames() []string
- func (s *Store) GetChannel(id uint) *models.Channel
- func (s *Store) GetChannelsForModel(model string) []*models.Channel
- func (s *Store) GetGlobalRouting(name string) *protocol.SyncedRouting
- func (s *Store) GetModelConfig(modelName string) *models.ModelConfig
- func (s *Store) GetSystemTestToken() *models.Token
- func (s *Store) GetToken(ctx context.Context, key string) *models.Token
- func (s *Store) GetTokenByID(ctx context.Context, id uint) *models.Token
- func (s *Store) GetUser(ctx context.Context, id uint) *protocol.SyncedUser
- func (s *Store) GetUserGroup(id uint) *models.UserGroup
- func (s *Store) GlobalRoutingCount() int
- func (s *Store) HandleSyncEvent(entity, action string, data []byte)
- func (s *Store) InvalidateUserRoutings(userID uint)
- func (s *Store) ListGlobalRoutingNames() []string
- func (s *Store) ListUserRoutingNames(userID uint) []string
- func (s *Store) LoadAgents(agents []models.Agent)
- func (s *Store) LoadChannels(channels []models.Channel)
- func (s *Store) LoadGlobalRoutings(items []models.ModelRouting)
- func (s *Store) LoadModelConfigs(configs []models.ModelConfig)
- func (s *Store) LoadSettings(settings []models.Setting)
- func (s *Store) LoadTokens(tokens []models.Token)
- func (s *Store) LoadUserGroups(groups []models.UserGroup)
- func (s *Store) LoadUsers(users []protocol.SyncedUser)
- func (s *Store) ModelConfigCount() int
- func (s *Store) OnChannelChange(fn func(old, new *models.Channel))
- func (s *Store) RebuildModelIndex()
- func (s *Store) ResolveRouting(name string, userID uint) *protocol.SyncedRouting
- func (s *Store) SetAgent(agent *models.Agent)
- func (s *Store) SetChannel(ch *models.Channel)
- func (s *Store) SetGlobalRouting(name string, r *protocol.SyncedRouting)
- func (s *Store) SetLogger(l *zap.Logger)
- func (s *Store) SetModelConfig(mc *models.ModelConfig)
- func (s *Store) SetToken(token *models.Token)
- func (s *Store) SetTraceMaxBodySize(size int)
- func (s *Store) SetUser(u *protocol.SyncedUser)
- func (s *Store) SetUserGroup(g *models.UserGroup)
- func (s *Store) SetUserRoutings(userID uint, routings map[string]*protocol.SyncedRouting)
- func (s *Store) SetVersion(v int64)
- func (s *Store) TokenCount() int
- func (s *Store) TraceMaxBodySize() int
- func (s *Store) UpdateAgentAutoAddresses(agentID string, addrs []agentproxy.Address)
- func (s *Store) UserCount() int
- func (s *Store) UserGroupCount() int
- func (s *Store) UserRoutingsCount() int
- func (s *Store) Version() int64
- type Syncer
- type TokenIDFetcher
- type WSBridge
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RouteIndex ¶
type RouteIndex struct {
// contains filtered or unexported fields
}
RouteIndex 封装 Agent 路由规则的存储和索引。
func (*RouteIndex) Load ¶
func (ri *RouteIndex) Load(routes []*models.AgentRoute)
Load 全量加载:清空旧数据后重建索引。
func (*RouteIndex) Match ¶
func (ri *RouteIndex) Match(tokenID uint, model string, channelIDs []uint) *models.AgentRoute
Match 按优先级匹配路由规则: 1. token + model 精确匹配 (priority 100) 2. token 默认 (priority 90) 3. channel + model 精确匹配 (priority 80) 4. channel 默认 (priority 70)
type Store ¶
type Store struct {
RouteIndex *RouteIndex
// contains filtered or unexported fields
}
func NewStore ¶
func NewStore(client app.WSClient, cfg config.AgentCacheConfig) *Store
NewStore 装配 agent 端缓存 Store。 client 用于 LRU 实体的 miss 拉取(可为 nil;nil 时 LRU 实体只读缓存)。 cfg 决定 LRU 容量与负缓存 TTL;零值/非法值由 normalize 兜底为默认。
选择性 LRU:tokens / users 走 LRU;channels / modelConfigs / agents / userGroups 仍是 admin 维护的小规模实体,走 FullCache。
func (*Store) AgentCount ¶
func (*Store) CacheSnapshot ¶
func (s *Store) CacheSnapshot() map[string]protocol.CacheEntityStats
CacheSnapshot 收集每实体的 Stats 用于 heartbeat 上报。 LRU 模式实体含完整字段;Full 模式实体仅 Size 有意义、其他字段为 0。
func (*Store) ChannelCount ¶
func (*Store) DeleteAgent ¶
func (*Store) DeleteChannel ¶
func (*Store) DeleteGlobalRouting ¶
DeleteGlobalRouting 删除全局 routing。
func (*Store) DeleteModelConfig ¶
func (*Store) DeleteToken ¶
func (*Store) DeleteTokenByID ¶
func (*Store) DeleteUser ¶
func (*Store) DeleteUserGroup ¶
func (*Store) GetAgentsByTag ¶
GetAgentsByTag returns all active agents that have the given tag.
func (*Store) GetAllAgents ¶
GetAllAgents returns all cached agents.
func (*Store) GetAllModelNames ¶
GetAllModelNames 返回所有暴露给 /v1/models 的 model 名: - 真实 model(来自 channel.Models 派生的 modelChannels 索引) - 全局 enabled routing 的 name 用户级 routing 不进全局列表(避免命名冲突;用户调 /v1/models 时由 handler 叠加该用户的 user routing)。
func (*Store) GetChannelsForModel ¶
func (*Store) GetGlobalRouting ¶
func (s *Store) GetGlobalRouting(name string) *protocol.SyncedRouting
GetGlobalRouting 返回 enabled 的全局 routing;disabled 或 not found 都返回 nil。 disabled 等同于运行时"临时移除"——校验层另有一份不过滤 enabled 的查询。
func (*Store) GetModelConfig ¶
func (s *Store) GetModelConfig(modelName string) *models.ModelConfig
func (*Store) GetSystemTestToken ¶
GetSystemTestToken finds the system test token by name. 走 Range 遍历主存储——LRU 模式下只看缓存中的 token,未缓存的不会被找到。
func (*Store) GetTokenByID ¶
func (*Store) GlobalRoutingCount ¶
GlobalRoutingCount 返回当前缓存的全局 routing 数(用于 stats / 日志)。
func (*Store) HandleSyncEvent ¶
func (*Store) InvalidateUserRoutings ¶
InvalidateUserRoutings 清掉某 user 的整块 cache,下次 ResolveRouting LRU miss 时由 Loader 重新拉取(B3.4 接入)。
func (*Store) ListGlobalRoutingNames ¶
ListGlobalRoutingNames 返回所有 enabled 全局 routing 名,按字典序排序。 用于 /v1/models 暴露 routing 作为可调用 model 名。
func (*Store) ListUserRoutingNames ¶
ListUserRoutingNames 返回当前用户 enabled user-scope routing 名,按字典序排序。 userID==0 或无 entry 时返回 nil。LRU miss 触发 loader 失败时同样返回 nil。
func (*Store) LoadAgents ¶
func (*Store) LoadChannels ¶
func (*Store) LoadGlobalRoutings ¶
func (s *Store) LoadGlobalRoutings(items []models.ModelRouting)
LoadGlobalRoutings 全量替换 globalRoutings 缓存(用于 FullSync)。 把 models.ModelRouting 投影成 protocol.SyncedRouting;只加载 enabled=true 的条目。
func (*Store) LoadModelConfigs ¶
func (s *Store) LoadModelConfigs(configs []models.ModelConfig)
func (*Store) LoadSettings ¶
func (*Store) LoadTokens ¶
func (*Store) LoadUserGroups ¶
func (*Store) LoadUsers ¶
func (s *Store) LoadUsers(users []protocol.SyncedUser)
func (*Store) ModelConfigCount ¶
func (*Store) OnChannelChange ¶
OnChannelChange 注册一个 channel upsert 时的回调。 old 可能是 nil(首次出现);new 可能是 nil(删除)。 同步调用,回调函数应保持轻量。
func (*Store) RebuildModelIndex ¶
func (s *Store) RebuildModelIndex()
RebuildModelIndex 从 channels 重建 model→channels 派生索引。
func (*Store) ResolveRouting ¶
func (s *Store) ResolveRouting(name string, userID uint) *protocol.SyncedRouting
ResolveRouting 按 spec §1.4 优先级解析:用户 routing > 全局 routing > nil(让上层当真实 model 处理)。
func (*Store) SetChannel ¶
func (*Store) SetGlobalRouting ¶
func (s *Store) SetGlobalRouting(name string, r *protocol.SyncedRouting)
SetGlobalRouting 写入全局 routing。WS push / FullSync 调用。
func (*Store) SetLogger ¶
SetLogger 注入 zap.Logger,用于 routing apply / resolve 等可观测性日志。 默认 NewStore 使用 zap.NewNop();server 装配时调用以接入实际 logger。
func (*Store) SetModelConfig ¶
func (s *Store) SetModelConfig(mc *models.ModelConfig)
func (*Store) SetTraceMaxBodySize ¶
func (*Store) SetUser ¶
func (s *Store) SetUser(u *protocol.SyncedUser)
func (*Store) SetUserGroup ¶
func (*Store) SetUserRoutings ¶
func (s *Store) SetUserRoutings(userID uint, routings map[string]*protocol.SyncedRouting)
SetUserRoutings 用整块替换某 user 的全部 user-scope routings。 WS push 按 user 粒度推送时调用。
func (*Store) SetVersion ¶
func (*Store) TokenCount ¶
func (*Store) TraceMaxBodySize ¶
func (*Store) UpdateAgentAutoAddresses ¶
func (s *Store) UpdateAgentAutoAddresses(agentID string, addrs []agentproxy.Address)
UpdateAgentAutoAddresses updates in-memory auto-detected addresses for an agent without overriding manually configured addresses.
func (*Store) UserGroupCount ¶
func (*Store) UserRoutingsCount ¶
UserRoutingsCount 返回当前 LRU 中缓存的 user-scope routing 块数(每个 user 一块)。
type Syncer ¶
type Syncer struct {
Store *Store
Client app.WSClient
Bus app.EventBus
Logger *zap.Logger
FullSyncInterval time.Duration
// contains filtered or unexported fields
}
func (*Syncer) FullSync ¶
FullSync pulls all data from master.
LRU 模式实体(token / user)不参与 FullSync——它们靠 push apply-if-present + miss 时 RPC 拉取保持最新。全量重拉违背 LRU 容量目标,会让 agent 内存 重新涨回基线。
func (*Syncer) StartPeriodicCheck ¶
StartPeriodicCheck starts periodic version comparison
func (*Syncer) SubscribeEvents ¶
func (s *Syncer) SubscribeEvents()
SubscribeEvents subscribes to local EventBus for sync events from WSBridge
type TokenIDFetcher ¶
TokenIDFetcher 负责按 id 从 master 拉 token—— 当 byID 命中但 primary 已被 LRU 淘汰时使用。 接入将在 Task 16 / Task 18 完成;当前可传 nil。
Directories
¶
| Path | Synopsis |
|---|---|
|
Package entitycache 提供通用实体缓存抽象。
|
Package entitycache 提供通用实体缓存抽象。 |
|
Package loaders 提供 entitycache.Loader 的具体实现(每实体一个文件)。
|
Package loaders 提供 entitycache.Loader 的具体实现(每实体一个文件)。 |