Documentation
¶
Overview ¶
Package localcache provides local cache
Index ¶
- func CreateConcurrentLimit(n *node.Node) (num int64)
- func DecrNodeConcurrent(n *node.Node) error
- func DeleteInstanceInfoMap(ctx context.Context, insID string) error
- func DeleteNodeMetric(ctx context.Context, nodeID string) error
- func DeleteSandboxCache(sandboxID string)
- func DeleteSandboxProxyMap(ctx context.Context, sandboxID string) error
- func DeleteTemplateImageJobPullProgress(ctx context.Context, jobID string) error
- func DeregisterTemplateReplica(templateID, nodeID string)
- func EvictNode(nodeID string)
- func GetCacheItems() map[string]cache.Item
- func GetDescribeTask(ctx context.Context, taskID string) (*types.DescribeTaskMap, bool)
- func GetHealthyNodes(n int) node.NodeList
- func GetHealthyNodesByInstanceType(n int, product string) node.NodeList
- func GetImageStateByNode(imageName string, nodeName string) *fwk.ImageStateSummary
- func GetInstanceInfoMap(ctx context.Context, insID string) (*types.InstanceInfoMap, bool)
- func GetNode(id string) (*node.Node, bool)
- func GetNodes(n int) node.NodeList
- func GetNodesByIp(ip string) (*node.Node, bool)
- func GetSandboxProxyMap(ctx context.Context, sandboxID string) (*types.SandboxProxyMap, bool)
- func GetSchedulableNodesByInstanceType(n int, product string) node.NodeList
- func GetTemplateImageJobPullProgress(ctx context.Context, jobID string) (*types.TemplateImageJobPullProgressMap, bool)
- func HealthyMasterNodes() (num int64)
- func IncrNodeConcurrent(n *node.Node) error
- func Init(ctx context.Context) error
- func InvalidateImageState(imageName string)
- func IsSnapshotStorageWriteAllowed(mode string) bool
- func ListKnownSandboxIDs() []string
- func LoadImageScore()
- func LocalCreateConcurrentLimit(n *node.Node) (num int64)
- func MaxMvmLimit(n *node.Node) (num int64)
- func NotifyEvent(e *Event) error
- func RangeDBHost(index, size int, product string) ([]*node.Node, int)
- func RealMaxMvmLimit(n *node.Node) (num int64)
- func RealTimeCreateConcurrentLimit(n *node.Node) (num int64)
- func RegisterNodeLoader(loader func(context.Context) ([]*node.Node, error))
- func RegisterTemplateReplica(templateID, nodeID string, sizeBytes int64)
- func ResetSnapshotStorageStateCacheForTest()
- func SetDescribeTask(ctx context.Context, taskInfo *types.DescribeTaskMap) error
- func SetInstanceInfoField(ctx context.Context, insID string, kv ...string) error
- func SetInstanceInfoMap(ctx context.Context, insInfo *types.InstanceInfoMap) error
- func SetSandboxCache(sandboxID string, cache *SandboxCache)
- func SetSandboxProxyMap(ctx context.Context, proxyInfo *types.SandboxProxyMap) error
- func SetSnapshotStorageState(state SnapshotStorageState)
- func SetTemplateImageJobPullProgress(ctx context.Context, progress *types.TemplateImageJobPullProgressMap) error
- func SetTemplateImageJobPullProgressNoTTL(ctx context.Context, progress *types.TemplateImageJobPullProgressMap) error
- func SyncNodeTemplates(nodeID string, templateIDs []string)
- func UpdateNodeMetricInProcess(m *NodeMetric) error
- func UpsertNode(n *node.Node)
- func WriteNodeMetric(ctx context.Context, m *NodeMetric) error
- type Event
- type EventType
- type NodeMetric
- type RedisNodeInfo
- type SandboxCache
- type SnapshotStorageState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateConcurrentLimit ¶
func DecrNodeConcurrent ¶
func DeleteNodeMetric ¶
DeleteNodeMetric removes both current and legacy metric keys for a retired node. Cache eviction remains correct if Redis is temporarily unavailable, so callers may log this error after the database transaction has committed.
func DeleteSandboxCache ¶
func DeleteSandboxCache(sandboxID string)
func DeleteSandboxProxyMap ¶
func DeregisterTemplateReplica ¶
func DeregisterTemplateReplica(templateID, nodeID string)
func EvictNode ¶
func EvictNode(nodeID string)
EvictNode synchronously removes every scheduler-local view owned by nodeID. It is used after a node deletion commits and by metadata reloads on replicas that observe the deleted registration later.
func GetCacheItems ¶
func GetDescribeTask ¶
func GetHealthyNodes ¶
func GetImageStateByNode ¶
func GetImageStateByNode(imageName string, nodeName string) *fwk.ImageStateSummary
func GetInstanceInfoMap ¶
func GetSandboxProxyMap ¶
func GetSchedulableNodesByInstanceType ¶
GetSchedulableNodesByInstanceType returns healthy nodes that may receive new sandboxes. Cordon filtering happens before limit n so isolated nodes do not consume PreSelectNum. Healthy-but-isolated nodes remain in GetHealthyNodes*.
func HealthyMasterNodes ¶
func HealthyMasterNodes() (num int64)
func IncrNodeConcurrent ¶
func InvalidateImageState ¶
func InvalidateImageState(imageName string)
func ListKnownSandboxIDs ¶
func ListKnownSandboxIDs() []string
func LoadImageScore ¶
func LoadImageScore()
func MaxMvmLimit ¶
func NotifyEvent ¶
func RealMaxMvmLimit ¶
func RegisterNodeLoader ¶
func RegisterTemplateReplica ¶
func ResetSnapshotStorageStateCacheForTest ¶
func ResetSnapshotStorageStateCacheForTest()
ResetSnapshotStorageStateCacheForTest clears the in-process snapshot storage state cache. It is exported solely so cross-package tests (for example, templatecenter) can isolate cache state between cases. Production code MUST NOT call this.
func SetDescribeTask ¶
func SetDescribeTask(ctx context.Context, taskInfo *types.DescribeTaskMap) error
func SetInstanceInfoField ¶
func SetInstanceInfoMap ¶
func SetInstanceInfoMap(ctx context.Context, insInfo *types.InstanceInfoMap) error
func SetSandboxCache ¶
func SetSandboxCache(sandboxID string, cache *SandboxCache)
func SetSandboxProxyMap ¶
func SetSandboxProxyMap(ctx context.Context, proxyInfo *types.SandboxProxyMap) error
func SetSnapshotStorageState ¶
func SetSnapshotStorageState(state SnapshotStorageState)
func SetTemplateImageJobPullProgress ¶
func SetTemplateImageJobPullProgress(ctx context.Context, progress *types.TemplateImageJobPullProgressMap) error
func SetTemplateImageJobPullProgressNoTTL ¶
func SetTemplateImageJobPullProgressNoTTL(ctx context.Context, progress *types.TemplateImageJobPullProgressMap) error
func SyncNodeTemplates ¶
func UpdateNodeMetricInProcess ¶
func UpdateNodeMetricInProcess(m *NodeMetric) error
UpdateNodeMetricInProcess pushes a metric directly into the receiving cubemaster's local cache so scheduling on this replica does not have to wait for the next Redis tick. Only the groups marked present on the NodeMetric (HasAllocated / HasDisk) are written; other fields keep whatever value the previous Redis tick or heartbeat installed, which preserves the partial-update semantics the Redis writer relies on.
Returns an error if the node is unknown to this replica (which is normal during cold start and will self-heal when reload syncs the registration table).
func UpsertNode ¶
func WriteNodeMetric ¶
func WriteNodeMetric(ctx context.Context, m *NodeMetric) error
WriteNodeMetric persists a cubelet-reported metric snapshot to Redis so all cubemaster replicas converge on the same view through their existing loopUpdateMetric tick. We deliberately overwrite update_at with the server-side timestamp passed in (which the heartbeat handler clamps to time.Now()) so clock skew on individual cubelets cannot push entries past or stall the MetricUpdateTimeout filter.
Types ¶
type NodeMetric ¶
type NodeMetric struct {
NodeID string
MetricTime time.Time
HasAllocated bool
MilliCPUUsage int64
MemoryMBUsage int64
MvmNum int64
NicQueues int64
HasDisk bool
DataDiskUsagePer float64
StorageDiskUsagePer float64
SysDiskUsagePer float64
}
NodeMetric is the in-API-process view of a cubelet's resource report. It is shared by the heartbeat handler and Redis fan-out so all paths agree on field semantics. All numeric fields use the same units as RedisNodeInfo (milli-cpu, MB, 0~100 percent) so cross-replica scheduling stays stable regardless of whether a master saw the cubelet directly or learned about it through Redis.
HasAllocated and HasDisk distinguish "cubelet reported zero" from "cubelet did not report this group". Without these flags an empty section in a heartbeat would clobber the previous valid values in Redis, because HSET cannot tell apart "set to zero" from "leave untouched". The two flags map 1:1 to the Allocated / DiskUsage sub structures on UpdateNodeStatusRequest, so a partial heartbeat (allocated-only, disk-only, or anything in between) round-trips without corrupting the other group's prior state.
type RedisNodeInfo ¶
type RedisNodeInfo struct {
InsID string `json:"InstanceID" redis:"ins_id"`
QuotaCpuUsage int64 `json:"QuotaCpuUsage" redis:"quota_cpu_usage"`
QuotaMemUsage int64 `json:"QuotaMemUsage" redis:"quota_mem_mb_usage"`
CpuUtil float64 `json:"CpuUtil" redis:"cpu_util"`
CpuLoadUsage float64 `json:"CpuLoadUsage" redis:"cpu_load_usage"`
MemUsage int64 `json:"MemUsage" redis:"mem_load_mb_usage"`
DataDiskUsagePer float64 `json:"DataDiskUsagePer" redis:"data_disk_usage_per"`
StorageDiskUsagePer float64 `json:"StorageDiskUsagePer" redis:"storage_disk_usage_per"`
SysDiskUsagePer float64 `json:"SysDiskUsagePer" redis:"sys_disk_usage_per"`
MvmNum int64 `json:"mvm_num" redis:"mvm_num"`
MetricUpdate string `json:"MetricUpdateAt" redis:"update_at"`
RealTimeCreateNum int64 `json:"RealTimeCreateNum,omitempty" redis:"realtime_create_num"`
NICQueues int64 `json:"nic_queues,omitempty" redis:"nic_queues"`
}
type SandboxCache ¶
func GetSandboxCache ¶
func GetSandboxCache(sandboxID string) *SandboxCache
type SnapshotStorageState ¶
type SnapshotStorageState struct {
NodeID string
NodeIP string
UsagePct uint64
Mode string
LastError string
LastUpdatedAt int64
}
func GetSnapshotStorageState ¶
func GetSnapshotStorageState(nodeID, nodeIP string) (SnapshotStorageState, bool)
func ListSnapshotStorageStates ¶
func ListSnapshotStorageStates() []SnapshotStorageState
ListSnapshotStorageStates returns all currently cached snapshot storage states, deduplicated by (NodeID, NodeIP). It is intended for the snapshot reconciler to keep retrying nodes whose last refresh ended in failure even when the healthy-node list (backed by redis) is temporarily empty.