Documentation
¶
Index ¶
- Variables
- type APIIndex
- func (i *APIIndex) AllReady() bool
- func (i *APIIndex) AllowsInvoke(roleIDs []uint, serviceID, routeID uint) bool
- func (i *APIIndex) AnyDirty() bool
- func (i *APIIndex) ApplyRole(action string, value protocol.SyncedAPIRole) error
- func (i *APIIndex) ApplyRoute(action string, value protocol.SyncedAPIRoute) error
- func (i *APIIndex) ApplyService(action string, value protocol.SyncedAPIService) error
- func (i *APIIndex) ApplyUpstream(action string, value protocol.SyncedAPIUpstream) error
- func (i *APIIndex) ApplyUserGroupRoleSet(action string, value protocol.APIRoleSetFetchResult) error
- func (i *APIIndex) CheckInvoke(roleIDs []uint, serviceID, routeID uint) (bool, error)
- func (i *APIIndex) FindServiceRoute(serviceSlug, routeSlug string) (ServiceRoute, error)
- func (i *APIIndex) FindServiceRouteByID(serviceID, routeID uint) (ServiceRoute, error)
- func (i *APIIndex) MarkDirty(entity string)
- func (i *APIIndex) ReplaceRoles(values []protocol.SyncedAPIRole) error
- func (i *APIIndex) ReplaceRoutes(values []protocol.SyncedAPIRoute) error
- func (i *APIIndex) ReplaceServices(values []protocol.SyncedAPIService) error
- func (i *APIIndex) ReplaceUpstreams(values []protocol.SyncedAPIUpstream) error
- func (i *APIIndex) ReplaceUserGroupRoleSets(values []protocol.APIRoleSetFetchResult) error
- func (i *APIIndex) RequireReady() error
- func (i *APIIndex) ResetReadiness()
- func (i *APIIndex) UpstreamsForBackend(backendID uint) []protocol.SyncedAPIUpstream
- func (i *APIIndex) UserGroupRoleSet(groupID uint) protocol.APIRoleSetFetchResult
- type APILimiter
- type ControlSession
- type LimiterIndex
- func (li *LimiterIndex) CacheName() string
- func (li *LimiterIndex) CacheStat() protocol.CacheEntityStats
- func (li *LimiterIndex) DeleteBinding(id uint)
- func (li *LimiterIndex) DeleteLimiter(id uint)
- func (li *LimiterIndex) EffectiveAttemptLimiters(userID, groupID uint, src string, channelID uint) []*models.RequestLimiter
- func (li *LimiterIndex) EffectiveRequestLimiters(userID, groupID uint) []*models.RequestLimiter
- func (li *LimiterIndex) EffectiveSourceAPILimiters(userID, groupID, serviceID, routeID uint) []APILimiter
- func (li *LimiterIndex) EffectiveUpstreamAPILimiters(upstreamID uint) []APILimiter
- func (li *LimiterIndex) Limiter(id uint) *models.RequestLimiter
- func (li *LimiterIndex) LoadBindings(bs []models.LimiterBinding)
- func (li *LimiterIndex) LoadLimiters(ls []models.RequestLimiter)
- func (li *LimiterIndex) PutBinding(b *models.LimiterBinding)
- func (li *LimiterIndex) PutLimiter(l *models.RequestLimiter)
- type NamedCacheStat
- type RouteIndex
- func (ri *RouteIndex) Apply(action string, route *models.AgentRoute)
- func (ri *RouteIndex) CacheName() string
- func (ri *RouteIndex) CacheStat() protocol.CacheEntityStats
- func (ri *RouteIndex) Delete(routeID uint)
- func (ri *RouteIndex) FindAPIRouteRoute(routeID uint) *models.AgentRoute
- func (ri *RouteIndex) FindAPIServiceRoute(serviceID uint) *models.AgentRoute
- func (ri *RouteIndex) FindAdminChannelRoute(channelID uint, realModel string) *models.AgentRoute
- func (ri *RouteIndex) FindTokenRoute(tokenID uint, realModel string) *models.AgentRoute
- func (ri *RouteIndex) Load(routes []*models.AgentRoute)
- func (ri *RouteIndex) Put(route *models.AgentRoute)
- func (ri *RouteIndex) Replace(routes []*models.AgentRoute)
- type ServiceRoute
- type Store
- func (s *Store) AdvanceVersion(version int64)
- func (s *Store) AgentCount() int
- func (s *Store) ApplyDirectAddressesUpdate(update protocol.AgentDirectAddressesUpdate) bool
- func (s *Store) BeginDirectAddressSession(masterInstanceID string)
- func (s *Store) CacheSnapshot() map[string]protocol.CacheEntityStats
- func (s *Store) ChannelCount() int
- func (s *Store) ClearAPIRoleSets()
- func (s *Store) ClearAgentCapabilities()
- func (s *Store) Close()
- func (s *Store) DeleteAgent(agentID string)
- func (s *Store) DeleteAgentCapabilities(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) DeleteTokenAPIRoleSet(id uint)
- func (s *Store) DeleteTokenByID(id uint)
- func (s *Store) DeleteUser(id uint)
- func (s *Store) DeleteUserAPIRoleSet(id uint)
- func (s *Store) DeleteUserGroup(id uint)
- func (s *Store) Done() <-chan struct{}
- func (s *Store) EffectiveAttemptLimiters(userID, groupID uint, src string, channelID uint) []*models.RequestLimiter
- func (s *Store) EffectiveRequestLimiters(userID, groupID uint) []*models.RequestLimiter
- func (s *Store) FallbackSleepMs() int
- func (s *Store) FindTokenAPIRoleSet(ctx context.Context, id uint) (*protocol.APIRoleSet, bool, error)
- func (s *Store) FindTokenByID(ctx context.Context, id uint) (*models.Token, bool, error)
- func (s *Store) FindUser(ctx context.Context, id uint) (*protocol.SyncedUser, bool, error)
- func (s *Store) FindUserAPIRoleSet(ctx context.Context, id uint) (*protocol.APIRoleSet, bool, error)
- func (s *Store) GetAgent(agentID string) *models.Agent
- func (s *Store) GetAgentCapabilities(agentID string) []string
- 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(ctx context.Context, 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) GetVisiblePrivateChannelsForUser(userID uint, model string) []*protocol.SyncedPrivateChannel
- func (s *Store) GlobalRoutingCount() int
- func (s *Store) HandleSyncEvent(entity, action string, data []byte)
- func (s *Store) HasRealModel(name string) bool
- func (s *Store) InvalidateTokenRoutings(tokenID uint)
- func (s *Store) InvalidateUserRoutings(userID uint)
- func (s *Store) InvalidateVisiblePrivateChannels(userID uint)
- func (s *Store) ListGlobalRoutingNames() []string
- func (s *Store) ListTokenRoutingNames(ctx context.Context, tokenID uint) []string
- func (s *Store) ListUserRoutingNames(ctx context.Context, userID uint) []string
- func (s *Store) ListVisibleBYOKModelNamesForUser(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) LoadScripts(list []models.AdminScript)
- 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) MatchScripts(input script.MatchInput) []*script.Compiled
- func (s *Store) ModelConfigCount() int
- func (s *Store) OnChannelChange(fn func(old, new *models.Channel))
- func (s *Store) OverrideVisiblePrivateChannels(userID uint, channels []protocol.SyncedPrivateChannel)
- func (s *Store) RebuildModelIndex()
- func (s *Store) ResolveRouting(ctx context.Context, name string, owner protocol.RoutingOwner) *protocol.SyncedRouting
- func (s *Store) ResourceCounts() (loads, refreshes int64)
- func (s *Store) ScriptCount() int
- func (s *Store) ScriptEngine() *script.Engine
- func (s *Store) SetAgent(agent *models.Agent)
- func (s *Store) SetAgentCapabilities(agentID string, capabilities []string)
- 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) SetTokenAPIRoleSet(id uint, roleSet *protocol.APIRoleSet)
- func (s *Store) SetTokenRoutings(tokenID uint, routings map[string]*protocol.SyncedRouting)
- func (s *Store) SetUser(u *protocol.SyncedUser)
- func (s *Store) SetUserAPIRoleSet(id uint, roleSet *protocol.APIRoleSet)
- func (s *Store) SetUserGroup(g *models.UserGroup)
- func (s *Store) SetUserQuota(id uint, quota int64)
- func (s *Store) SetUserRoutings(userID uint, routings map[string]*protocol.SyncedRouting)
- func (s *Store) SetVersion(v int64)
- func (s *Store) Settings() settings.AgentSettings
- func (s *Store) TokenCount() int
- func (s *Store) TokenRoutingsCount() 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
- func (s *Store) VisiblePrivateChannelsCount() int
- type Syncer
- func (s *Syncer) ApplySyncPushForSession(expected *ControlSession, params protocol.SyncPushParams) (bool, error)
- func (s *Syncer) BeginControlSession(client app.WSClient) *ControlSession
- func (s *Syncer) CurrentControlSession() *ControlSession
- func (s *Syncer) EndControlSession(expected *ControlSession) bool
- func (s *Syncer) FullSync(ctx context.Context) error
- func (s *Syncer) FullSyncForSession(ctx context.Context, expected *ControlSession) error
- func (s *Syncer) RequestFullSync() bool
- func (s *Syncer) RequestFullSyncForSession(expected *ControlSession) bool
- func (s *Syncer) RunPeriodicCheck(ctx context.Context)
- func (s *Syncer) RunRequestedFullSyncs(ctx context.Context)
- func (s *Syncer) SetClient(client app.WSClient)
- func (s *Syncer) StartPeriodicCheck(ctx context.Context)
- func (s *Syncer) SubscribeEvents() error
- type TokenIDFetcher
- type WSBridge
Constants ¶
This section is empty.
Variables ¶
var ( ErrAPICacheNotReady = errors.New("api cache not ready") ErrAPIServiceNotFound = errors.New("api service not found") ErrAPIRouteNotFound = errors.New("api route not found") )
var (
ErrControlSessionChanged = errors.New("control session changed")
)
Functions ¶
This section is empty.
Types ¶
type APIIndex ¶ added in v0.0.16
type APIIndex struct {
// contains filtered or unexported fields
}
func NewAPIIndex ¶ added in v0.0.16
func NewAPIIndex() *APIIndex
func (*APIIndex) AllowsInvoke ¶ added in v0.0.16
func (*APIIndex) ApplyRole ¶ added in v0.0.16
func (i *APIIndex) ApplyRole(action string, value protocol.SyncedAPIRole) error
func (*APIIndex) ApplyRoute ¶ added in v0.0.16
func (i *APIIndex) ApplyRoute(action string, value protocol.SyncedAPIRoute) error
func (*APIIndex) ApplyService ¶ added in v0.0.16
func (i *APIIndex) ApplyService(action string, value protocol.SyncedAPIService) error
func (*APIIndex) ApplyUpstream ¶ added in v0.0.16
func (i *APIIndex) ApplyUpstream(action string, value protocol.SyncedAPIUpstream) error
func (*APIIndex) ApplyUserGroupRoleSet ¶ added in v0.0.16
func (i *APIIndex) ApplyUserGroupRoleSet(action string, value protocol.APIRoleSetFetchResult) error
func (*APIIndex) CheckInvoke ¶ added in v0.0.16
func (*APIIndex) FindServiceRoute ¶ added in v0.0.16
func (i *APIIndex) FindServiceRoute(serviceSlug, routeSlug string) (ServiceRoute, error)
func (*APIIndex) FindServiceRouteByID ¶ added in v0.0.16
func (i *APIIndex) FindServiceRouteByID(serviceID, routeID uint) (ServiceRoute, error)
FindServiceRouteByID returns the immutable execution projection named by a Source-frozen service/route pair. It does not perform authorization.
func (*APIIndex) ReplaceRoles ¶ added in v0.0.16
func (i *APIIndex) ReplaceRoles(values []protocol.SyncedAPIRole) error
func (*APIIndex) ReplaceRoutes ¶ added in v0.0.16
func (i *APIIndex) ReplaceRoutes(values []protocol.SyncedAPIRoute) error
func (*APIIndex) ReplaceServices ¶ added in v0.0.16
func (i *APIIndex) ReplaceServices(values []protocol.SyncedAPIService) error
func (*APIIndex) ReplaceUpstreams ¶ added in v0.0.16
func (i *APIIndex) ReplaceUpstreams(values []protocol.SyncedAPIUpstream) error
func (*APIIndex) ReplaceUserGroupRoleSets ¶ added in v0.0.16
func (i *APIIndex) ReplaceUserGroupRoleSets(values []protocol.APIRoleSetFetchResult) error
func (*APIIndex) RequireReady ¶ added in v0.0.16
func (*APIIndex) ResetReadiness ¶ added in v0.0.16
func (i *APIIndex) ResetReadiness()
func (*APIIndex) UpstreamsForBackend ¶ added in v0.0.16
func (i *APIIndex) UpstreamsForBackend(backendID uint) []protocol.SyncedAPIUpstream
func (*APIIndex) UserGroupRoleSet ¶ added in v0.0.16
func (i *APIIndex) UserGroupRoleSet(groupID uint) protocol.APIRoleSetFetchResult
type APILimiter ¶ added in v0.0.16
type APILimiter struct {
Limiter *models.RequestLimiter
TargetType string
TargetID uint
}
type ControlSession ¶ added in v0.0.13
type ControlSession struct {
// contains filtered or unexported fields
}
ControlSession is an unforgeable lease for one installed Master connection. Its fields stay private so only Syncer can decide whether a caller may commit.
type LimiterIndex ¶ added in v0.0.8
type LimiterIndex struct {
// contains filtered or unexported fields
}
LimiterIndex 持有同步下发的 limiters + bindings,重建候选索引, 并按 spec §6.1 就近覆盖解析出每个 (Metric,KeyBy) 维度的生效 limiter。 放在 cache 包(同 RouteIndex),由 Store 持有;relay 侧通过接口读取,避免循环依赖。
func NewLimiterIndex ¶ added in v0.0.8
func NewLimiterIndex() *LimiterIndex
func (*LimiterIndex) CacheName ¶ added in v0.0.8
func (li *LimiterIndex) CacheName() string
CacheName / CacheStat 实现 NamedCacheStat:报限流器/绑定条数(持锁读)。
func (*LimiterIndex) CacheStat ¶ added in v0.0.8
func (li *LimiterIndex) CacheStat() protocol.CacheEntityStats
func (*LimiterIndex) DeleteBinding ¶ added in v0.0.8
func (li *LimiterIndex) DeleteBinding(id uint)
func (*LimiterIndex) DeleteLimiter ¶ added in v0.0.8
func (li *LimiterIndex) DeleteLimiter(id uint)
func (*LimiterIndex) EffectiveAttemptLimiters ¶ added in v0.0.8
func (li *LimiterIndex) EffectiveAttemptLimiters(userID, groupID uint, src string, channelID uint) []*models.RequestLimiter
EffectiveAttemptLimiters 返回尝试级(KeyBy 依赖渠道)的生效 limiter,含 ChannelScope 过滤。 src 是渠道来源字符串:"admin" | "private"(等于 string(state.SourceAdmin/SourcePrivate))。
func (*LimiterIndex) EffectiveRequestLimiters ¶ added in v0.0.8
func (li *LimiterIndex) EffectiveRequestLimiters(userID, groupID uint) []*models.RequestLimiter
EffectiveRequestLimiters 返回请求级(KeyBy 不依赖渠道)的生效 limiter。
func (*LimiterIndex) EffectiveSourceAPILimiters ¶ added in v0.0.16
func (li *LimiterIndex) EffectiveSourceAPILimiters(userID, groupID, serviceID, routeID uint) []APILimiter
func (*LimiterIndex) EffectiveUpstreamAPILimiters ¶ added in v0.0.16
func (li *LimiterIndex) EffectiveUpstreamAPILimiters(upstreamID uint) []APILimiter
func (*LimiterIndex) Limiter ¶ added in v0.0.8
func (li *LimiterIndex) Limiter(id uint) *models.RequestLimiter
Limiter 按 ID 返回限流器副本(快照/展示用)。不存在返回 nil。持锁读。
func (*LimiterIndex) LoadBindings ¶ added in v0.0.8
func (li *LimiterIndex) LoadBindings(bs []models.LimiterBinding)
func (*LimiterIndex) LoadLimiters ¶ added in v0.0.8
func (li *LimiterIndex) LoadLimiters(ls []models.RequestLimiter)
func (*LimiterIndex) PutBinding ¶ added in v0.0.8
func (li *LimiterIndex) PutBinding(b *models.LimiterBinding)
func (*LimiterIndex) PutLimiter ¶ added in v0.0.8
func (li *LimiterIndex) PutLimiter(l *models.RequestLimiter)
type NamedCacheStat ¶ added in v0.0.8
type NamedCacheStat interface {
CacheName() string // 监控页唯一键,如 "route_index" / "limiter_index"
CacheStat() protocol.CacheEntityStats
}
NamedCacheStat 是任意"带名字、能自报统计"的缓存/索引。 实现它即可被 Store.CacheSnapshot() 自动纳入心跳上报——无需再在多处手抄清单。 新增缓存务必实现此接口(或由 Store 的反射完整性测试 TestCacheSnapshot_Complete 拦截遗漏)。
type RouteIndex ¶
type RouteIndex struct {
// contains filtered or unexported fields
}
RouteIndex 封装 Agent 路由规则的存储和索引。
func (*RouteIndex) Apply ¶ added in v0.0.13
func (ri *RouteIndex) Apply(action string, route *models.AgentRoute)
Apply 应用 create/update/delete 路由变更,未知动作不修改索引。
func (*RouteIndex) CacheName ¶ added in v0.0.8
func (ri *RouteIndex) CacheName() string
CacheName / CacheStat 实现 NamedCacheStat:索引类只报条目数(无 LRU 命中语义)。
func (*RouteIndex) CacheStat ¶ added in v0.0.8
func (ri *RouteIndex) CacheStat() protocol.CacheEntityStats
func (*RouteIndex) FindAPIRouteRoute ¶ added in v0.0.16
func (ri *RouteIndex) FindAPIRouteRoute(routeID uint) *models.AgentRoute
func (*RouteIndex) FindAPIServiceRoute ¶ added in v0.0.16
func (ri *RouteIndex) FindAPIServiceRoute(serviceID uint) *models.AgentRoute
func (*RouteIndex) FindAdminChannelRoute ¶ added in v0.0.13
func (ri *RouteIndex) FindAdminChannelRoute(channelID uint, realModel string) *models.AgentRoute
FindAdminChannelRoute 查找当前 admin channel scope 下的精确模型或默认路由。
func (*RouteIndex) FindTokenRoute ¶ added in v0.0.13
func (ri *RouteIndex) FindTokenRoute(tokenID uint, realModel string) *models.AgentRoute
FindTokenRoute 查找当前 token scope 下的精确模型或默认路由。
func (*RouteIndex) Replace ¶ added in v0.0.13
func (ri *RouteIndex) Replace(routes []*models.AgentRoute)
Replace 全量替换路由索引,并在完整构建后一次性发布。
type ServiceRoute ¶ added in v0.0.16
type ServiceRoute struct {
Service protocol.SyncedAPIService
Route protocol.SyncedAPIRoute
}
type Store ¶
type Store struct {
APIIndex *APIIndex
RouteIndex *RouteIndex
LimiterIndex *LimiterIndex
// 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) AdvanceVersion ¶ added in v0.0.13
AdvanceVersion moves the local global version forward without requiring adjacent values. Global versions may have gaps and stale pages may arrive.
func (*Store) AgentCount ¶
func (*Store) ApplyDirectAddressesUpdate ¶ added in v0.0.13
func (s *Store) ApplyDirectAddressesUpdate(update protocol.AgentDirectAddressesUpdate) bool
ApplyDirectAddressesUpdate applies a newer event from the active Master epoch. The version high-water advances even when a manual address wins.
func (*Store) BeginDirectAddressSession ¶ added in v0.0.13
BeginDirectAddressSession removes runtime addresses from the previous control snapshot while preserving authoritative manual configuration.
func (*Store) CacheSnapshot ¶
func (s *Store) CacheSnapshot() map[string]protocol.CacheEntityStats
CacheSnapshot 收集每实体/索引的 Stats 用于 heartbeat 上报。 单一 provider 列表:实体缓存(LRU/Full)+ 实现 NamedCacheStat 的索引。 新增缓存请加进 namedStats() 或让其实现 NamedCacheStat; TestCacheSnapshot_Complete 反射兜底拦截遗漏。
func (*Store) ChannelCount ¶
func (*Store) ClearAPIRoleSets ¶ added in v0.0.16
func (s *Store) ClearAPIRoleSets()
func (*Store) ClearAgentCapabilities ¶ added in v0.0.13
func (s *Store) ClearAgentCapabilities()
func (*Store) DeleteAgent ¶
func (*Store) DeleteAgentCapabilities ¶ added in v0.0.13
func (*Store) DeleteChannel ¶
func (*Store) DeleteGlobalRouting ¶
DeleteGlobalRouting 删除全局 routing。
func (*Store) DeleteModelConfig ¶
func (*Store) DeleteToken ¶
func (*Store) DeleteTokenAPIRoleSet ¶ added in v0.0.16
func (*Store) DeleteTokenByID ¶
func (*Store) DeleteUser ¶
func (*Store) DeleteUserAPIRoleSet ¶ added in v0.0.16
func (*Store) DeleteUserGroup ¶
func (*Store) EffectiveAttemptLimiters ¶ added in v0.0.8
func (*Store) EffectiveRequestLimiters ¶ added in v0.0.8
func (s *Store) EffectiveRequestLimiters(userID, groupID uint) []*models.RequestLimiter
EffectiveRequestLimiters / EffectiveAttemptLimiters 委托给 LimiterIndex, 供 relay 侧 Gate 通过 app.AgentCache 接口读取(src: "admin"|"private")。
func (*Store) FallbackSleepMs ¶ added in v0.0.2
FallbackSleepMs 实现 exec.SleepReader 接口。 单独抽出方法是为了避免 exec 包 import cache 包(叶子原则)。
func (*Store) FindTokenAPIRoleSet ¶ added in v0.0.16
func (*Store) FindTokenByID ¶ added in v0.0.16
func (*Store) FindUserAPIRoleSet ¶ added in v0.0.16
func (*Store) GetAgentCapabilities ¶ added in v0.0.13
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 ¶
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) GetVisiblePrivateChannelsForUser ¶ added in v0.0.2
func (s *Store) GetVisiblePrivateChannelsForUser(userID uint, model string) []*protocol.SyncedPrivateChannel
func (*Store) GlobalRoutingCount ¶
GlobalRoutingCount 返回当前缓存的全局 routing 数(用于 stats / 日志)。
func (*Store) HandleSyncEvent ¶
func (*Store) HasRealModel ¶ added in v0.0.6
HasRealModel 判断 name 是否有 channel 支撑的真实模型(不含 routing)。
func (*Store) InvalidateTokenRoutings ¶ added in v0.0.13
func (*Store) InvalidateUserRoutings ¶
InvalidateUserRoutings 清掉某 user 的整块 cache,下次 ResolveRouting LRU miss 时由 Loader 重新拉取(B3.4 接入)。
func (*Store) InvalidateVisiblePrivateChannels ¶ added in v0.0.2
InvalidateVisiblePrivateChannels 删该 user 的整块 cache,下次 LRU miss 由 loader 重新拉取(与 user_routings 同模式:不增量合并,整块失效)。 share 表变更 / channel CRUD / user 离开 group 都触发。
func (*Store) ListGlobalRoutingNames ¶
ListGlobalRoutingNames 返回所有 enabled 全局 routing 名,按字典序排序。 用于 /v1/models 暴露 routing 作为可调用 model 名。
func (*Store) ListTokenRoutingNames ¶ added in v0.0.13
func (*Store) ListUserRoutingNames ¶
ListUserRoutingNames 返回当前用户 enabled user-scope routing 名,按字典序排序。 userID==0 或无 entry 时返回 nil。LRU miss 触发 loader 失败时同样返回 nil。
func (*Store) ListVisibleBYOKModelNamesForUser ¶ added in v0.0.2
ListVisibleBYOKModelNamesForUser 返回某 user 全部 enabled BYOK channel 的 Models 字段并集(去重,保序:channel 内部 Models 原序,跨 channel 先到先得)。 userID == 0 / 缓存 miss / 无 enabled channel 时返回 nil。 复用 visiblePrivateChannels LRU 缓存层,不引入新缓存。
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) LoadScripts ¶ added in v0.0.6
func (s *Store) LoadScripts(list []models.AdminScript)
LoadScripts 增量入列(full sync,分页友好——逐条 set,不整体替换, 避免分页第 2 页清掉第 1 页)。坏脚本不入列、disabled 入列但 match 时被过滤。
func (*Store) LoadSettings ¶
func (*Store) LoadTokens ¶
func (*Store) LoadUserGroups ¶
func (*Store) LoadUsers ¶
func (s *Store) LoadUsers(users []protocol.SyncedUser)
func (*Store) MatchScripts ¶ added in v0.0.6
func (s *Store) MatchScripts(input script.MatchInput) []*script.Compiled
MatchScripts 实现 script.ScriptProvider,转发给内部 scriptStore。
func (*Store) ModelConfigCount ¶
func (*Store) OnChannelChange ¶
OnChannelChange 注册一个 channel upsert 时的回调。 old 可能是 nil(首次出现);new 可能是 nil(删除)。 同步调用,回调函数应保持轻量。
func (*Store) OverrideVisiblePrivateChannels ¶ added in v0.0.2
func (s *Store) OverrideVisiblePrivateChannels(userID uint, channels []protocol.SyncedPrivateChannel)
OverrideVisiblePrivateChannels 直接写入 visiblePrivateChannels LRU, 绕过 loader——仅供跨包测试用,调用方必须在测试上下文中(testing.Testing())。 非测试上下文调用会 panic,避免生产代码意外污染用户 BYOK 缓存。
func (*Store) RebuildModelIndex ¶
func (s *Store) RebuildModelIndex()
RebuildModelIndex 从 channels 重建 model→channels 派生索引。
func (*Store) ResolveRouting ¶
func (s *Store) ResolveRouting(ctx context.Context, name string, owner protocol.RoutingOwner) *protocol.SyncedRouting
ResolveRouting 按 token > user > global 的优先级解析顶层路由。
func (*Store) ResourceCounts ¶ added in v0.0.13
func (*Store) ScriptCount ¶ added in v0.0.6
ScriptCount 返回成功编译入列的脚本数。
func (*Store) ScriptEngine ¶ added in v0.0.6
ScriptEngine 返回共享的脚本执行引擎。
func (*Store) SetAgentCapabilities ¶ added in v0.0.13
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) SetTokenAPIRoleSet ¶ added in v0.0.16
func (s *Store) SetTokenAPIRoleSet(id uint, roleSet *protocol.APIRoleSet)
func (*Store) SetTokenRoutings ¶ added in v0.0.13
func (s *Store) SetTokenRoutings(tokenID uint, routings map[string]*protocol.SyncedRouting)
func (*Store) SetUser ¶
func (s *Store) SetUser(u *protocol.SyncedUser)
func (*Store) SetUserAPIRoleSet ¶ added in v0.0.16
func (s *Store) SetUserAPIRoleSet(id uint, roleSet *protocol.APIRoleSet)
func (*Store) SetUserGroup ¶
func (*Store) SetUserQuota ¶ added in v0.0.8
SetUserQuota 更新已缓存 user 的 Quota 字段;用于配额扣减后的原地刷新。 若 user 不在缓存中则静默忽略(不触发 loader 拉取)。
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) Settings ¶ added in v0.0.2
func (s *Store) Settings() settings.AgentSettings
Settings 返回当前同步配置快照(value copy,不可变,无锁读)。
func (*Store) TokenCount ¶
func (*Store) TokenRoutingsCount ¶ added in v0.0.13
func (*Store) TraceMaxBodySize ¶
TraceMaxBodySize 兼容老调用方(internal/agent/relay/handler.go:125-126 等)。 新代码请走 Settings().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. It remains for callers that replace an already-authorized local snapshot.
func (*Store) UserGroupCount ¶
func (*Store) UserRoutingsCount ¶
UserRoutingsCount 返回当前 LRU 中缓存的 user-scope routing 块数(每个 user 一块)。
func (*Store) VisiblePrivateChannelsCount ¶ added in v0.0.2
VisiblePrivateChannelsCount 返回当前 LRU 中缓存的 user-scope private channel 块数。
type Syncer ¶
type Syncer struct {
Store *Store
Bus app.EventBus
Logger *zap.Logger
FullSyncInterval time.Duration
// contains filtered or unexported fields
}
func (*Syncer) ApplySyncPushForSession ¶ added in v0.0.13
func (s *Syncer) ApplySyncPushForSession( expected *ControlSession, params protocol.SyncPushParams, ) (bool, error)
ApplySyncPushForSession atomically checks the connection lease and applies one ordered push. Stale handlers are ignored without touching dirty state.
func (*Syncer) BeginControlSession ¶ added in v0.0.13
func (s *Syncer) BeginControlSession(client app.WSClient) *ControlSession
BeginControlSession installs a new client lease and cancels the previous one.
func (*Syncer) CurrentControlSession ¶ added in v0.0.13
func (s *Syncer) CurrentControlSession() *ControlSession
func (*Syncer) EndControlSession ¶ added in v0.0.13
func (s *Syncer) EndControlSession(expected *ControlSession) bool
EndControlSession clears only the expected lease; stale cleanup cannot clear a replacement connection.
func (*Syncer) FullSync ¶
FullSync pulls all data from master.
LRU 模式实体(token / user / private_channel)不参与 FullSync——它们靠 push invalidate + miss 时 RPC 拉取保持最新。全量重拉违背 LRU 容量目标,会让 agent 内存重新涨回基线。
func (*Syncer) FullSyncForSession ¶ added in v0.0.13
func (s *Syncer) FullSyncForSession(ctx context.Context, expected *ControlSession) error
FullSyncForSession runs and commits one pass only while expected remains the current control connection.
func (*Syncer) RequestFullSync ¶ added in v0.0.13
RequestFullSync queues at most one pass behind the currently running pass.
func (*Syncer) RequestFullSyncForSession ¶ added in v0.0.13
func (s *Syncer) RequestFullSyncForSession(expected *ControlSession) bool
func (*Syncer) RunPeriodicCheck ¶ added in v0.0.13
func (*Syncer) RunRequestedFullSyncs ¶ added in v0.0.13
RunRequestedFullSyncs owns the capacity-one request signal and executes requested passes serially until its server-derived context is cancelled.
func (*Syncer) StartPeriodicCheck ¶
StartPeriodicCheck starts periodic version comparison
func (*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。
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package entitycache 提供通用实体缓存抽象。
|
Package entitycache 提供通用实体缓存抽象。 |
|
Package loaders 提供 entitycache.Loader 的具体实现(每实体一个文件)。
|
Package loaders 提供 entitycache.Loader 的具体实现(每实体一个文件)。 |